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

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { useFetcher } from 'react-router';
import Dialog from '~/components/Dialog';
import Spinner from '~/components/Spinner';
2024-03-29 15:58:22 -04:00
2024-03-28 19:48:49 -04:00
type Properties = {
readonly isEnabled: boolean;
readonly disabled?: boolean;
2024-12-31 10:30:14 +05:30
};
2024-03-28 19:48:49 -04:00
// TODO: Use form action instead of JSON patching
// AND FIX JSON END OF UNEXPECTED INPUT
export default function Modal({ isEnabled, disabled }: Properties) {
2024-12-31 10:30:14 +05:30
const fetcher = useFetcher();
2024-03-28 19:48:49 -04:00
return (
2024-04-30 11:03:53 -04:00
<Dialog>
<Dialog.Button isDisabled={disabled}>
2024-12-31 10:30:14 +05:30
{fetcher.state === 'idle' ? undefined : <Spinner className="w-3 h-3" />}
2024-03-28 19:48:49 -04:00
{isEnabled ? 'Disable' : 'Enable'} Magic DNS
2024-04-30 11:03:53 -04:00
</Dialog.Button>
<Dialog.Panel
onSubmit={() => {
fetcher.submit(
{
'dns.magic_dns': !isEnabled,
},
{
method: 'PATCH',
encType: 'application/json',
},
);
}}
>
<Dialog.Title>
{isEnabled ? 'Disable' : 'Enable'} Magic DNS
</Dialog.Title>
<Dialog.Text>
Devices will no longer be accessible via your tailnet domain. The
search domain will also be disabled.
</Dialog.Text>
2024-04-30 11:03:53 -04:00
</Dialog.Panel>
</Dialog>
2024-12-31 10:30:14 +05:30
);
2024-03-28 19:48:49 -04:00
}