conditions changed in remarks
This commit is contained in:
parent
4db00f84fd
commit
465cc8f9b0
@ -139,6 +139,24 @@ const formatDate = (dateString) => {
|
||||
return `${day}/${month}/${year}`;
|
||||
};
|
||||
|
||||
const extractIndustryCode = (value) => {
|
||||
if (value === null || value === undefined) return '';
|
||||
const normalized = String(value).trim();
|
||||
if (!normalized) return '';
|
||||
|
||||
const leadingDigits = normalized.match(/^(\d+)/);
|
||||
const beforeDash = normalized.split('-')[0]?.trim();
|
||||
const rawCode = (leadingDigits?.[1] ?? beforeDash ?? normalized);
|
||||
|
||||
return String(rawCode).trim().replace(/^0+(?=\d)/, '');
|
||||
};
|
||||
|
||||
const getIndustryCodeFromIsicSelection = (selectedValue, options = []) => {
|
||||
if (selectedValue === null || selectedValue === undefined || selectedValue === '') return '';
|
||||
const selected = options.find((opt) => String(opt?.value) === String(selectedValue));
|
||||
return extractIndustryCode(selected?.label ?? selectedValue);
|
||||
};
|
||||
|
||||
const createEmptyProfile = () => ({
|
||||
apiId: null,
|
||||
userProfileName: '',
|
||||
@ -1066,7 +1084,7 @@ const CompanyProfile = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{form.industryCodeProduction && form.industryCodeBusiness && form.industryCodeBusiness !== form.industryCodeProduction && (
|
||||
{form.industryCodeProduction && form.industryCodeBusiness && extractIndustryCode(form.industryCodeBusiness) !== getIndustryCodeFromIsicSelection(form.industryCodeProduction, isicOptions) && (
|
||||
<div className="mt-4 w-[calc(100%-1px)]">
|
||||
<TextField
|
||||
label="Remarks"
|
||||
|
||||
@ -65,33 +65,52 @@ const mapApiEstablishmentToProfile = (apiData) => {
|
||||
employmentNonEmiratiFemale: data.non_emirati_female || 0,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const computeEmploymentTotals = (data) => {
|
||||
const emiratiMale = parseInt(data.employmentEmiratiMale) || 0;
|
||||
const nonEmiratiMale = parseInt(data.employmentNonEmiratiMale) || 0;
|
||||
const emiratiFemale = parseInt(data.employmentEmiratiFemale) || 0;
|
||||
const nonEmiratiFemale = parseInt(data.employmentNonEmiratiFemale) || 0;
|
||||
|
||||
|
||||
const totalEmployees = emiratiMale + nonEmiratiMale + emiratiFemale + nonEmiratiFemale;
|
||||
const totalEmirati = emiratiMale + emiratiFemale;
|
||||
|
||||
|
||||
return {
|
||||
employmentTotalEmployees: totalEmployees,
|
||||
employmentTotalEmirati: totalEmirati
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const extractIndustryCode = (value) => {
|
||||
if (value === null || value === undefined) return '';
|
||||
const normalized = String(value).trim();
|
||||
if (!normalized) return '';
|
||||
|
||||
const leadingDigits = normalized.match(/^(\d+)/);
|
||||
const beforeDash = normalized.split('-')[0]?.trim();
|
||||
const rawCode = (leadingDigits?.[1] ?? beforeDash ?? normalized);
|
||||
|
||||
return String(rawCode).trim().replace(/^0+(?=\d)/, '');
|
||||
};
|
||||
|
||||
const getIndustryCodeFromIsicSelection = (selectedValue, options = []) => {
|
||||
if (selectedValue === null || selectedValue === undefined || selectedValue === '') return '';
|
||||
const selected = options.find((opt) => String(opt?.value) === String(selectedValue));
|
||||
return extractIndustryCode(selected?.label ?? selectedValue);
|
||||
};
|
||||
|
||||
const EditCompanyProfile = () => {
|
||||
const navigate = useNavigate();
|
||||
const { id: establishmentId } = useParams();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [form, setForm] = useState(createEmptyProfile());
|
||||
|
||||
const [activeStep, setActiveStep] = useState(0);
|
||||
const [fieldErrors, setFieldErrors] = useState({});
|
||||
const [passwordError, setPasswordError] = useState("");
|
||||
const [confirmError, setConfirmError] = useState("");
|
||||
const [passwordReuseError, setPasswordReuseError] = useState("");
|
||||
|
||||
|
||||
const [emirateOptions, setEmirateOptions] = useState([]);
|
||||
const [emirateLookup, setEmirateLookup] = useState({});
|
||||
const [contactCityOptions, setContactCityOptions] = useState([]);
|
||||
@ -109,7 +128,7 @@ const EditCompanyProfile = () => {
|
||||
const [checkedProducts, setCheckedProducts] = useState(new Set());
|
||||
const initialSnapshotRef = useRef(null);
|
||||
const productListRef = useRef(null);
|
||||
|
||||
|
||||
const formSteps = React.useMemo(
|
||||
() => [
|
||||
{ label: 'Profile' },
|
||||
@ -120,7 +139,7 @@ const EditCompanyProfile = () => {
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
const requiredFieldsByStep = React.useMemo(
|
||||
() => ({
|
||||
0: [
|
||||
@ -152,7 +171,7 @@ const EditCompanyProfile = () => {
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
const validateStepFields = useCallback((stepIndex) => {
|
||||
setPasswordReuseError("");
|
||||
|
||||
@ -184,7 +203,7 @@ const EditCompanyProfile = () => {
|
||||
});
|
||||
return valid;
|
||||
}, [form, requiredFieldsByStep, selectedProducts, checkedProducts]);
|
||||
|
||||
|
||||
const handleFormChange = useCallback((field, value) => {
|
||||
// Clear remarks if either industry code field is changed
|
||||
if (field === 'industryCodeBusiness' || field === 'industryCodeCurrent') {
|
||||
@ -222,7 +241,7 @@ const EditCompanyProfile = () => {
|
||||
}));
|
||||
}
|
||||
}, [fieldErrors]);
|
||||
|
||||
|
||||
const handleNext = useCallback(() => {
|
||||
if (validateStepFields(activeStep)) {
|
||||
if (activeStep < formSteps.length - 1) {
|
||||
@ -230,11 +249,11 @@ const EditCompanyProfile = () => {
|
||||
}
|
||||
}
|
||||
}, [activeStep, formSteps.length, validateStepFields]);
|
||||
|
||||
|
||||
const handlePrev = useCallback(() => {
|
||||
if (activeStep > 0) setActiveStep(activeStep - 1);
|
||||
}, [activeStep]);
|
||||
|
||||
|
||||
// Load cities based on selected emirate using your service function
|
||||
const loadCities = useCallback(async (emirateName) => {
|
||||
if (!emirateName) {
|
||||
@ -262,7 +281,7 @@ const EditCompanyProfile = () => {
|
||||
setIsLoadingCities(false);
|
||||
}
|
||||
}, [emirateOptions]);
|
||||
|
||||
|
||||
// Load products and filter out selected ones
|
||||
const loadProducts = useCallback(async () => {
|
||||
try {
|
||||
@ -286,7 +305,7 @@ const EditCompanyProfile = () => {
|
||||
setIsLoadingProducts(false);
|
||||
}
|
||||
}, [selectedProducts]);
|
||||
|
||||
|
||||
// Product search handler
|
||||
const handleProductSearch = (e) => {
|
||||
const searchTerm = e.target.value.toLowerCase();
|
||||
@ -935,7 +954,7 @@ const EditCompanyProfile = () => {
|
||||
rows={3}
|
||||
/> */}
|
||||
</div>
|
||||
{form.industryCodeBusiness && form.industryCodeBusiness !== form.industryCodeCurrent && (
|
||||
{form.industryCodeBusiness && extractIndustryCode(form.industryCodeBusiness) !== getIndustryCodeFromIsicSelection(form.industryCodeCurrent, isicOptions) && (
|
||||
<div className="col-span-full">
|
||||
<TextField
|
||||
label="Remarks"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user