import { useAlertContext } from '@components/common/modal/Alert.js'; import { Button } from '@components/common/ui/Button.js'; import { ButtonGroup } from '@components/common/ui/ButtonGroup.js'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@components/common/ui/Card.js'; import { toast } from '@components/common/ui/Sonner.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import axios from 'axios'; import React from 'react'; interface SecretProps { webhook: { secret: string; updateApi: string }; } export default function Secret({ webhook }: SecretProps) { const { openAlert, closeAlert } = useAlertContext(); const copy = async () => { try { await navigator.clipboard.writeText(webhook.secret); toast.success(_('Secret copied')); } catch { toast.error(_('Could not copy the secret')); } }; const regenerate = async () => { try { await axios.patch(webhook.updateApi, { regenerateSecret: true }); window.location.reload(); } catch (e: any) { closeAlert(); toast.error(e?.response?.data?.error?.message || _('Something went wrong')); } }; return (
{_('Signing secret')} {_( 'Every request carries an X-EverShop-Signature header, an HMAC-SHA256 of "." made with this secret. Check it on your side to be sure the request came from your store.' )}
e.target.select()} className="flex-1 min-w-0 rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm" />
); } export const layout = { areaId: 'content', sortOrder: 12 }; export const query = ` query Query { webhook(id: getContextValue("webhookUuid", null)) { secret updateApi } } `;