import { useAppForm, Form } from '@/components/form'; import { type AdminNode, updateAdminNodeInput, useUpdateAdminNode } from '@/api/admin/nodes/queries'; import { useAllAdminLocations } from '@/api/admin/locations/queries'; import { type NodeFormValues, nodeFormValues, nodeNumberValidators, nodeValuesFromForm, } from '@/components/admin/nodes/nodeForm'; import { useNodeDetail } from '@/components/admin/nodes/useNodeDetail'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; interface Values extends NodeFormValues { resetSecret: boolean; } const nodeToValues = (node: AdminNode): Values => ({ ...nodeFormValues(node), resetSecret: false }); const NodeSettingsForm = () => { const { node } = useNodeDetail(); const updateNode = useUpdateAdminNode(); const { data: locations = [] } = useAllAdminLocations(); const form = useAppForm({ defaultValues: nodeToValues(node), onSubmit: async ({ value }) => { const { resetSecret, ...values } = value; try { await updateNode.mutateAsync( updateAdminNodeInput(node.attributes.id, nodeValuesFromForm(values), resetSecret) ); form.setFieldValue('resetSecret', false); } catch { // Error toast is handled by the mutation. } }, }); return (
); }; export default function NodeSettingsTab() { const { node } = useNodeDetail(); return