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

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-03-28 19:48:49 -04:00
import { useFetcher } from '@remix-run/react'
2024-03-29 15:58:22 -04:00
import Button from '~/components/Button'
// TODO: Remove useModal and replace with Dialog
2024-03-30 18:39:46 -04:00
import useModal from '~/components/Modal'
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()
2024-03-30 18:39:46 -04:00
const { Modal, open } = useModal({
title: `${isEnabled ? 'Disable' : 'Enable'} Magic DNS`,
variant: isEnabled ? 'danger' : 'confirm',
buttonText: `${isEnabled ? 'Disable' : 'Enable'} Magic DNS`,
description: 'Devices will no longer be accessible via your tailnet domain. The search domain will also be disabled.',
onConfirm: () => {
fetcher.submit({
// eslint-disable-next-line @typescript-eslint/naming-convention
'dns_config.magic_dns': !isEnabled
}, {
method: 'PATCH',
encType: 'application/json'
})
}
})
2024-03-28 19:48:49 -04:00
return (
<>
2024-03-29 15:58:22 -04:00
<Button
variant='emphasized'
className='w-fit text-sm'
disabled={disabled}
2024-03-28 19:48:49 -04:00
onClick={() => {
2024-03-30 18:39:46 -04:00
open()
2024-03-28 19:48:49 -04:00
}}
>
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-03-29 15:58:22 -04:00
</Button>
2024-03-30 18:39:46 -04:00
{Modal}
2024-03-28 19:48:49 -04:00
</>
)
}