import { useState } from 'react' import { useNavigate, useOutletContext } from 'react-router-dom' import { useForm, hasLength } from '@mantine/form' import { Paper, Center, Stack, Group, Text, TextInput, Textarea, Button } from '@mantine/core' import { useAppSelector } from '../app/hooks' import { useDeletePanelByIdMutation, useUpdatePanelByIdMutation } from '../app/api/panels' import type { Panel } from '../app/types/common' import type { UpdatePanelData } from '../app/types/panels' import type { PanelContext } from '../components/PanelLayout' const UpdatePanelForm = ({ panel, setPanel, setModifying, setErrorMsg }: { panel: Panel, setPanel: React.Dispatch, setModifying: React.Dispatch, setErrorMsg: React.Dispatch }) => { const panelForm = useForm({ initialValues: { name: panel.name, description: panel.description, }, validate: { name: hasLength({ min: 3, max: 20 }, 'Name must be between 3 and 20 characters long'), description: hasLength({ min: 3, max: 512 }, 'Description must be between 3 and 512 characters'), } }) const [updatePanel, { isLoading }] = useUpdatePanelByIdMutation() const submitUpdatePanel = async (values: UpdatePanelData) => { await updatePanel({ id: panel.id, data: values }).unwrap().then((panelInfo) => { setErrorMsg('') setModifying(false) setPanel(panelInfo) }).catch((error) => { if (!error.data) { setErrorMsg('Failed to access the API') } else { setErrorMsg(error.data.msg) } }) } return (