From ee135f9d54e92350c5e639d64f1948ca41f47509 Mon Sep 17 00:00:00 2001
From: Miqdad <ahmadkimpir@gmail.com>
Date: Wed, 16 Apr 2025 14:40:48 +0700
Subject: <miqdad> make scroll to the error field

---
 src/lib/pengajuan-tempo/component/Pengiriman.jsx | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

(limited to 'src/lib/pengajuan-tempo/component/Pengiriman.jsx')

diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
index bbf22345..a8e7fd22 100644
--- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx
+++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
@@ -360,6 +360,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
     [errorsPengiriman]
   );
 
+  const tukarInvoiceInputRef = useRef(null);
+  const tukarInvoiceInputPembayaranRef = useRef(null);
   const PICNameRef = useRef(null);
   const streetPengirimanRef = useRef(null);
   const statePengirimanRef = useRef(null);
@@ -390,6 +392,14 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
           behavior: 'smooth',
           block: 'center',
         };
+        if (errorsPengiriman.tukarInvoiceInput && tukarInvoiceInputRef.current) {
+          tukarInvoiceInputRef.current.scrollIntoView(options);
+          return;
+        }
+        if (errorsPengiriman.tukarInvoiceInputPembayaran && tukarInvoiceInputPembayaranRef.current) {
+          tukarInvoiceInputPembayaranRef.current.scrollIntoView(options);
+          return;
+        }
         if (errorsPengiriman.PICName && PICNameRef.current) {
           PICNameRef.current.scrollIntoView(options);
           return;
@@ -1353,7 +1363,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                 <div className='w-2/5'>
                   <label className='form-label   text-wrap'>
                     Jadwal Penukaran Invoice{' '}
-                    <span className=' opacity-60'>(Wajib Diisi)</span>
                   </label>
                   {!isKonfirmasi && (
                     <span className='text-xs opacity-60'>
@@ -1370,6 +1379,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     value={formPengiriman.tukarInvoiceInput}
                     className='form-input'
                     rows={4}
+                    aria-invalid={errorsPengiriman.tukarInvoiceInput}
+                    ref={tukarInvoiceInputRef}
                     cols={40}
                     onChange={handleInputChange}
                     required
@@ -1386,7 +1397,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                 <div className='w-2/5'>
                   <label className='form-label text-nowrap'>
                     Jadwal Pembayaran{' '}
-                    <span className=' opacity-60'>(Wajib Diisi)</span>
                   </label>
                   {!isKonfirmasi && (
                     <span className='text-xs opacity-60'>
@@ -1401,6 +1411,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
                     placeholder='Masukkan jadwal pembayaran'
                     value={formPengiriman.tukarInvoiceInputPembayaran}
                     className='form-input'
+                    aria-invalid={errorsPengiriman.tukarInvoiceInputPembayaran}
+                    ref={tukarInvoiceInputPembayaranRef}
                     rows={4}
                     cols={40}
                     onChange={handleInputChange}
-- 
cgit v1.2.3

