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 +++++++++++++++++++++++++++++ src/pages/media-relations.jsx | 16 ++ src/pages/my/kunjungan-sales.jsx | 2 +- src/pages/my/kunjungan-service.jsx | 2 +- src/pages/my/merchant.jsx | 2 +- src/pages/my/surat-dukungan.jsx | 2 +- 6 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 src/lib/form/components/MediaRelations.jsx create mode 100644 src/pages/media-relations.jsx (limited to 'src') 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 diff --git a/src/pages/media-relations.jsx b/src/pages/media-relations.jsx new file mode 100644 index 00000000..afdb61ec --- /dev/null +++ b/src/pages/media-relations.jsx @@ -0,0 +1,16 @@ +import Seo from '@/core/components/Seo' +import BasicLayout from '@/core/components/layouts/BasicLayout' +import CreateMediaRelations from '@/lib/form/components/MediaRelations' + +export default function media_relations() { + + return ( + <> + + + + + + + ) +} diff --git a/src/pages/my/kunjungan-sales.jsx b/src/pages/my/kunjungan-sales.jsx index 63e95837..052991d9 100644 --- a/src/pages/my/kunjungan-sales.jsx +++ b/src/pages/my/kunjungan-sales.jsx @@ -2,7 +2,7 @@ import Seo from '@/core/components/Seo' import BasicLayout from '@/core/components/layouts/BasicLayout' import KunjunganSales from '@/lib/form/components/KunjunganSales' -export default function pembayaran_tempo() { +export default function kunjungan_sales() { return ( <> diff --git a/src/pages/my/kunjungan-service.jsx b/src/pages/my/kunjungan-service.jsx index 80d1ecbc..28697804 100644 --- a/src/pages/my/kunjungan-service.jsx +++ b/src/pages/my/kunjungan-service.jsx @@ -2,7 +2,7 @@ import Seo from '@/core/components/Seo' import BasicLayout from '@/core/components/layouts/BasicLayout' import CreateKunjunganService from '@/lib/form/components/KunjunganService' -export default function pembayaran_tempo() { +export default function kunjungan_service() { return ( <> diff --git a/src/pages/my/merchant.jsx b/src/pages/my/merchant.jsx index 9cb83a0f..a6f71c8b 100644 --- a/src/pages/my/merchant.jsx +++ b/src/pages/my/merchant.jsx @@ -3,7 +3,7 @@ import BasicLayout from '@/core/components/layouts/BasicLayout' import CreateMerchant from '@/lib/form/components/Merchant' import CreateSuratDukungan from '@/lib/form/components/SuratDukungan' -export default function pembayaran_tempo() { +export default function merchant() { return ( <> diff --git a/src/pages/my/surat-dukungan.jsx b/src/pages/my/surat-dukungan.jsx index 8c469d02..a19c60d6 100644 --- a/src/pages/my/surat-dukungan.jsx +++ b/src/pages/my/surat-dukungan.jsx @@ -3,7 +3,7 @@ import BasicLayout from '@/core/components/layouts/BasicLayout' import CreateKunjunganService from '@/lib/form/components/KunjunganService' import CreateSuratDukungan from '@/lib/form/components/SuratDukungan' -export default function pembayaran_tempo() { +export default function surat_dukungan() { return ( <> -- cgit v1.2.3