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

93 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { useFetcher } from 'react-router';
import { useState } from 'react';
import { Input } from 'react-aria-components';
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';
import Spinner from '~/components/Spinner';
import TextField from '~/components/TextField';
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
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 (
2024-12-31 10:30:14 +05:30
<div className="flex flex-col w-2/3">
<h1 className="text-2xl font-medium mb-4">Tailnet Name</h1>
<p className="text-gray-700 dark:text-gray-300">
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
2024-03-29 01:53:32 -04:00
readOnly
className={cn(
'block px-2.5 py-1.5 w-1/2 rounded-lg my-4',
'border border-ui-200 dark:border-ui-600',
'dark:bg-ui-800 dark:text-ui-300 text-sm',
2024-12-31 10:30:14 +05:30
'outline-none',
)}
2024-12-31 10:30:14 +05:30
type="text"
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>
2024-12-31 10:30:14 +05:30
{(close) => (
2024-04-30 11:03:53 -04:00
<>
2024-12-31 10:30:14 +05:30
<Dialog.Title>Rename Tailnet</Dialog.Title>
2024-04-30 11:03:53 -04:00
<Dialog.Text>
2024-12-31 10:30:14 +05:30
Keep in mind that changing this can lead to all sorts of
unexpected behavior and may break existing devices in your
tailnet.
2024-04-30 11:03:53 -04:00
</Dialog.Text>
<TextField
2024-12-31 10:30:14 +05:30
label="Tailnet name"
placeholder="ts.net"
2024-04-30 11:03:53 -04:00
state={[newName, setNewName]}
2024-12-31 10:30:14 +05:30
className="my-2"
2024-04-30 11:03:53 -04:00
/>
2024-12-31 10:30:14 +05:30
<div className="mt-6 flex justify-end gap-2 mt-6">
<Dialog.Action variant="cancel" onPress={close}>
2024-04-30 11:03:53 -04:00
Cancel
</Dialog.Action>
<Dialog.Action
2024-12-31 10:30:14 +05:30
variant="confirm"
2024-04-30 11:03:53 -04:00
onPress={() => {
2024-12-31 10:30:14 +05:30
fetcher.submit(
{
'dns.base_domain': newName,
},
{
method: 'PATCH',
encType: 'application/json',
},
);
2024-04-30 11:03:53 -04:00
2024-12-31 10:30:14 +05:30
close();
2024-04-30 11:03:53 -04:00
}}
>
Rename
</Dialog.Action>
</div>
</>
)}
</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
}