diff --git a/src/components/equipment-edit-form/index.tsx b/src/components/equipment-edit-form/index.tsx index 5d1290d7..5d3cc27f 100644 --- a/src/components/equipment-edit-form/index.tsx +++ b/src/components/equipment-edit-form/index.tsx @@ -4,7 +4,6 @@ import { AxiosResponse } from 'axios'; import { useEffect } from 'react'; import { Button, Flex, Grid, GridItem } from '@chakra-ui/react'; import { Datepicker } from '../form-fields/date'; -import { ControlledSelect } from '../form-fields/controlled-select'; import { ESTADOS_EQUIPAMENTO, @@ -16,28 +15,29 @@ import { Input } from '../form-fields/input'; import { TextArea } from '../form-fields/text-area'; import { toast } from '@/utils/toast'; import { api } from '@/config/lib/axios'; +import { NewControlledSelect } from '../form-fields/new-controlled-select'; export type EditEquipFormValues = { tippingNumber: string; serialNumber: string; - type: { value: string; label: string }; + type: string; situacao: string; model: string; description?: string; - initialUseDate: { value: number; label: string }; + initialUseDate: number; acquisitionDate: Date; screenSize?: string; invoiceNumber: string; power?: string; - screenType?: { value: string; label: string }; + screenType?: string; processor?: string; - storageType?: { value: string; label: string }; + storageType?: string; storageAmount?: string; brandName: string; acquisition: { name: string }; unitId?: string; ram_size?: string; - estado: { value: string; label: string }; + estado: string; }; interface EditEquipmentFormProps { @@ -114,11 +114,11 @@ export default function EquipmentEditForm({ const dateString = formatDate(acquisitionDate); const payload = { - type: type.value, - estado: estado.value, - initialUseDate: initialUseDate.value, - storageType: storageType?.value, - screenType: screenType?.value, + type, + estado, + initialUseDate, + storageType, + screenType, acquisitionDate: dateString, ...rest, }; @@ -141,13 +141,15 @@ export default function EquipmentEditForm({ return (
- @@ -215,7 +217,7 @@ export default function EquipmentEditForm({ })} /> - - - {watchType.value === 'CPU' && ( + {watchType === 'CPU' && ( <> - )} - {watchType.value === 'Monitor' && ( + {watchType === 'Monitor' && ( <> - )} - {(watchType.value === 'Estabilizador' || - watchType.value === 'Nobreak') && ( + {(watchType === 'Estabilizador' || watchType === 'Nobreak') && ( (); - const watchType = watch('type', { label: '', value: '' }); + const watchType = watch('type'); useEffect(() => { resetField('power'); @@ -86,11 +86,11 @@ export default function EquipmentForm({ formData; const payload = { - type: type.value, - estado: estado.value, - initialUseDate: initialUseDate.value, - storageType: storageType?.value, - screenType: screenType?.value, + type, + estado, + initialUseDate, + storageType, + screenType, ...rest, }; @@ -121,7 +121,7 @@ export default function EquipmentForm({ return ( - - - - {watchType.value === 'CPU' && ( + {watchType === 'CPU' && ( <> - )} - {watchType.value === 'Monitor' && ( + {watchType === 'Monitor' && ( <> - )} - {(watchType.value === 'Estabilizador' || - watchType.value === 'Nobreak') && ( + {(watchType === 'Estabilizador' || watchType === 'Nobreak') && ( - - - - {equipment.type.value === 'CPU' && ( + {equipment.type === 'CPU' && ( <> - )} - {equipment.type.value === 'Monitor' && ( + {equipment.type === 'Monitor' && ( <> - )} - {(equipment.type.value === 'Estabilizador' || - equipment.type.value === 'Nobreak') && ( + {(equipment.type === 'Estabilizador' || + equipment.type === 'Nobreak') && ( )} @@ -298,10 +259,9 @@ export default function EquipmentViewForm({ label="Descrição" errors={errors.description} maxChars={255} - {...register('description', { - maxLength: 255, - })} + {...register('description')} readOnly + disabled /> diff --git a/src/components/equipment-view-modal/index.tsx b/src/components/equipment-view-modal/index.tsx index e10d350c..3159d8d9 100644 --- a/src/components/equipment-view-modal/index.tsx +++ b/src/components/equipment-view-modal/index.tsx @@ -17,30 +17,8 @@ function transformFields(data: any) { if (!data) return; const transformedData = { ...data }; - transformedData.type = { - label: transformedData.type, - value: transformedData.type, - }; - - transformedData.estado = { - label: transformedData.estado, - value: transformedData.estado, - }; - - transformedData.storageType = { - label: transformedData.storageType, - value: transformedData.storageType, - }; - - transformedData.screenType = { - label: transformedData.screenType, - value: transformedData.screenType, - }; - - transformedData.initialUseDate = { - label: transformedData.initialUseDate.split('-')[0], - value: transformedData.initialUseDate.split('-')[0], - }; + transformedData.initialUseDate = + transformedData.initialUseDate.split('-')?.[0]; transformedData.brandName = transformedData.brand.name; diff --git a/src/components/form-fields/equipment/equipment-form.tsx b/src/components/form-fields/equipment/equipment-form.tsx deleted file mode 100644 index 1ac9ad87..00000000 --- a/src/components/form-fields/equipment/equipment-form.tsx +++ /dev/null @@ -1,306 +0,0 @@ -import { useForm } from 'react-hook-form'; -import { AxiosResponse } from 'axios'; -import { useEffect } from 'react'; -import { Button, Flex, Grid, GridItem } from '@chakra-ui/react'; - -import { - ESTADOS_EQUIPAMENTO, - TIPOS_ARMAZENAMENTO, - TIPOS_EQUIPAMENTO, - TIPOS_MONITOR, -} from '@/constants/equipment'; -import { toast } from '@/utils/toast'; -import { ControlledSelect } from '../controlled-select'; -import { Datepicker } from '../date'; -import { TextArea } from '../text-area'; -import { Input } from '../input'; -import { api } from '@/config/lib/axios'; - -type FormValues = { - tippingNumber: string; - serialNumber: string; - type: { value: string; label: string }; - situacao: string; - model: string; - description?: string; - initialUseDate: { value: string; label: string }; - acquisitionDate: string; - screenSize?: string; - invoiceNumber: string; - power?: string; - screenType?: { value: string; label: string }; - processor?: string; - storageType?: { value: string; label: string }; - storageAmount?: string; - brandName: string; - acquisitionName: string; - unitId?: string; - ram_size?: string; - estado: { value: string; label: string }; -}; - -interface EquipmentFormProps { - onClose: () => void; -} - -export default function EquipmentForm({ onClose }: EquipmentFormProps) { - const { - control, - register, - handleSubmit, - watch, - resetField, - formState: { errors }, - } = useForm(); - - const watchType = watch('type', { label: '', value: '' }); - - useEffect(() => { - resetField('power'); - resetField('screenSize'); - resetField('screenType'); - resetField('ram_size'); - resetField('processor'); - resetField('storageType'); - resetField('storageAmount'); - }, [resetField, watchType]); - - const listOfYears: Array<{ value: number; label: string }> = (() => { - const endYear: number = new Date().getFullYear(); - const startYear: number = endYear - 30; - - return Array.from({ length: endYear - startYear + 1 }, (_, index) => { - const year = startYear + index; - return { value: year, label: year.toString() }; - }).reverse(); - })(); - - const onSubmit = handleSubmit(async (formData) => { - try { - const { type, estado, initialUseDate, storageType, screenType, ...rest } = - formData; - - const payload = { - type: type.value, - estado: estado.value, - initialUseDate: initialUseDate.value, - storageType: storageType?.value, - screenType: screenType?.value, - ...rest, - }; - - const response = await api.post('equipment/createEquipment', payload); - - if (response.status === 200) { - toast.success('Equipamento cadastrado com sucesso', 'Sucesso'); - onClose(); - return; - } - toast.error('Erro ao tentar cadastrar o equipamento', 'Erro'); - } catch { - toast.error('Erro ao tentar cadastrar o equipamento', 'Erro'); - } - }); - - return ( - - - - - - - - - - - - - - - - - - - - - {watchType.value === 'CPU' && ( - <> - - - - - - )} - - {watchType.value === 'Monitor' && ( - <> - - - - )} - - {(watchType.value === 'Estabilizador' || - watchType.value === 'Nobreak') && ( - - )} - -