import { useEffect } from 'react'; import { useNavigate, useParams, useLocation } from 'react-router-dom'; import { popHistory } from '../../utils/navigation'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useForm } from 'react-hook-form'; import { customerApi } from '../../services/api'; import Card from '../../components/ui/Card'; import Button from '../../components/ui/Button'; import Input from '../../components/ui/Input'; import Select from '../../components/ui/Select'; import type { Customer } from '../../types'; type CustomerFormData = Omit; export default function CustomerForm() { const { id } = useParams(); const navigate = useNavigate(); const location = useLocation(); const queryClient = useQueryClient(); const isEdit = !!id; const back = popHistory(location.state, isEdit ? `/customers/${id}` : '/customers'); const { register, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm(); const customerType = watch('type'); const { data: customer } = useQuery({ queryKey: ['customer', id], queryFn: () => customerApi.getById(parseInt(id!)), enabled: isEdit, }); useEffect(() => { if (customer?.data) { const data = { ...customer.data }; // Convert date strings to YYYY-MM-DD format for date inputs if (data.birthDate) { data.birthDate = data.birthDate.split('T')[0] as any; } if (data.foundingDate) { data.foundingDate = data.foundingDate.split('T')[0] as any; } // Boolean → String für v === 'true' || v === true, })} options={[ { value: 'false', label: 'Sie (formell)' }, { value: 'true', label: 'Du (informell)' }, ]} /> {customerType === 'BUSINESS' && ( <> setValue('foundingDate', '' as any)} /> )} setValue('birthDate', '' as any)} />
{customerType === 'BUSINESS' && (
{isEdit && (

Dokumente (Gewerbeanmeldung, Handelsregisterauszug) können nach dem Speichern in der Kundendetailansicht hochgeladen werden.

)}
)}