headplane/app/routes/_data.dns._index/magic.tsx

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-03-28 19:48:49 -04:00
import { useFetcher } from '@remix-run/react'
2024-04-30 11:03:53 -04:00
import Dialog from '~/components/Dialog'
2024-03-30 04:12:37 -04:00
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;
// eslint-disable-next-line react/boolean-prop-naming
readonly disabled?: boolean;
2024-03-28 19:48:49 -04:00
}
export default function Modal({ isEnabled, disabled }: Properties) {
2024-03-28 19:48:49 -04:00
const fetcher = useFetcher()
return (
2024-04-30 11:03:53 -04:00
<Dialog>
<Dialog.Button isDisabled={disabled}>
2024-03-30 04:12:37 -04:00
{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>
{close => (
<>
<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>
<div className='mt-6 flex justify-end gap-2 mt-6'>
<Dialog.Action
variant='cancel'
onPress={close}
>
Cancel
</Dialog.Action>
<Dialog.Action
variant='confirm'
onPress={() => {
fetcher.submit({
// eslint-disable-next-line @typescript-eslint/naming-convention
'dns.magic_dns': !isEnabled
2024-04-30 11:03:53 -04:00
}, {
method: 'PATCH',
encType: 'application/json'
})
close()
}}
>
{isEnabled ? 'Disable' : 'Enable'} Magic DNS
</Dialog.Action>
</div>
</>
)}
</Dialog.Panel>
</Dialog>
2024-03-28 19:48:49 -04:00
)
}