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'; import { useRouter } from 'next/router'; import useAuth from '@/core/hooks/useAuth' 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); const router = useRouter() const auth = useAuth() useEffect(() => { if(auth == false) { router.push('/login') } const loadCities = async () => { let dataCities = await cityApi(); dataCities = dataCities.map((city) => ({ value: city.id, label: city.name, })); setCities(dataCities); }; loadCities(); }, [auth]); 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 (
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.{' '}