mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 01:15:49 +10:00
c2744cbe07
Audited every className token in the repo by compiling them against the shared tailwind config and diffing generated selectors. The following dead tokens were replaced with the intended, existing ones: - text-sbase -> text-base (document invite email button, botched sm->base edit) - text-primary-forground -> text-foreground (admin license card; the literal spelling fix would render 10% lightness text on the dark card, the inherited foreground colour is the intended look) - tracking-tigh -> tracking-tight (signing waiting page heading) - font-sm -> text-sm (4 delete-confirmation dialogs) - dark:text-muted-background -> dark:text-muted (field drag ghost in 4 flows; restores the dark mode readability fix intended by #1242) - placeholder:text-foreground-muted -> placeholder:text-muted-foreground (command palette input) - text-medium -> font-medium (org create dialog free plan, matches paid plans) - text-md -> text-base (envelope drop zone hint) - justify-left -> justify-start (member invite remove button, no visual change) - removed stray "gradie" fragment and text-dark (no dark colour exists) No visual change except where the dead class silently disabled intended styling (email button size, drag ghost dark mode text, dialog confirm text size).
152 lines
4.6 KiB
TypeScript
152 lines
4.6 KiB
TypeScript
import { trpc } from '@documenso/trpc/react';
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@documenso/ui/primitives/dialog';
|
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@documenso/ui/primitives/form/form';
|
|
import { Input } from '@documenso/ui/primitives/input';
|
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { msg } from '@lingui/core/macro';
|
|
import { useLingui } from '@lingui/react';
|
|
import { Trans } from '@lingui/react/macro';
|
|
import type { Webhook } from '@prisma/client';
|
|
import { useEffect, useState } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
|
|
import { useCurrentTeam } from '~/providers/team';
|
|
|
|
export type WebhookDeleteDialogProps = {
|
|
webhook: Pick<Webhook, 'id' | 'webhookUrl'>;
|
|
onDelete?: () => void;
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
export const WebhookDeleteDialog = ({ webhook, children }: WebhookDeleteDialogProps) => {
|
|
const { _ } = useLingui();
|
|
const { toast } = useToast();
|
|
|
|
const team = useCurrentTeam();
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const deleteMessage = _(msg`delete ${webhook.webhookUrl}`);
|
|
|
|
const ZDeleteWebhookFormSchema = z.object({
|
|
webhookUrl: z.literal(deleteMessage, {
|
|
errorMap: () => ({ message: _(msg`You must enter '${deleteMessage}' to proceed`) }),
|
|
}),
|
|
});
|
|
|
|
type TDeleteWebhookFormSchema = z.infer<typeof ZDeleteWebhookFormSchema>;
|
|
|
|
const { mutateAsync: deleteWebhook } = trpc.webhook.deleteWebhook.useMutation();
|
|
|
|
const form = useForm<TDeleteWebhookFormSchema>({
|
|
resolver: zodResolver(ZDeleteWebhookFormSchema),
|
|
values: {
|
|
webhookUrl: '',
|
|
},
|
|
});
|
|
|
|
const onSubmit = async () => {
|
|
try {
|
|
await deleteWebhook({ id: webhook.id });
|
|
|
|
toast({
|
|
title: _(msg`Webhook deleted`),
|
|
description: _(msg`The webhook has been successfully deleted.`),
|
|
duration: 5000,
|
|
});
|
|
|
|
setOpen(false);
|
|
} catch (error) {
|
|
toast({
|
|
title: _(msg`An unknown error occurred`),
|
|
description: _(msg`We encountered an unknown error while attempting to delete it. Please try again later.`),
|
|
variant: 'destructive',
|
|
duration: 5000,
|
|
});
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (!open) {
|
|
form.reset();
|
|
}
|
|
}, [open, form]);
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={(value) => !form.formState.isSubmitting && setOpen(value)}>
|
|
<DialogTrigger asChild>
|
|
{children ?? (
|
|
<Button className="mr-4" variant="destructive">
|
|
<Trans>Delete</Trans>
|
|
</Button>
|
|
)}
|
|
</DialogTrigger>
|
|
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
<Trans>Delete Webhook</Trans>
|
|
</DialogTitle>
|
|
|
|
<DialogDescription>
|
|
<Trans>
|
|
Please note that this action is irreversible. Once confirmed, your webhook will be permanently deleted.
|
|
</Trans>
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
|
<fieldset className="flex h-full flex-col space-y-4" disabled={form.formState.isSubmitting}>
|
|
<FormField
|
|
control={form.control}
|
|
name="webhookUrl"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>
|
|
<Trans>
|
|
Confirm by typing:{' '}
|
|
<span className="font-semibold text-destructive text-sm">{deleteMessage}</span>
|
|
</Trans>
|
|
</FormLabel>
|
|
<FormControl>
|
|
<Input className="bg-background" type="text" {...field} />
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<DialogFooter>
|
|
<Button type="button" variant="secondary" onClick={() => setOpen(false)}>
|
|
<Trans>Cancel</Trans>
|
|
</Button>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="destructive"
|
|
disabled={!form.formState.isValid}
|
|
loading={form.formState.isSubmitting}
|
|
>
|
|
<Trans>Delete</Trans>
|
|
</Button>
|
|
</DialogFooter>
|
|
</fieldset>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|