client given cr fixed
This commit is contained in:
parent
367d15d065
commit
da34c59a90
@ -602,32 +602,28 @@ React.useEffect(() => {
|
||||
value={info.establishmentName}
|
||||
onChange={handleFieldChange('establishmentName')}
|
||||
disabled={true}
|
||||
|
||||
/>
|
||||
<Field
|
||||
{/* <Field
|
||||
label="Permanent Factory Code(PFC)"
|
||||
placeholder="Enter Permanent Factory Code"
|
||||
value={info.permanentFactoryCode}
|
||||
onChange={handleFieldChange('permanentFactoryCode')}
|
||||
disabled={true}
|
||||
|
||||
/>
|
||||
<Field
|
||||
/> */}
|
||||
{/* <Field
|
||||
label="Business Register Industry Code"
|
||||
placeholder="Enter Industry Code"
|
||||
value={info.industryCode}
|
||||
onChange={handleFieldChange('industryCode')}
|
||||
disabled={true}
|
||||
|
||||
/>
|
||||
<Field
|
||||
/> */}
|
||||
{/* <Field
|
||||
label="License Number"
|
||||
placeholder="Enter License Number"
|
||||
value={info.licenseNumber}
|
||||
onChange={handleFieldChange('licenseNumber')}
|
||||
disabled={true}
|
||||
|
||||
/>
|
||||
/> */}
|
||||
{/* Email field is hidden but data remains in form state */}
|
||||
<Field
|
||||
label="ISIC Code"
|
||||
@ -635,7 +631,6 @@ React.useEffect(() => {
|
||||
value={info.isicCode}
|
||||
onChange={handleFieldChange('isicCode')}
|
||||
disabled={true}
|
||||
|
||||
/>
|
||||
<Field
|
||||
label="Emirate"
|
||||
|
||||
@ -410,6 +410,7 @@ const ProductData = ({
|
||||
const [isLoadingProducts, setIsLoadingProducts] = React.useState(false);
|
||||
const [productsError, setProductsError] = React.useState('');
|
||||
const [showDraftSaved, setShowDraftSaved] = React.useState(false);
|
||||
const [deletedProducts, setDeletedProducts] = React.useState([]);
|
||||
const MAX_PRODUCTS = maxProducts;
|
||||
// Remove the unused state variables since we'll use the props directly
|
||||
const [unitOptions, setUnitOptions] = React.useState([]);
|
||||
@ -737,6 +738,56 @@ const existingProduct = currentSubmission.products?.find(p =>
|
||||
};
|
||||
});
|
||||
|
||||
// Add deleted products with is_active: false if we're in draft edit mode
|
||||
if (location.state?.isEdit && deletedProducts.length > 0) {
|
||||
const deletedFormattedProducts = deletedProducts.map(product => {
|
||||
const selectedProduct = productOptions.find(p => p.value === product.product);
|
||||
const existingProduct = currentSubmission.products?.find(p =>
|
||||
p.product_id === (selectedProduct?.product_id || product.product_id) ||
|
||||
p.product?.id === (selectedProduct?.product_id || product.product_id)
|
||||
);
|
||||
return {
|
||||
id: existingProduct?.id || 0,
|
||||
product_id: selectedProduct?.product_id || product.product_id || null,
|
||||
unit_id: product.unit?.toString() || '0',
|
||||
annual_installed_capacity: product.capacity || '0',
|
||||
previous_quantity_period_one: product.octQuantity || '0',
|
||||
previous_quantity_period_two: product.novQuantity || '0',
|
||||
previous_quantity_period_three: product.decQuantity || '0',
|
||||
previous_cost_period_one: product.octCost || '0',
|
||||
previous_cost_period_two: product.novCost || '0',
|
||||
previous_cost_period_three: product.decCost || '0',
|
||||
current_quantity_period_one: product.janQuantity || '0',
|
||||
current_quantity_period_two: product.febQuantity || '0',
|
||||
current_quantity_period_three: product.marQuantity || '0',
|
||||
current_cost_period_one: product.janCost || '0',
|
||||
current_cost_period_two: product.febCost || '0',
|
||||
current_cost_period_three: product.marCost || '0',
|
||||
forecast_quantity_period_one: product.aprQuantity || '0',
|
||||
forecast_quantity_period_two: product.mayQuantity || '0',
|
||||
forecast_quantity_period_three: product.junQuantity || '0',
|
||||
forecast_cost_period_one: product.aprCost || '0',
|
||||
forecast_cost_period_two: product.mayCost || '0',
|
||||
forecast_cost_period_three: product.junCost || '0',
|
||||
previous_quantity: product.octQuantity || '0',
|
||||
previous_cost: product.octCost || '0',
|
||||
current_quantity: product.novQuantity || '0',
|
||||
current_cost: product.novCost || '0',
|
||||
forecast_quantity: product.decQuantity || '0',
|
||||
forecast_cost: product.decCost || '0',
|
||||
variation_reason_master_id: product.variationReason || '0',
|
||||
other_variation_reason: product.otherVariationReason || '0',
|
||||
zero_target_reason_master_id: product.zeroTargetReason || '0',
|
||||
other_zero_target_reason: product.otherZeroTargetReason || '0',
|
||||
remarks: product.remarks || remarks || '',
|
||||
is_active: false // Mark as inactive
|
||||
};
|
||||
});
|
||||
|
||||
// Combine active and deleted products
|
||||
formattedProducts.push(...deletedFormattedProducts);
|
||||
}
|
||||
|
||||
// Prepare the complete payload with values from currentSubmission
|
||||
const payload = {
|
||||
establishment_id: establishmentId,
|
||||
@ -1284,6 +1335,11 @@ useEffect(() => {
|
||||
const productToRemove = products.find(p => p.id === id);
|
||||
onProductsChange(products.filter((p) => p.id !== id));
|
||||
|
||||
// Track deleted products if we're in draft edit mode
|
||||
if (location.state?.isEdit && productToRemove) {
|
||||
setDeletedProducts(prev => [...prev, productToRemove]);
|
||||
}
|
||||
|
||||
// Remove the product ID from selectedProductIds if it exists
|
||||
if (productToRemove?.product) {
|
||||
setSelectedProductIds(prev => prev.filter(pid => pid !== productToRemove.product));
|
||||
|
||||
@ -680,7 +680,7 @@ const CompanyProfile = () => {
|
||||
2: [
|
||||
{ field: 'contactName', label: 'Name' },
|
||||
{ field: 'contactAddress', label: 'Address' },
|
||||
{ field: 'contactCityTown', label: 'City/Town' },
|
||||
// { field: 'contactCityTown', label: 'City/Town' },
|
||||
{ field: 'contactEmirate', label: 'Emirate' },
|
||||
{ field: 'contactMobileNumber', label: 'Mobile Number' },
|
||||
{ field: 'contactEmail', label: 'Email' },
|
||||
@ -1127,8 +1127,8 @@ const CompanyProfile = () => {
|
||||
options={contactCityOptions}
|
||||
placeholder="Select City/Town"
|
||||
width="100%"
|
||||
required
|
||||
error={fieldErrors.contactCityTown}
|
||||
// required
|
||||
// error={fieldErrors.contactCityTown}
|
||||
readOnly={modalMode === 'view'}
|
||||
/>
|
||||
<TextField
|
||||
|
||||
@ -131,7 +131,7 @@ const EditCompanyProfile = () => {
|
||||
{ field: 'contactName', label: 'Name' },
|
||||
// { field: 'contactAddress', label: 'Address' },
|
||||
{ field: 'contactEmirate', label: 'Emirate' },
|
||||
{ field: 'contactCityTown', label: 'City/Town' },
|
||||
// { field: 'contactCityTown', label: 'City/Town' },
|
||||
{ field: 'contactEmail', label: 'Email' },
|
||||
],
|
||||
3: [
|
||||
@ -699,16 +699,17 @@ const EditCompanyProfile = () => {
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-[16px] font-semibold text-[#232528]">Details</h4>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<TextField
|
||||
{/* <TextField
|
||||
label="Permanent Factory Code"
|
||||
type="hidden"
|
||||
value={form.permanentFactoryCode || ""}
|
||||
onChange={(e) => handleFormChange("permanentFactoryCode", e.target.value)}
|
||||
placeholder="Enter Factory Code"
|
||||
width="100%"
|
||||
// required
|
||||
error={fieldErrors.permanentFactoryCode}
|
||||
/>
|
||||
<TextField
|
||||
/> */}
|
||||
{/* <TextField
|
||||
label="Unique License Number"
|
||||
value={form.uniqueLicenseNumber || ""}
|
||||
onChange={(e) => handleFormChange("uniqueLicenseNumber", e.target.value)}
|
||||
@ -716,8 +717,8 @@ const EditCompanyProfile = () => {
|
||||
width="100%"
|
||||
required
|
||||
error={fieldErrors.uniqueLicenseNumber}
|
||||
/>
|
||||
<TextField
|
||||
/> */}
|
||||
{/* <TextField
|
||||
label="Industry Code (Business Register)"
|
||||
value={form.industryCodeBusiness || ""}
|
||||
onChange={(e) => handleFormChange("industryCodeBusiness", e.target.value)}
|
||||
@ -725,7 +726,7 @@ const EditCompanyProfile = () => {
|
||||
width="100%"
|
||||
// required
|
||||
error={fieldErrors.industryCodeBusiness}
|
||||
/>
|
||||
/> */}
|
||||
<div className="whitespace-nowrap">
|
||||
<TextField
|
||||
label="Industry Code (Current Production)"
|
||||
@ -738,7 +739,7 @@ const EditCompanyProfile = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-full">
|
||||
<TextField
|
||||
{/* <TextField
|
||||
label="Description of Industry"
|
||||
value={form.industryDescription || ""}
|
||||
onChange={(e) => handleFormChange("industryDescription", e.target.value)}
|
||||
@ -746,7 +747,7 @@ const EditCompanyProfile = () => {
|
||||
width="100%"
|
||||
multiline
|
||||
rows={3}
|
||||
/>
|
||||
/> */}
|
||||
</div>
|
||||
{form.industryCodeBusiness && form.industryCodeBusiness !== form.industryCodeCurrent && (
|
||||
<div className="col-span-full">
|
||||
@ -782,6 +783,7 @@ const EditCompanyProfile = () => {
|
||||
width="100%"
|
||||
required
|
||||
error={fieldErrors.contactName}
|
||||
readOnly
|
||||
/>
|
||||
<TextField
|
||||
label="Address"
|
||||
@ -790,6 +792,7 @@ const EditCompanyProfile = () => {
|
||||
placeholder="Enter Address"
|
||||
width="100%"
|
||||
// required
|
||||
readOnly
|
||||
error={fieldErrors.contactAddress}
|
||||
/>
|
||||
<SelectField
|
||||
@ -808,6 +811,7 @@ const EditCompanyProfile = () => {
|
||||
placeholder="Select Emirate"
|
||||
width="100%"
|
||||
required
|
||||
readOnly
|
||||
error={fieldErrors.contactEmirate}
|
||||
/>
|
||||
<SelectField
|
||||
@ -824,7 +828,7 @@ const EditCompanyProfile = () => {
|
||||
}))}
|
||||
placeholder={form.contactEmirate ? (isLoadingCities ? "Loading cities..." : "Select City/Town") : "Select emirate first"}
|
||||
width="100%"
|
||||
required
|
||||
// required
|
||||
disabled={!form.contactEmirate || isLoadingCities}
|
||||
error={fieldErrors.contactCityTown}
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user