From b3be7e6d5c320764ef3ca38df196218abf9be25b Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Tue, 10 Dec 2024 10:05:47 +0700
Subject: <iman> move formulis & add state field

---
 src/lib/form/components/SuratDukungan.jsx | 33 ++++++++++++-------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

(limited to 'src/lib/form/components/SuratDukungan.jsx')

diff --git a/src/lib/form/components/SuratDukungan.jsx b/src/lib/form/components/SuratDukungan.jsx
index 31e7ee83..fadb2c57 100644
--- a/src/lib/form/components/SuratDukungan.jsx
+++ b/src/lib/form/components/SuratDukungan.jsx
@@ -1,5 +1,6 @@
 import HookFormSelect from '@/core/components/elements/Select/HookFormSelect';
 import cityApi from '@/lib/address/api/cityApi';
+import stateApi from '@/lib/address/api/stateApi.js';
 import { yupResolver } from '@hookform/resolvers/yup';
 import React, { useEffect, useRef, useState } from 'react';
 import ReCAPTCHA from 'react-google-recaptcha';
@@ -10,7 +11,7 @@ import createLeadsApi from '../api/createLeadApi';
 
 import PageContent from '@/lib/content/components/PageContent';
 
-import useAuth from '@/core/hooks/useAuth'
+import useAuth from '@/core/hooks/useAuth';
 import { useRouter } from 'next/router';
 
 const CreateSuratDukungan = () => {
@@ -20,32 +21,21 @@ const CreateSuratDukungan = () => {
     formState: { errors },
     control,
     reset,
+    watch,
+    setValue,
   } = useForm({
     resolver: yupResolver(validationSchema),
     defaultValues,
   });
-  const [cities, setCities] = useState([]);
   const [company_unit, setCompany_unit] = useState([]);
 
   const recaptchaRef = useRef(null);
-  const router = useRouter()
+  const router = useRouter();
 
-  const auth = useAuth()
-
-  useEffect(() => {
-    if(auth == false) {
-      router.push('/login')
-    }
-    const loadCities = async () => {
-      let dataCities = await cityApi();
-      dataCities = dataCities.map((city) => ({
-        value: city.id,
-        label: city.name,
-      }));
-      setCities(dataCities);
-    };
-    loadCities();
-  }, [auth]);
+  const auth = useAuth();
+  if (auth == false) {
+    router.push(`/login?next=${encodeURIComponent('/surat-dukungan')}`);
+  }
 
   const onSubmitHandler = async (values) => {
     const recaptchaValue = recaptchaRef.current.getValue();
@@ -85,6 +75,9 @@ const CreateSuratDukungan = () => {
       recaptchaRef.current.reset();
     }
   };
+  if (!auth) {
+    return;
+  }
   return (
     <div className='container mx-auto p-4 md:p-0 my-0 md:my-10'>
       <h1 className='text-h-sm md:text-title-sm font-semibold mb-6'>
@@ -241,7 +234,7 @@ const CreateSuratDukungan = () => {
               </div>
             </form>
           </div>
-          <PageContent path='/surat-dukungan'/>
+          <PageContent path='/surat-dukungan' />
         </div>
       </div>
     </div>
-- 
cgit v1.2.3

