From b027c12d678698a9b8adcf4508a6160321c8172a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 10 May 2023 15:11:55 +0700 Subject: Feature rfq, social media url, widget whatsapp offset --- src/lib/form/components/RequestForQuotation.jsx | 203 ++++++++++++++++++++++++ src/lib/product/components/ProductCard.jsx | 1 + src/lib/transaction/components/Transaction.jsx | 4 +- 3 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 src/lib/form/components/RequestForQuotation.jsx (limited to 'src/lib') diff --git a/src/lib/form/components/RequestForQuotation.jsx b/src/lib/form/components/RequestForQuotation.jsx new file mode 100644 index 00000000..cd8fbfd6 --- /dev/null +++ b/src/lib/form/components/RequestForQuotation.jsx @@ -0,0 +1,203 @@ +import odooApi from '@/core/api/odooApi' +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 getFileBase64 from '@/core/utils/getFileBase64' + +const RequestForQuotation = () => { + const { + register, + handleSubmit, + formState: { errors }, + control, + reset + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues + }) + const [cities, setCities] = useState([]) + + const quotationFileRef = useRef(null) + const recaptchaRef = useRef(null) + + useEffect(() => { + const loadCities = async () => { + let dataCities = await cityApi() + dataCities = dataCities.map((obj) => ({ value: obj.name, label: obj.name })) + setCities(dataCities) + } + loadCities() + }, []) + + const onSubmitHandler = async (values) => { + const recaptchaValue = recaptchaRef.current.getValue() + if (!recaptchaValue) { + toast.error('Recaptcha harus diisi') + return + } + + const file = quotationFileRef.current.files[0] + let fileBase64 = null + if (typeof file !== 'undefined') { + if (file.size > 5000000) { + toast.error('Maksimal ukuran file adalah 5MB') + return + } + fileBase64 = await getFileBase64(file) + } + + const data = { + name: `Request For Quotation - ${values.company}`, + email_from: values.email, + phone: values.phone, + description: [ + `Nama Perusahaan: ${values.company}`, + `No. Telepon: ${values.phone}`, + `Kota: ${values.city}`, + `No. Handphone: ${values.mobile}`, + `Alamat Email: ${values.email}`, + `Keterangan: ${values.description}` + ].join('\n') + } + + if (fileBase64) data.file_quotation = fileBase64 + + const createLead = await createLeadApi({ data }) + if (createLead) { + toast.success('Berhasil mengirimkan formulir request for quotation') + reset() + recaptchaRef.current.reset() + } + } + return ( +
+

Kunjungan Sales

+ +
+
+
+ Halaman untuk pengajuan penawaran harga, lengkapi data di bawah ini dengan jelas untuk + mempermudah tim support kami melayani kebutuhan Anda. Tim kami akan sesegera mungkin + untuk membuatkan penawaran harga terbaik, hubungi kami melalui telpon jika ada + keterlambatan pelayanan. +
+
+ + +
{errors.company?.message}
+
+ +
+ + +
{errors.phone?.message}
+
+ +
+ + } + /> +
{errors.city?.message}
+
+ +
+ + +
{errors.contactPerson?.message}
+
+ +
+ + +
{errors.mobile?.message}
+
+ +
+ + +
{errors.email?.message}
+
+ +
+ +