'use client'; import Link from 'next/link'; import { ExternalLink } from '@/public/assets/external-link'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { Button } from '@kit/ui/button'; import { Checkbox } from '@kit/ui/checkbox'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@kit/ui/form'; import { Input } from '@kit/ui/input'; import { Trans } from '@kit/ui/trans'; import { UpdateAccountSchema } from '../_lib/schemas/update-account.schema'; import { onUpdateAccount } from '../_lib/server/update-account'; import { z } from 'zod'; type UpdateAccountFormValues = z.infer; export function UpdateAccountForm({ defaultValues, }: { defaultValues: UpdateAccountFormValues, }) { const form = useForm({ resolver: zodResolver(UpdateAccountSchema), mode: 'onChange', defaultValues, }); const { firstName, lastName, personalCode, email, weight, height, userConsent } = defaultValues; const hasFirstName = !!firstName; const hasLastName = !!lastName; const hasPersonalCode = !!personalCode; const hasEmail = !!email; const hasWeight = !!weight; const hasHeight = !!height; const hasUserConsent = !!userConsent; const onUpdateAccountOptions = async (values: UpdateAccountFormValues) => onUpdateAccount({ ...values, ...(hasFirstName && { firstName }), ...(hasLastName && { lastName }), ...(hasPersonalCode && { personalCode }), ...(hasEmail && { email }), ...(hasWeight && { weight: values.weight ?? weight }), ...(hasHeight && { height: values.height ?? height }), ...(hasUserConsent && { userConsent: values.userConsent ?? userConsent }), }); return (
( )} /> ( )} /> ( )} /> ( )} /> ( )} /> ( )} />
( field.onChange( e.target.value === '' ? null : Number(e.target.value), ) } /> )} /> ( field.onChange( e.target.value === '' ? null : Number(e.target.value), ) } /> )} />
(
)} /> ); }