import { useAlertContext } from '@components/common/modal/Alert.js'; import { Badge } from '@components/common/ui/Badge.js'; import { Button } from '@components/common/ui/Button.js'; import { ButtonGroup } from '@components/common/ui/ButtonGroup.js'; import { Card, CardContent } from '@components/common/ui/Card.js'; import { Checkbox } from '@components/common/ui/Checkbox.js'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@components/common/ui/Table.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import axios from 'axios'; import React, { useState } from 'react'; interface WebhookRow { uuid: string; name: string; url: string; enabled: boolean; topics: string[]; pendingCount: number; failedCount: number; editUrl: string; deleteApi: string; } function Actions({ webhooks, selectedIds }: { webhooks: WebhookRow[]; selectedIds: string[]; }) { const { openAlert, closeAlert } = useAlertContext(); const remove = async () => { await Promise.all( webhooks .filter((w) => selectedIds.includes(w.uuid)) .map((w) => axios.delete(w.deleteApi)) ); window.location.reload(); }; if (selectedIds.length === 0) { return null; } return ( ); } export default function WebhookGrid({ webhooks }: { webhooks: WebhookRow[] }) { const [selectedRows, setSelectedRows] = useState([]); return (
setSelectedRows(checked ? webhooks.map((w) => w.uuid) : []) } /> {_('Name')} {_('URL')} {_('Events')} {_('Status')} {_('Pending')} {_('Failed')} {webhooks.map((w) => ( setSelectedRows( checked ? selectedRows.concat([w.uuid]) : selectedRows.filter((row) => row !== w.uuid) ) } /> {w.name} {w.url} {w.topics.length} {w.enabled ? _('Enabled') : _('Disabled')} {w.pendingCount} {w.failedCount > 0 ? ( {w.failedCount} ) : ( 0 )} ))}
{webhooks.length === 0 && (
{_( 'No webhook yet. Create one to send store events to another system.' )}
)}
); } export const layout = { areaId: 'content', sortOrder: 20 }; export const query = ` query Query { webhooks { uuid name url enabled topics pendingCount failedCount editUrl deleteApi } } `;