aboutsummaryrefslogtreecommitdiff
path: root/src/app/(main)/admin/users/UserDeleteForm.tsx
blob: 8f6fd502b1b4881823c78820798f2706c6f43573 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { AlertDialog, Row } from '@umami/react-zen';
import { useDeleteQuery, useMessages, useModified } from '@/components/hooks';

export function UserDeleteForm({
  userId,
  username,
  onSave,
  onClose,
}: {
  userId: string;
  username: string;
  onSave?: () => void;
  onClose?: () => void;
}) {
  const { messages, labels, formatMessage } = useMessages();
  const { mutateAsync } = useDeleteQuery(`/users/${userId}`);
  const { touch } = useModified();

  const handleConfirm = async () => {
    await mutateAsync(null, {
      onSuccess: async () => {
        touch('users');
        touch(`users:${userId}`);
        onSave?.();
        onClose?.();
      },
    });
  };

  return (
    <AlertDialog
      title={formatMessage(labels.delete)}
      onConfirm={handleConfirm}
      onCancel={onClose}
      confirmLabel={formatMessage(labels.delete)}
      isDanger
    >
      <Row gap="1">{formatMessage(messages.confirmDelete, { target: username })}</Row>
    </AlertDialog>
  );
}