fixed client change request and added validation for save as draft

This commit is contained in:
Malini 2026-02-09 13:13:19 +05:30
parent 5fb960abbd
commit ef4e17f853
4 changed files with 72 additions and 9 deletions

View File

@ -603,6 +603,19 @@ useEffect(() => {
const handleSaveDraft = async () => {
try {
// Validate draft form before saving
if (!validateDraftForm()) {
// Scroll to first error
const firstErrorKey = Object.keys(formErrors)[0];
if (firstErrorKey) {
const element = document.querySelector(`[data-field="${firstErrorKey}"]`);
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
return;
}
setIsSavingDraft(true);
// Get current submission from localStorage
@ -1180,6 +1193,55 @@ useEffect(() => {
return isValid;
};
// Validation function for Save as Draft - requires at least one field to be filled
const validateDraftForm = () => {
const errors = {};
let hasAnyData = false;
products.forEach((product, index) => {
// Check if product has any data
const hasProduct = product.product || product.productId || product.product_id;
const hasUnit = product.unit || product.unit_id;
const hasCapacity = product.capacity;
const hasQuantity = product.octQuantity || product.novQuantity || product.decQuantity ||
product.janQuantity || product.febQuantity || product.marQuantity ||
product.aprQuantity || product.mayQuantity || product.junQuantity;
const hasCost = product.octCost || product.novCost || product.decCost ||
product.janCost || product.febCost || product.marCost ||
product.aprCost || product.mayCost || product.junCost;
const hasVariationReason = product.variationReason || product.otherVariationReason;
const hasZeroReason = product.zeroTargetReason || product.otherZeroTargetReason;
const hasRemarks = product.remarks;
// If any field has data, mark hasAnyData as true
if (hasProduct || hasUnit || hasCapacity || hasQuantity || hasCost ||
hasVariationReason || hasZeroReason || hasRemarks) {
hasAnyData = true;
}
// If product has some data, validate mandatory fields
if (hasProduct || hasUnit || hasCapacity || hasQuantity || hasCost) {
// Product is mandatory if any other field is filled
if (!hasProduct) {
errors[`product_${index}`] = 'Please enter product field';
}
// Unit is mandatory if product is selected or any quantity/cost is entered
if (!hasUnit && (hasProduct || hasQuantity || hasCost)) {
errors[`unit_${index}`] = 'Unit is required when product or quantities are entered';
}
}
});
// Check if at least one product has any data
if (!hasAnyData) {
errors['draft_general'] = 'Please enter at least one field before saving as draft';
}
setFormErrors(errors);
return Object.keys(errors).length === 0;
};
const handleNext = () => {
if (validateForm()) {
onNext();
@ -1782,7 +1844,7 @@ useEffect(() => {
<p className="mb-3"><strong>Monthly entries:</strong> Enter Qty and Cost for each month in the Current and Forecast quarters. Use 0 where there is no output or cost.</p>
<p className="mb-3"><strong>Number only:</strong> Use a decimal point where needed. No negative values.</p>
<p className="mb-3"><strong>Units:</strong> Use one measurement unit per product across all months.</p>
<p className="mb-0"><strong>Delete:</strong> Removing a product here affects this survey only; it does not change your profile.</p>
{/* <p className="mb-0"><strong>Delete:</strong> Removing a product here affects this survey only; it does not change your profile.</p> */}
</div>
)}
</div>
@ -2453,18 +2515,19 @@ useEffect(() => {
</div>
</div>
{(hasError || isInitialLoad) && (
{(hasError || isInitialLoad || Object.keys(formErrors).length > 0) && (
<div className="mt-4">
{isInitialLoad && !hasError && (
{isInitialLoad && !hasError && Object.keys(formErrors).length === 0 && (
<p className="text-sm text-[#5F646D]">Loading product data...</p>
)}
{hasError && (
{(hasError || Object.keys(formErrors).length > 0) && (
<div className="text-sm text-red-600 space-y-1">
{error && <p>{error}</p>}
{reasonsError && <p>{reasonsError}</p>}
{zeroReasonsError && <p>{zeroReasonsError}</p>}
{productsError && <p>{productsError}</p>}
{unitsError && <p>{unitsError}</p>}
{formErrors['draft_general'] && <p>{formErrors['draft_general']}</p>}
</div>
)}
</div>

View File

@ -40,7 +40,7 @@ const steps = [
const Cards = () => {
return (
<section className="bg-gray-50 py-6 md:py-8 lg:py-10 px-6 md:px-12 lg:h-screen lg:px-24">
<section className="bg-gray-50 py-6 md:py-8 lg:py-10 px-6 md:px-12 lg:px-24">
<div className="mb-8">
<h2 className="text-2xl font-semibold text-gray-900">How the survey works</h2>
<p className="text-gray-500 mt-1">A simple quarterly cycle</p>
@ -65,7 +65,7 @@ const Cards = () => {
))}
</div>
<p className="text-xs text-gray-500 mt-10">
<p className="text-xs text-gray-500 mt-10 mb-15">
Accounts are issued by FCSC. There is no self-registration.
</p>
</section>

View File

@ -13,7 +13,7 @@ const Cta = () => {
Our support team can assist with access, questions, or clarifications.
</p>
<p className="text-sm text-gray-500">
Support hours: SunThu, 8:0016:00 GST
Support hours: MondayFriday, 8:0016:00 GST
</p>
</div>

View File

@ -30,10 +30,10 @@ const Industrial = () => {
<strong>Reference area:</strong> United Arab Emirates
</li>
<li>
<strong>Respondents:</strong> Registered manufacturing establishments
<strong>Respondents:</strong> Representatives from selected manufacturing establishments.
</li>
<li>
<strong>Classification:</strong> ISIC Rev.4
<strong>Classification:</strong> ISIC Rev 4 , HS 2022 8dgt for products.
</li>
</ul>