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

60 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { useFetcher } from 'react-router';
2024-03-28 19:48:49 -04:00
2024-12-31 10:30:14 +05:30
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
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>
2024-12-31 10:30:14 +05:30
{(close) => (
2024-04-30 11:03:53 -04:00
<>
<Dialog.Title>
{isEnabled ? 'Disable' : 'Enable'} Magic DNS
</Dialog.Title>
<Dialog.Text>
2024-12-31 10:30:14 +05:30
Devices will no longer be accessible via your tailnet domain. The
search domain will also be disabled.
2024-04-30 11:03:53 -04:00
</Dialog.Text>
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(
{
// eslint-disable-next-line @typescript-eslint/naming-convention
'dns.magic_dns': !isEnabled,
},
{
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
}}
>
{isEnabled ? 'Disable' : 'Enable'} Magic DNS
</Dialog.Action>
</div>
</>
)}
</Dialog.Panel>
</Dialog>
2024-12-31 10:30:14 +05:30
);
2024-03-28 19:48:49 -04:00
}