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

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { PencilIcon } from '@primer/octicons-react';
import { Form, useSubmit } from 'react-router';
import { useState } from 'react';
2024-05-15 21:52:19 -04:00
2024-12-31 10:30:14 +05:30
import Button from '~/components/Button';
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 dialogState = useState(false);
const [newName, setNewName] = useState(username);
2024-05-15 21:52:19 -04:00
return (
<>
<Button
variant="light"
control={dialogState}
className="rounded-full p-0 w-8 h-8"
>
<PencilIcon className="w-4 h-4" />
</Button>
<Dialog control={dialogState}>
<Dialog.Panel control={dialogState}>
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
}