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;
|
2024-03-29 21:46:21 -04:00
|
|
|
readonly disabled?: boolean;
|
2024-12-31 10:30:14 +05:30
|
|
|
};
|
2024-03-28 19:48:49 -04:00
|
|
|
|
2025-01-26 15:04:13 -05:00
|
|
|
// TODO: Use form action instead of JSON patching
|
|
|
|
|
// AND FIX JSON END OF UNEXPECTED INPUT
|
2024-03-29 21:46:21 -04:00
|
|
|
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>
|
2024-05-05 23:38:41 -04:00
|
|
|
<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>
|
2025-01-26 15:04:13 -05:00
|
|
|
<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
|
|
|
}
|