From 043cb69422f14a6c761e60ca2f6feeb8623676b7 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 13 Apr 2023 09:03:15 +0700 Subject: pembayaran tempo dan form kunjungan sales --- src/core/components/form/CreatePembayaranTempo.jsx | 125 -------------- src/lib/form/api/createLeadsApi.js | 8 + src/lib/form/components/CreatePembayaranTempo.jsx | 131 ++++++++++++++ src/lib/form/components/KunjunganSales.jsx | 188 +++++++++++++++++++++ src/pages/my/kunjungan-sales.jsx | 17 ++ src/pages/pembayaran-tempo.jsx | 5 +- 6 files changed, 345 insertions(+), 129 deletions(-) delete mode 100644 src/core/components/form/CreatePembayaranTempo.jsx create mode 100644 src/lib/form/api/createLeadsApi.js create mode 100644 src/lib/form/components/CreatePembayaranTempo.jsx create mode 100644 src/lib/form/components/KunjunganSales.jsx create mode 100644 src/pages/my/kunjungan-sales.jsx (limited to 'src') diff --git a/src/core/components/form/CreatePembayaranTempo.jsx b/src/core/components/form/CreatePembayaranTempo.jsx deleted file mode 100644 index 88e4aec9..00000000 --- a/src/core/components/form/CreatePembayaranTempo.jsx +++ /dev/null @@ -1,125 +0,0 @@ -import HookFormSelect from '@/core/components/elements/Select/HookFormSelect' -import { yupResolver } from '@hookform/resolvers/yup' -import React, { useRef } 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' - -const CreatePembayaranTempo = () => { - const { - register, - handleSubmit, - formState: { errors } - } = useForm({ - resolver: yupResolver(validationSchema), - defaultValues - }) - - const recaptchaRef = useRef(null) - - const onSubmitHandler = async (values) => { - const recaptchaValue = recaptchaRef.current.getValue() - if (!recaptchaValue) { - toast.error('Catcha harus diisi') - return - } - const data = { - ...values - } - - const address = await createAddressApi({ data }) - if (address?.id) { - toast.success('Berhasil menambahkan alamat') - router.back() - } - } - return ( -
-

Pembayaran Tempo

-
-
-
-
- - -
{errors.email?.message}
-
-
-
-
- - -
{errors.name?.message}
-
-
-
-
- - -
{errors.npwp?.message}
-
-
-
-
- - -
-
-
-
- - - {/*
{errors.name?.message}
*/} -
-
-
-
- - - {/*
{errors.name?.message}
*/} -
-
- -
-
- -
-
-
-
- -
-
-
-
-
- ) -} -const validationSchema = Yup.object().shape({ - name: Yup.string().min(3, 'Minimal 3 karakter').required('Harus di-isi'), - email: Yup.string().email('Format harus seperti contoh@email.com').required('Harus di-isi'), - npwp: Yup.string().required('Harus di-isi') -}) -const defaultValues = { - name: '', - email: '', - npwp: '', - siup: '', - tdp: '', - nib: '' -} - -export default CreatePembayaranTempo diff --git a/src/lib/form/api/createLeadsApi.js b/src/lib/form/api/createLeadsApi.js new file mode 100644 index 00000000..5665de2c --- /dev/null +++ b/src/lib/form/api/createLeadsApi.js @@ -0,0 +1,8 @@ +import odooApi from '@/core/api/odooApi' + +const createLeadsApi = async ({ data }) => { + const leads = await odooApi('POST', '/api/v1/lead', data) + return leads +} + +export default createLeadsApi diff --git a/src/lib/form/components/CreatePembayaranTempo.jsx b/src/lib/form/components/CreatePembayaranTempo.jsx new file mode 100644 index 00000000..63a013aa --- /dev/null +++ b/src/lib/form/components/CreatePembayaranTempo.jsx @@ -0,0 +1,131 @@ +import HookFormSelect from '@/core/components/elements/Select/HookFormSelect' +import getFileBase64 from '@/core/utils/getFileBase64' +import { yupResolver } from '@hookform/resolvers/yup' +import React, { useRef } 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' + +const CreatePembayaranTempo = () => { + const { + register, + handleSubmit, + formState: { errors } + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues + }) + + const recaptchaRef = useRef(null) + const npwp = useRef(null) + + const onSubmitHandler = async (values) => { + const recaptchaValue = recaptchaRef.current.getValue() + if (!recaptchaValue) { + toast.error('Catcha harus diisi') + return + } + const data = { + ...values, + name : 'Pengajuan Pembayaran Tempo - ' + values.name, + file_npwp : values.npwp.length > 0 ? await getFileBase64(values.npwp) : '' + } + + console.log('ini adalah data', data) + + // const address = await createLeadsApi({ data }) + // if (address?.id) { + // toast.success('Berhasil menambahkan alamat') + // router.back() + // } + } + return ( +
+

Pembayaran Tempo

+
+
+
+
+ + +
{errors.email?.message}
+
+
+
+
+ + +
{errors.name?.message}
+
+
+
+
+ + +
{errors.npwp?.message}
+
+
+
+
+ + +
+
+
+
+ + + {/*
{errors.name?.message}
*/} +
+
+
+
+ + + {/*
{errors.name?.message}
*/} +
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+
+ ) +} +const validationSchema = Yup.object().shape({ + name: Yup.string().min(3, 'Minimal 3 karakter').required('Harus di-isi'), + email: Yup.string().email('Format harus seperti contoh@email.com').required('Harus di-isi'), + npwp: Yup.string().required('Harus di-isi') +}) +const defaultValues = { + name: '', + email: '', + npwp: '', + siup: '', + tdp: '', + nib: '' +} + +export default CreatePembayaranTempo diff --git a/src/lib/form/components/KunjunganSales.jsx b/src/lib/form/components/KunjunganSales.jsx new file mode 100644 index 00000000..b96fddb5 --- /dev/null +++ b/src/lib/form/components/KunjunganSales.jsx @@ -0,0 +1,188 @@ +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' + +const CreateKunjunganSales = () => { + const { + register, + handleSubmit, + formState: { errors }, + control + } = 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 + } + + const address = await createAddressApi({ data }) + if (address?.id) { + toast.success('Berhasil menambahkan alamat') + router.back() + } + } + return ( +
+

Kunjungan Sales

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