-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: chris-4chain <[email protected]>
- Loading branch information
1 parent
9ab87a6
commit 3e68057
Showing
23 changed files
with
356 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@/components'; | ||
import { useSpvWalletClient } from '@/contexts'; | ||
import { errorWrapper } from '@/utils'; | ||
import { Webhook } from '@bsv/spv-wallet-js-client'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { Row } from '@tanstack/react-table'; | ||
import { CircleMinus } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import { toast } from 'sonner'; | ||
|
||
interface UnsubscribeWebhookProps { | ||
row: Row<Webhook>; | ||
} | ||
|
||
export const UnsubscribeWebhook = ({ row }: UnsubscribeWebhookProps) => { | ||
const { spvWalletClient } = useSpvWalletClient(); | ||
const queryClient = useQueryClient(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleIsOpenToggle = () => { | ||
setIsOpen((prev) => !prev); | ||
}; | ||
|
||
const mutation = useMutation({ | ||
mutationFn: async (url: string) => { | ||
// At this point, spvWalletClient is defined; using non-null assertion. | ||
return await spvWalletClient!.AdminDeleteWebhook(url); | ||
}, | ||
onSuccess: () => queryClient.invalidateQueries(), | ||
}); | ||
const onRemove = () => { | ||
mutation.mutate(row.original.url, { | ||
onSuccess: () => { | ||
toast.success('Webhook unsubscribed'); | ||
}, | ||
onError: (error) => { | ||
toast.error('Failed to unsubscribe webhook'); | ||
errorWrapper(error); | ||
}, | ||
}); | ||
}; | ||
return ( | ||
<> | ||
<Dialog open={isOpen} onOpenChange={handleIsOpenToggle}> | ||
<DialogTrigger asChild className="w-full"> | ||
<Button variant="destructive" className="h-8 max-w-min"> | ||
<CircleMinus className="w-4 h-4 mr-2" /> Unsubscribe | ||
</Button> | ||
</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Unsubscribe webhook</DialogTitle> | ||
</DialogHeader> | ||
<DialogDescription>Are you sure you want to unsubscribe a webhook ?</DialogDescription> | ||
<div className="grid grid-cols-2 gap-4"> | ||
<Button onClick={onRemove}>Unsubscribe</Button> | ||
<Button variant="ghost" onClick={handleIsOpenToggle}> | ||
Cancel | ||
</Button> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './UnsubscribeWebhook.tsx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Badge, Button } from '@/components/ui'; | ||
import { getSortDirection } from '@/utils'; | ||
import { Webhook } from '@bsv/spv-wallet-js-client'; | ||
import { Link } from '@tanstack/react-router'; | ||
import { ColumnDef } from '@tanstack/react-table'; | ||
|
||
import { ArrowUpDown } from 'lucide-react'; | ||
|
||
export interface WebhooksColumns extends Webhook { | ||
status: string; | ||
} | ||
|
||
export const webhookColumns: ColumnDef<WebhooksColumns>[] = [ | ||
{ | ||
accessorKey: 'url', | ||
header: ({ column }) => { | ||
return ( | ||
<Link | ||
search={(prev) => ({ | ||
...prev, | ||
order_by_field: 'url', | ||
sort_direction: getSortDirection(column), | ||
})} | ||
> | ||
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}> | ||
URL | ||
<ArrowUpDown className="ml-2 h-4 w-4" /> | ||
</Button> | ||
</Link> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: 'status', | ||
header: ({ column }) => { | ||
return ( | ||
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}> | ||
Status | ||
<ArrowUpDown className="ml-2 h-4 w-4" /> | ||
</Button> | ||
); | ||
}, | ||
cell: ({ row }) => { | ||
return row.getValue('status') === 'banned' ? ( | ||
<Badge variant="secondary">Banned</Badge> | ||
) : ( | ||
<Badge variant="outline">Active</Badge> | ||
); | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Card, CardContent, CardHeader, CardTitle, DataTable, webhookColumns } from '@/components'; | ||
import { UnsubscribeWebhook } from '@/components/UnsubscribeWebhook/UnsubscribeWebhook.tsx'; | ||
import { WebhookExtended } from '@/interfaces/webhook.ts'; | ||
|
||
export interface WebhooksTabContentProps { | ||
webhooks: WebhookExtended[]; | ||
} | ||
|
||
export const WebhooksTabContent = ({ webhooks }: WebhooksTabContentProps) => { | ||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Webhooks</CardTitle> | ||
</CardHeader> | ||
<CardContent className="mb-2"> | ||
{webhooks.length > 0 ? ( | ||
<DataTable | ||
columns={webhookColumns} | ||
data={webhooks} | ||
renderInlineItem={(row) => ( | ||
<> | ||
<UnsubscribeWebhook row={row} /> | ||
</> | ||
)} | ||
/> | ||
) : ( | ||
<div className="flex flex-col items-center gap-1 text-center"> | ||
<h3 className="text-2xl font-bold tracking-tight">You have no webhooks</h3> | ||
</div> | ||
)} | ||
</CardContent> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './WebhooksTabContent.tsx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Webhook } from '@bsv/spv-wallet-js-client'; | ||
|
||
export interface WebhookExtended extends Webhook { | ||
status: string; | ||
} |
Oops, something went wrong.