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

66 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Pencil } 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 Dialog from '~/components/Dialog';
import TextField from '~/components/TextField';
2024-05-15 21:52:19 -04:00
interface Props {
2024-12-31 10:30:14 +05:30
username: string;
magic?: string;
2024-05-15 21:52:19 -04:00
}
export default function Rename({ username, magic }: Props) {
2024-12-31 10:30:14 +05:30
const submit = useSubmit();
const [dialog, setDialog] = useState(false);
2024-12-31 10:30:14 +05:30
const [newName, setNewName] = useState(username);
2024-05-15 21:52:19 -04:00
return (
<>
<IconButton
label={`Rename ${username}`}
onPress={() => setDialog(true)}
2024-05-15 21:52:19 -04:00
>
<Pencil className="p-1" />
</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>Rename {username}?</Dialog.Title>
2024-05-15 21:52:19 -04:00
<Dialog.Text className="mb-8">
2024-12-31 10:30:14 +05:30
Enter a new username for {username}
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="rename" />
<input type="hidden" name="old" value={username} />
<TextField
label="Username"
placeholder="my-new-name"
name="new"
state={[newName, setNewName]}
className="my-2"
/>
<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
Rename
</Dialog.Action>
</div>
</Form>
</>
)}
</Dialog.Panel>
</Dialog>
</>
2024-12-31 10:30:14 +05:30
);
2024-05-15 21:52:19 -04:00
}