From a24bfba1ba58940e65ca800417169caf70edc058 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 18 Apr 2023 16:12:37 +0700 Subject: media relations --- src/lib/form/components/MediaRelations.jsx | 237 +++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 src/lib/form/components/MediaRelations.jsx (limited to 'src/lib/form/components') diff --git a/src/lib/form/components/MediaRelations.jsx b/src/lib/form/components/MediaRelations.jsx new file mode 100644 index 00000000..05ae7e03 --- /dev/null +++ b/src/lib/form/components/MediaRelations.jsx @@ -0,0 +1,237 @@ +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' + +const CreateMediaRelations = () => { + const { + register, + handleSubmit, + formState: { errors }, + control, + reset + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues + }) + const list_unit = [ + { + value: 'Media Cetak', + label: 'Media Cetak' + }, + { + value: 'Media', + 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 attachment = document.getElementById('attachment').files[0] + + 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 Media dan Relasi

+
+
+
+
+ + +
{errors.name?.message}
+
+
+
+
+ + +
{errors.company?.message}
+
+
+
+
+ + +
{errors.email?.message}
+
+
+
+
+ + +
{errors.phone?.message}
+
+
+
+
+ + } + /> +
+ {errors.company_unit?.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 CreateMediaRelations -- cgit v1.2.3