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

75 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-03-28 17:03:37 -04:00
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable unicorn/no-keyword-prefix */
2024-03-26 17:42:45 -04:00
import { Dialog } from '@headlessui/react'
2024-03-28 17:03:37 -04:00
import { useFetcher } from '@remix-run/react'
2024-03-26 17:42:45 -04:00
import { useState } from 'react'
2024-03-28 14:20:19 -04:00
type Properties = {
readonly name: string;
}
export default function Modal({ name }: Properties) {
2024-03-26 17:42:45 -04:00
const [isOpen, setIsOpen] = useState(false)
2024-03-28 17:03:37 -04:00
const [newName, setNewName] = useState(name)
const fetcher = useFetcher()
2024-03-26 17:42:45 -04:00
return (
<>
<button
type='button'
className='rounded-lg px-3 py-2 bg-gray-800 text-white w-fit text-sm'
onClick={() => {
setIsOpen(true)
}}
>
Rename Tailnet...
</button>
<Dialog
className='relative z-50'
open={isOpen} onClose={() => {
setIsOpen(false)
}}
>
<div className='fixed inset-0 bg-black/30' aria-hidden='true'/>
2024-03-28 14:20:19 -04:00
<div className='fixed inset-0 flex w-screen items-center justify-center'>
2024-03-26 17:42:45 -04:00
<Dialog.Panel className='bg-white rounded-lg p-4 w-full max-w-md'>
2024-03-28 14:20:19 -04:00
<Dialog.Title className='text-lg font-bold'>
Rename {name}
2024-03-26 17:42:45 -04:00
</Dialog.Title>
2024-03-28 14:20:19 -04:00
<Dialog.Description className='text-gray-500 dark:text-gray-400'>
Keep in mind that changing this can lead to all sorts
of unexpected behavior and may break existing devices
in your tailnet.
2024-03-26 17:42:45 -04:00
</Dialog.Description>
2024-03-28 17:03:37 -04:00
<input
type='text'
className='border rounded-lg p-2 w-full mt-4'
value={newName}
onChange={event => {
setNewName(event.target.value)
}}
/>
<button
type='submit'
className='rounded-lg py-2 bg-gray-800 text-white w-full mt-2'
onClick={() => {
fetcher.submit({
'dns_config.base_domain': newName
}, {
method: 'PATCH',
encType: 'application/json'
})
setIsOpen(false)
setNewName(name)
}}
>
Rename
</button>
2024-03-26 17:42:45 -04:00
</Dialog.Panel>
</div>
</Dialog>
</>
)
}