From 629915609473ea886e106b264e45bd6f971d85c2 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 14 Apr 2023 14:04:36 +0700 Subject: kunjungan sales --- src/lib/form/components/KunjunganService.jsx | 204 +++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 src/lib/form/components/KunjunganService.jsx (limited to 'src/lib') diff --git a/src/lib/form/components/KunjunganService.jsx b/src/lib/form/components/KunjunganService.jsx new file mode 100644 index 00000000..dfe5873e --- /dev/null +++ b/src/lib/form/components/KunjunganService.jsx @@ -0,0 +1,204 @@ +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 createLeadsApi from '../api/createLeadsApi' + +const CreateKunjunganService = () => { + const { + register, + handleSubmit, + formState: { errors }, + control, + reset + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues + }) + const [cities, setCities] = useState([]) + const [company_unit, setCompany_unit] = useState([]) + + 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 : 'Pengajuan Kunjungan Service - ' + values.company, + contact_name : values.cp, + email_from : values.email, + phone : values.mobile, + description : "\r\n Nama Perusahaan : " + values.company + " \r\n Alamat : " + values.address + " \r\n Propinsi : " + values.city + " \r\n Telepon: " + values.phone + " \r\n Handphone : " + values.mobile +" \r\n Email : " + values.email + " \r\n Keterangan : " + values.description , + } + + const create_leads = await createLeadsApi({ data }) + if (create_leads) { + toast.success('Berhasil menambahkan alamat') + reset() + recaptchaRef.current.reset() + } + } + return ( +
+

Kunjungan Service

+
+ +
+
+
+ + +
{errors.company?.message}
+
+
+
+
+ + +
{errors.phone?.message}
+
+
+
+
+ + +
{errors.address?.message}
+
+
+
+
+ + } + /> +
{errors.city?.message}
+
+
+
+
+ + +
+ {errors.cp?.message} +
+
+
+
+
+ + +
{errors.mobile?.message}
+
+
+
+
+ + +
{errors.email?.message}
+
+
+
+
+ +