import HookFormSelect from '@/core/components/elements/Select/HookFormSelect'; import cityApi from '@/lib/address/api/cityApi'; import { yupResolver } from '@hookform/resolvers/yup'; import React, { useEffect, useRef, useState } from 'react'; import ReCAPTCHA from 'react-google-recaptcha'; import { Controller, useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; import * as Yup from 'yup'; import createLeadApi from '../api/createLeadApi'; import PageContent from '@/lib/content/components/PageContent'; const CreateMerchant = () => { const { register, handleSubmit, formState: { errors }, control, reset, } = useForm({ resolver: yupResolver(validationSchema), defaultValues, }); const list_unit = [ { value: 'Manufacturing', label: 'Manufacturing', }, { value: 'Hospitality', label: 'Hospitality', }, { value: 'Automotive', label: 'Automotive', }, { value: 'Retail', label: 'Retail', }, { value: 'Maining', label: 'Maining', }, { value: 'Lain - Lain', label: 'Lain - Lain', }, ]; const [cities, setCities] = useState([]); const [company_unit, setCompany_unit] = useState(list_unit); const recaptchaRef = useRef(null); useEffect(() => { const loadCities = async () => { let dataCities = await cityApi(); dataCities = dataCities.map((city) => ({ value: city.id, label: city.name, })); setCities(dataCities); }; loadCities(); }, []); const onSubmitHandler = async (values) => { const recaptchaValue = recaptchaRef.current.getValue(); if (!recaptchaValue) { toast.error('Catcha harus diisi'); return; } const data = { ...values, name: 'Form Merchant - ' + values.company, contact_name: values.cp, email_from: values.email, phone: values.phone, description: 'Nama Perusahaan : ' + values.company + ' \r\n Alamat : ' + values.address + ' \r\n Kota : ' + values.city + ' \r\n Unit Perusahaan : ' + values.company_unit + ' \r\n Telepon: ' + values.phone + ' \r\n Email : ' + values.email + ' \r\n Website : ' + values.website + ' \r\n No Hp : ' + values.mobile + 'Keterangan : ' + values.description, }; const create_leads = await createLeadApi({ data }); if (create_leads) { toast.success('Berhasil menambahkan data'); reset(); recaptchaRef.current.reset(); } }; return (

Form Merchant

Penjualan online adalah hal yang HARUS dilakukan mulai sekarang. Perubahan dalam banyak industri dan pola pembelian. Gabung dengan platform kami dan mulai penjualan lansung di ribuan perusahaan d seluruh Indonesia.{' '}

{errors.company?.message}
{errors.address?.message}
{errors.phone?.message}
( )} />
{errors.city?.message}
( )} />
{errors.company_unit?.message}
{errors.website?.message}
{errors.cp?.message}
{errors.mobile?.message}
{errors.email?.message}
); }; const validationSchema = Yup.object().shape({ company: Yup.string().required('Harus di-isi'), email: Yup.string() .email('Format harus seperti contoh@email.com') .required('Harus di-isi'), phone: Yup.string().required('Harus di-isi'), cp: Yup.string().required('Harus di-isi'), city: Yup.string().required('Harus di-isi'), company_unit: Yup.string().required('Harus di-isi'), address: Yup.string().required('Harus di-isi'), website: Yup.string().required('Harus di-isi'), mobile: Yup.string().required('Harus di-isi'), }); const defaultValues = { company: '', email: '', phone: '', city: '', company_unit: '', cp: '', address: '', website: '', mobile: '', }; export default CreateMerchant;