Files
sign/apps/web/src/app/(dashboard)/templates/duplicate-template-dialog.tsx

96 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-10-06 22:54:24 +00:00
import { useRouter } from 'next/navigation';
2024-08-27 20:34:39 +09:00
import { Trans, msg } from '@lingui/macro';
import { useLingui } from '@lingui/react';
2023-10-06 22:54:24 +00:00
import { trpc as trpcReact } from '@documenso/trpc/react';
import { Button } from '@documenso/ui/primitives/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@documenso/ui/primitives/dialog';
import { useToast } from '@documenso/ui/primitives/use-toast';
type DuplicateTemplateDialogProps = {
id: number;
2024-02-08 12:33:20 +11:00
teamId?: number;
2023-10-06 22:54:24 +00:00
open: boolean;
onOpenChange: (_open: boolean) => void;
};
export const DuplicateTemplateDialog = ({
id,
open,
onOpenChange,
}: DuplicateTemplateDialogProps) => {
const router = useRouter();
2024-08-27 20:34:39 +09:00
const { _ } = useLingui();
2023-10-06 22:54:24 +00:00
const { toast } = useToast();
const { mutateAsync: duplicateTemplate, isPending } =
2023-10-06 22:54:24 +00:00
trpcReact.template.duplicateTemplate.useMutation({
onSuccess: () => {
router.refresh();
toast({
2024-08-27 20:34:39 +09:00
title: _(msg`Template duplicated`),
description: _(msg`Your template has been duplicated successfully.`),
2023-10-06 22:54:24 +00:00
duration: 5000,
});
onOpenChange(false);
},
2024-02-08 12:33:20 +11:00
onError: () => {
toast({
2024-08-27 20:34:39 +09:00
title: _(msg`Error`),
description: _(msg`An error occurred while duplicating template.`),
2024-02-08 12:33:20 +11:00
variant: 'destructive',
});
},
2023-10-06 22:54:24 +00:00
});
return (
<Dialog open={open} onOpenChange={(value) => !isPending && onOpenChange(value)}>
2023-10-06 22:54:24 +00:00
<DialogContent>
<DialogHeader>
2024-08-27 20:34:39 +09:00
<DialogTitle>
<Trans>Do you want to duplicate this template?</Trans>
</DialogTitle>
2023-10-06 22:54:24 +00:00
2024-08-27 20:34:39 +09:00
<DialogDescription className="pt-2">
<Trans>Your template will be duplicated.</Trans>
</DialogDescription>
2023-10-06 22:54:24 +00:00
</DialogHeader>
<DialogFooter>
2024-02-08 12:33:20 +11:00
<Button
type="button"
disabled={isPending}
2024-02-08 12:33:20 +11:00
variant="secondary"
onClick={() => onOpenChange(false)}
>
2024-08-27 20:34:39 +09:00
<Trans>Cancel</Trans>
2024-02-08 12:33:20 +11:00
</Button>
2023-10-06 22:54:24 +00:00
2024-02-08 12:33:20 +11:00
<Button
type="button"
loading={isPending}
2024-02-08 12:33:20 +11:00
onClick={async () =>
duplicateTemplate({
templateId: id,
})
}
>
2024-08-27 20:34:39 +09:00
<Trans>Duplicate</Trans>
2024-02-08 12:33:20 +11:00
</Button>
2023-10-06 22:54:24 +00:00
</DialogFooter>
</DialogContent>
</Dialog>
);
};