'use client'; import { useAppDispatch, useAppSelector } from '@akinon/next/redux/hooks'; import { checkoutApi } from '@akinon/next/data/client/checkout'; import { SubmitHandler, useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import * as yup from 'yup'; import { GuestLoginFormParams } from '@akinon/next/types'; import clsx from 'clsx'; import { Button, Checkbox, Input } from '@theme/components'; import { useLocalization } from '@akinon/next/hooks'; const GuestloginFormSchema = (t) => yup.object().shape({ user_email: yup .string() .email(t('checkout.auth.form.login.error.email_control')) .required(t('checkout.auth.form.login.error.required')), phone_number: yup .string() .transform((value: string) => value.replace(/_/g, '').replace(/ /g, '')) .length(11, t('checkout.auth.form.login.error.phone_control')) .required(t('checkout.auth.form.login.error.required')), sms_allowed: yup .boolean() .oneOf([true], t('checkout.auth.form.login.error.required')), kvkk_confirm: yup .boolean() .oneOf([true], t('checkout.auth.form.login.error.required')) }); const GuestLogin = () => { const { t } = useLocalization(); const { register, handleSubmit, control, formState: { errors }, setError } = useForm({ resolver: yupResolver(GuestloginFormSchema(t)) }); const { user_phone_format } = useAppSelector((state) => state.config); const dispatch = useAppDispatch(); const onSubmit: SubmitHandler = async (data) => { try { const response = await dispatch( checkoutApi.endpoints.guestLogin.initiate(data) ).unwrap(); Object.keys(response?.errors || {}).forEach((key) => { setError(key as keyof GuestLoginFormParams, { type: 'custom', message: response?.errors[key]?.join(', ') }); }); } catch (error) { console.error(error); } }; return (

{t('checkout.auth.form.login.agreement.label')}

{t('checkout.auth.form.login.agreement.terms_conditions')} {t('checkout.auth.form.login.agreement.privacy_policy')}
); }; export default GuestLogin;