From 8ddfe28897d63d96e85dc53b12376ac2d6407969 Mon Sep 17 00:00:00 2001 From: Malini Date: Tue, 6 Jan 2026 16:08:06 +0530 Subject: [PATCH] Added changes in edit profile --- .../survey/ProductData/ProductData.jsx | 29 ++- .../src/pages/Admin/Validations.jsx | 10 +- .../Admin/configuration/CompanyProfile.jsx | 134 +++++++---- .../configuration/EditCompanyProfile.jsx | 212 ++++++++++-------- 4 files changed, 242 insertions(+), 143 deletions(-) diff --git a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx index aad7a43..08146e5 100644 --- a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx +++ b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx @@ -33,6 +33,19 @@ const Input = ({ placeholder = '', type = 'text', value = '', onChange = () => { borderColor = 'border-[#92722A]'; } + // Handle input change with validation + const handleChange = (e) => { + if (type === 'number') { + // Only allow numbers and empty string + const newValue = e.target.value; + if (newValue === '' || /^\d+$/.test(newValue)) { + onChange(e); + } + } else { + onChange(e); + } + }; + // Prevent wheel event from changing the number input value const handleWheel = (e) => { if (type === 'number') { @@ -40,18 +53,28 @@ const Input = ({ placeholder = '', type = 'text', value = '', onChange = () => { } }; + // Prevent typing non-numeric characters in number inputs + const handleKeyPress = (e) => { + if (type === 'number' && !/^\d$/.test(e.key) && e.key !== 'Backspace' && e.key !== 'Delete' && e.key !== 'Tab') { + e.preventDefault(); + } + }; + return (
setIsFocused(true)} onBlur={() => setIsFocused(false)} onWheel={handleWheel} required={required} - className={`block w-full h-10 rounded-md border-2 ${borderColor} focus:ring-0 px-4 text-sm ${bgColor} transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`} + className={`block w-full h-10 rounded-md border-2 ${borderColor} focus:ring-0 px-4 text-sm ${bgColor} transition-colors`} />
); diff --git a/ipi-survey-platform/src/pages/Admin/Validations.jsx b/ipi-survey-platform/src/pages/Admin/Validations.jsx index 9e3948e..efa0162 100644 --- a/ipi-survey-platform/src/pages/Admin/Validations.jsx +++ b/ipi-survey-platform/src/pages/Admin/Validations.jsx @@ -67,10 +67,16 @@ const ManageSubmissions = () => { const [error, setError] = React.useState(null); const [search, setSearch] = React.useState(''); const [year, setYear] = React.useState(''); - const [quarter, setQuarter] = React.useState('All'); + // Function to get current quarter (1-4) + const getCurrentQuarter = () => { + const month = new Date().getMonth(); + return `Q${Math.floor(month / 3) + 1}`; + }; + + const [quarter, setQuarter] = React.useState(getCurrentQuarter()); const [emirate, setEmirate] = React.useState('All'); const [status, setStatus] = React.useState('All'); - const [selectedQuarter, setSelectedQuarter] = React.useState('All'); + const [selectedQuarter, setSelectedQuarter] = React.useState(getCurrentQuarter()); const [selectedYear, setSelectedYear] = React.useState(new Date().getFullYear().toString()); const [currentPage, setCurrentPage] = React.useState(1); const [toast, setToast] = React.useState(null); diff --git a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx index 7df4ac9..c0b3a3a 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx @@ -657,11 +657,11 @@ const CompanyProfile = () => { const formSteps = React.useMemo( () => [ - { label: 'User Profile' }, - { label: 'Identification Particulars' }, - { label: 'Establishment Contact Details' }, + { label: 'Profile' }, + { label: 'Details' }, + { label: 'Contact Details' }, { label: 'Products' }, - { label: 'Employment in Establishment' }, + { label: 'Employment Details' }, ], [] ); @@ -676,7 +676,7 @@ const CompanyProfile = () => { { field: 'permanentFactoryCode', label: 'Permanent Factory Code' }, { field: 'uniqueLicenseNumber', label: 'Unique License Number' }, { field: 'industryCodeBusiness', label: 'Industry Code (Business Register)' }, - { field: 'industryCodeCurrent', label: 'Industry Code (Current Production)' }, + { field: 'industryCodeProduction', label: 'Industry Code (Current Production)' }, ], 2: [ { field: 'contactName', label: 'Name' }, @@ -902,7 +902,7 @@ const CompanyProfile = () => { return (
-

User Profile

+

Profile

{

- Identification Particulars + Details

@@ -1017,6 +1017,8 @@ const CompanyProfile = () => { onChange={handleFormChange('industryCodeBusiness')} placeholder="Enter Code" width="100%" + required + error={fieldErrors.industryCodeBusiness} readOnly={modalMode === 'view'} /> @@ -1026,6 +1028,8 @@ const CompanyProfile = () => { onChange={handleFormChange('industryCodeProduction')} placeholder="Enter Code" width="100%" + required + error={fieldErrors.industryCodeProduction} readOnly={modalMode === 'view'} />
@@ -1077,7 +1081,7 @@ const CompanyProfile = () => { return (
-

Establishment Contact Details

+

Contact Details

{ case 4: return (
-

Employment in Establishment

+

Employment Details

{
- {/* Selected Products Panel */} -
-
-
Selected Products
- {selectedProducts.length > 0 && ( - - {selectedProducts.length} selected - - )} -
-
- {selectedProducts.length > 0 ? ( -
    - {selectedProducts.map((product) => ( -
  • -
    -
    - {product.hs_code || product.hsCode || ''} - {(product.hs_code || product.hsCode) ? ' - ' : ''} - {product.product_name || product.productName || product.label || 'Unnamed Product'} -
    -
    - {modalMode !== 'view' && ( - - )} -
  • - ))} -
- ) : ( -
- - -
- )} +{/* Selected Products Panel */} +
+
+
Selected Products
+ + {selectedProducts.length > 0 && ( + + {selectedProducts.length} selected + + )} +
+ +
+ + {selectedProducts.length > 0 ? ( +
    + + {selectedProducts.map((product) => { + // Extract product name and HS code + let name = product.product_name || product.productName || product.label || ''; + let hsCode = product.hs_code || product.hsCode || product.value; + + // If name contains a pattern like "59061000 - Product Name", extract the product name and HS code + const nameParts = name.split(' - '); + if (nameParts.length > 1 && /^\d+$/.test(nameParts[0])) { + hsCode = nameParts[0]; + name = nameParts.slice(1).join(' - ').trim(); + } + + return ( +
  • +
    + {/* Product Name */} +
    + {name || 'Unnamed Product'}
    + + {/* HS Code under it */} + {hsCode && ( +
    + HS Code: {hsCode} +
    + )}
    + + {/* Remove button */} + {modalMode !== 'view' && ( + + )} +
  • + ); + })} + +
+ ) : ( +
+ - +
+ )} +
+
+ + +
); @@ -2385,6 +2421,7 @@ const handleView = async (id) => { const emptyProfile = createEmptyProfile(); Object.assign(emptyProfile, computeEmploymentTotals(emptyProfile)); setModalMode('add'); + setIsViewMode(false); // Ensure view mode is false when adding setForm(emptyProfile); setEditingRow(null); setActiveStep(0); @@ -2408,6 +2445,7 @@ const handleView = async (id) => { setForm(emptyProfile); setEditingRow(null); setModalMode('add'); + setIsViewMode(false); // Ensure view mode is false when adding initialSnapshotRef.current = emptyProfile; corporateBackupRef.current = captureCorporateValues(emptyProfile); setIsDirty(false); diff --git a/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx b/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx index 80fe005..35aeefb 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/EditCompanyProfile.jsx @@ -106,11 +106,11 @@ const EditCompanyProfile = () => { const formSteps = React.useMemo( () => [ - { label: 'User Profile' }, - { label: 'Identification Particulars' }, - { label: 'Establishment Contact Details' }, + { label: 'Profile' }, + { label: 'Details' }, + { label: 'Contact Details' }, { label: 'Products' }, - { label: 'Employment in Establishment' }, + { label: 'Employment Details' }, ], [] ); @@ -122,14 +122,14 @@ const EditCompanyProfile = () => { { field: 'userProfileEmail', label: 'Email' }, ], 1: [ - { field: 'permanentFactoryCode', label: 'Permanent Factory Code' }, + // { field: 'permanentFactoryCode', label: 'Permanent Factory Code' }, { field: 'uniqueLicenseNumber', label: 'Unique License Number' }, { field: 'industryCodeBusiness', label: 'Industry Code (Business Register)' }, { field: 'industryCodeCurrent', label: 'Industry Code (Current Production)' }, ], 2: [ { field: 'contactName', label: 'Name' }, - { field: 'contactAddress', label: 'Address' }, + // { field: 'contactAddress', label: 'Address' }, { field: 'contactEmirate', label: 'Emirate' }, { field: 'contactCityTown', label: 'City/Town' }, { field: 'contactEmail', label: 'Email' }, @@ -636,7 +636,7 @@ const EditCompanyProfile = () => { return (
-

User Profile

+

Profile

{ return (
-

Identification Particulars

+

Details

{ onChange={(e) => handleFormChange("permanentFactoryCode", e.target.value)} placeholder="Enter Factory Code" width="100%" - required + // required error={fieldErrors.permanentFactoryCode} /> { return (
-

Establishment Contact Details

+

Contact Details

{ onChange={(e) => handleFormChange("contactAddress", e.target.value)} placeholder="Enter Address" width="100%" - required + // required error={fieldErrors.contactAddress} /> {
{/* Left side: Products Header */}
-

Products

+

Products *

{ {/* Right side: Icons */}
-
+ Added By: +
Admin User
@@ -948,6 +949,9 @@ const EditCompanyProfile = () => {
{product.label}
+ {product.hs_code && ( +
HS Code - {product.hs_code}
+ )}
{/* Selected Products Panel */} -
-
-
Selected Products
- {selectedProducts.length > 0 && ( - - {selectedProducts.length} selected - - )} -
-
- {selectedProducts.length > 0 ? ( -
    - {selectedProducts.map((product) => { - const isNewlyAdded = newlyAddedProductIds.has(product.value); - return ( -
  • -
    - {/* {product.action_done_by === "admin_users" ? ( - - ) : ( - - )} */} - {product.action_done_by === "admin_users" ? ( - - ) : ( - - )} -
    -
    - {product.label} -
    - {product.hs_code && ( -
    - HS Code: {product.hs_code} -
    - )} -
    -
    - {isNewlyAdded && ( - - )} -
  • - ); - })} -
- ) : ( -
- No products selected -
- )} +
+
+
Selected Products
+ + {selectedProducts.length > 0 && ( + + {selectedProducts.length} selected + + )} +
+ +
+ {selectedProducts.length > 0 ? ( +
    + {selectedProducts.map((product) => { + const isNewlyAdded = newlyAddedProductIds.has(product.value); + + // extract hs + name + const hsCode = product.label?.split(" - ")[0] ?? ""; + const productName = product.label?.split(" - ")[1] ?? product.label; + + return ( +
  • +
    + + {product.action_done_by === "admin_users" ? ( + + ) : ( + + )} + +
    +
    + {productName} +
    + +
    + HS Code: {hsCode} +
    + + {isNewlyAdded && ( + + )} +
  • + ); + })} +
+ ) : ( +
+ No products selected +
+ )} +
+
+
); @@ -1046,47 +1058,67 @@ const EditCompanyProfile = () => { return (
-

Employment in Establishment

+

Employment Details

handleFormChange("employmentEmiratiMale", e.target.value)} + onChange={(e) => { + if (e.target.value === '' || /^\d+$/.test(e.target.value)) { + handleFormChange("employmentEmiratiMale", e.target.value); + } + }} placeholder="Enter Count" width="100%" - type="number" - required + type="text" + inputMode="numeric" + pattern="[0-9]*" error={fieldErrors.employmentEmiratiMale} /> handleFormChange("employmentNonEmiratiMale", e.target.value)} + onChange={(e) => { + if (e.target.value === '' || /^\d+$/.test(e.target.value)) { + handleFormChange("employmentNonEmiratiMale", e.target.value); + } + }} placeholder="Enter Count" width="100%" - type="number" - required + type="text" + inputMode="numeric" + pattern="[0-9]*" error={fieldErrors.employmentNonEmiratiMale} /> handleFormChange("employmentEmiratiFemale", e.target.value)} + onChange={(e) => { + if (e.target.value === '' || /^\d+$/.test(e.target.value)) { + handleFormChange("employmentEmiratiFemale", e.target.value); + } + }} placeholder="Enter Count" width="100%" - type="number" - required + type="text" + inputMode="numeric" + pattern="[0-9]*" error={fieldErrors.employmentEmiratiFemale} /> handleFormChange("employmentNonEmiratiFemale", e.target.value)} + onChange={(e) => { + if (e.target.value === '' || /^\d+$/.test(e.target.value)) { + handleFormChange("employmentNonEmiratiFemale", e.target.value); + } + }} placeholder="Enter Count" width="100%" - type="number" - required + type="text" + inputMode="numeric" + pattern="[0-9]*" error={fieldErrors.employmentNonEmiratiFemale} /> { {/* Header */}
-

Edit Company Profile

+

Edit Profile

{/* Body */}