headplane/app/routes/users/dialogs/remove.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

import { X } from 'lucide-react';
2024-12-31 10:30:14 +05:30
import { Form, useSubmit } from 'react-router';
import { useState } from 'react';
2024-05-15 21:52:19 -04:00
import IconButton from '~/components/IconButton';
2024-12-31 10:30:14 +05:30
import Code from '~/components/Code';
import Dialog from '~/components/Dialog';
2024-05-15 21:52:19 -04:00
interface Props {
2024-12-31 10:30:14 +05:30
username: string;
2024-05-15 21:52:19 -04:00
}
export default function Remove({ username }: Props) {
2024-12-31 10:30:14 +05:30
const submit = useSubmit();
const [dialog, setDialog] = useState(false);
2024-05-15 21:52:19 -04:00
return (
<>
<IconButton
label={`Delete ${username}`}
onPress={() => setDialog(true)}
2024-05-15 21:52:19 -04:00
>
<X className="p-0.5" />
</IconButton>
<Dialog control={[dialog, setDialog]}>
<Dialog.Panel control={[dialog, setDialog]}>
2024-12-31 10:30:14 +05:30
{(close) => (
2024-05-15 21:52:19 -04:00
<>
2024-12-31 10:30:14 +05:30
<Dialog.Title>Delete {username}?</Dialog.Title>
2024-05-15 21:52:19 -04:00
<Dialog.Text className="mb-8">
2024-12-31 10:30:14 +05:30
Are you sure you want to delete {username}? A deleted user
cannot be recovered.
2024-05-15 21:52:19 -04:00
</Dialog.Text>
<Form
method="POST"
onSubmit={(event) => {
2024-12-31 10:30:14 +05:30
submit(event.currentTarget);
2024-05-15 21:52:19 -04:00
}}
>
<input type="hidden" name="_method" value="delete" />
<input type="hidden" name="username" value={username} />
<div className="mt-6 flex justify-end gap-2 mt-6">
2024-12-31 10:30:14 +05:30
<Dialog.Action variant="cancel" onPress={close}>
2024-05-15 21:52:19 -04:00
Cancel
</Dialog.Action>
2024-12-31 10:30:14 +05:30
<Dialog.Action variant="confirm" onPress={close}>
2024-05-15 21:52:19 -04:00
Delete
</Dialog.Action>
</div>
</Form>
</>
)}
</Dialog.Panel>
</Dialog>
</>
2024-12-31 10:30:14 +05:30
);
2024-05-15 21:52:19 -04:00
}