headplane/app/routes/dns/components/rename.tsx

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { useState } from 'react';
import { useFetcher } from 'react-router';
2024-03-26 17:42:45 -04:00
2024-12-31 10:30:14 +05:30
import Code from '~/components/Code';
import Dialog from '~/components/Dialog';
2025-01-28 16:02:47 -05:00
import Input from '~/components/Input';
2024-12-31 10:30:14 +05:30
import Spinner from '~/components/Spinner';
import { cn } from '~/utils/cn';
2024-03-28 14:20:19 -04:00
type Properties = {
readonly name: string;
readonly disabled?: boolean;
2024-12-31 10:30:14 +05:30
};
2024-03-28 14:20:19 -04:00
// TODO: Switch to form submit instead of JSON patch
export default function Modal({ name, disabled }: Properties) {
2024-12-31 10:30:14 +05:30
const [newName, setNewName] = useState(name);
const fetcher = useFetcher();
2024-03-26 17:42:45 -04:00
return (
2025-01-28 16:02:47 -05:00
<div className="flex flex-col w-2/3 gap-y-4">
<h1 className="text-2xl font-medium mb-2">Tailnet Name</h1>
<p>
2024-12-31 10:30:14 +05:30
This is the base domain name of your Tailnet. Devices are accessible at{' '}
<Code>[device].{name}</Code> when Magic DNS is enabled.
2024-03-29 01:53:32 -04:00
</p>
<Input
2025-01-28 16:02:47 -05:00
isReadOnly
className="w-3/5 font-medium text-sm"
2024-03-29 01:53:32 -04:00
value={name}
2024-12-31 10:30:14 +05:30
onFocus={(event) => {
event.target.select();
2024-03-29 01:53:32 -04:00
}}
/>
2024-04-30 11:03:53 -04:00
<Dialog>
<Dialog.Button isDisabled={disabled}>
2024-04-30 11:03:53 -04:00
{fetcher.state === 'idle' ? undefined : (
2024-12-31 10:30:14 +05:30
<Spinner className="w-3 h-3" />
2024-04-30 11:03:53 -04:00
)}
Rename Tailnet
</Dialog.Button>
<Dialog.Panel
onSubmit={() => {
fetcher.submit(
{
'dns.base_domain': newName,
},
{
method: 'PATCH',
encType: 'application/json',
},
);
}}
>
<Dialog.Title>Rename Tailnet</Dialog.Title>
<Dialog.Text>
Keep in mind that changing this can lead to all sorts of unexpected
behavior and may break existing devices in your tailnet.
</Dialog.Text>
2025-01-28 16:02:47 -05:00
<Input
label="Tailnet name"
placeholder="ts.net"
2025-01-28 16:02:47 -05:00
onChange={setNewName}
/>
2024-04-30 11:03:53 -04:00
</Dialog.Panel>
</Dialog>
2024-03-29 01:53:32 -04:00
</div>
2024-12-31 10:30:14 +05:30
);
2024-03-26 17:42:45 -04:00
}