changed quarter

This commit is contained in:
Malini 2025-11-08 18:58:07 +05:30
parent 31883f8689
commit 776f1391d2
11 changed files with 222 additions and 144 deletions

View File

@ -57,13 +57,13 @@ const SubmissionTable = ({ selectedQuarter, selectedYear }) => {
const titleText = useMemo(() => { const titleText = useMemo(() => {
const count = filtered.length; const count = filtered.length;
if (selectedQuarter !== 'All' && selectedYear !== 'All') { if (selectedQuarter !== 'All' && selectedYear !== 'All') {
return `Recent 10 Submissions for Selected Quarter ${selectedQuarter} ${selectedYear} (${count})`; return ` Recent Submissions for Selected Quarter ${selectedQuarter} ${selectedYear} (${count})`;
} else if (selectedQuarter !== 'All') { } else if (selectedQuarter !== 'All') {
return `Recent 10 Submissions for Selected Quarter ${selectedQuarter} (${count})`; return `Recent Submissions for Selected Quarter ${selectedQuarter} (${count})`;
} else if (selectedYear !== 'All') { } else if (selectedYear !== 'All') {
return `Recent 10 Submissions for Selected Year ${selectedYear} (${count})`; return `Recent Submissions for Selected Year ${selectedYear} (${count})`;
} else { } else {
return `Recent 10 Submissions (${count})`; return `Recent Submissions (${count})`;
} }
}, [selectedQuarter, selectedYear, filtered]); }, [selectedQuarter, selectedYear, filtered]);

View File

@ -115,15 +115,22 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' })
const normalizedHistory = React.useMemo(() => { const normalizedHistory = React.useMemo(() => {
if (!Array.isArray(history)) return []; if (!Array.isArray(history)) return [];
return history.map((entry, index) => ({ return history.map((entry, index) => {
const quarter = entry?.quarter || '';
const year = entry?.year || '';
const surveyName = `IPI ${quarter} ${year} Survey`;
return {
id: entry?.id ?? index, id: entry?.id ?? index,
survey_name: 'Industrial Production Survey', survey_name: surveyName,
year: entry?.year || '—', year: year || '—',
quarter: entry?.quarter || '—', quarter: quarter || '—',
status: entry?.status || 'Pending', status: entry?.status || 'Pending',
submission_on: formatDateTime(entry?.created_at || entry?.submitted_on), submission_on: formatDateTime(entry?.created_at || entry?.submitted_on),
products: entry?.product_count ?? 0, products: entry?.product_count ?? 0,
})); originalData: entry // Keep original data for reference
};
});
}, [history]); }, [history]);
const filtered = normalizedHistory.filter((entry) => { const filtered = normalizedHistory.filter((entry) => {
@ -165,7 +172,8 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' })
return ( return (
<> <>
<div className="max-w-[1280px] mx-auto bg-white border border-[#E5E7EB] shadow-[0_16px_32px_rgba(15,23,42,0.06)] rounded-[8px] mt-8 w-full overflow-hidden"> <div className="min-h-[4rem] mt-[-70px]">
<div className="max-w-[1280px] mx-auto mb-5 bg-white border border-[#E5E7EB] shadow-[0_16px_32px_rgba(15,23,42,0.06)] rounded-[8px] mt-8 w-full overflow-hidden">
<div className="flex items-center justify-between px-6 pt-6 pb-4"> <div className="flex items-center justify-between px-6 pt-6 pb-4">
<h2 className="text-[18px] leading-[28px] font-medium text-[#232528]"> <h2 className="text-[18px] leading-[28px] font-medium text-[#232528]">
Submission History Submission History
@ -191,8 +199,7 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' })
type="button" type="button"
onClick={() => downloadCsv(filtered)} onClick={() => downloadCsv(filtered)}
disabled={!filtered.length} disabled={!filtered.length}
className={`inline-flex h-10 items-center gap-2 rounded-md border px-4 text-sm font-medium ${ className={`inline-flex h-10 items-center gap-2 rounded-md border px-4 text-sm font-medium ${filtered.length
filtered.length
? 'border-[#92722A] text-[#92722A] hover:bg-[#F2ECCF]' ? 'border-[#92722A] text-[#92722A] hover:bg-[#F2ECCF]'
: 'border-gray-200 text-gray-400 cursor-not-allowed' : 'border-gray-200 text-gray-400 cursor-not-allowed'
}`} }`}
@ -227,7 +234,7 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' })
</div> </div>
) : ( ) : (
<div className="overflow-x-auto"> <div className="overflow-x-auto">
<div className="min-w-[1200px]"> <div className="min-w-[1200px] ">
<Table <Table
headers={tableHeaders} headers={tableHeaders}
rows={tableRows} rows={tableRows}
@ -246,6 +253,8 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' })
)} )}
</div> </div>
</div> </div>
</div>
<Footer /> <Footer />
</> </>

View File

@ -31,7 +31,7 @@ const SurveyCarousel = ({
return ( return (
<div className="bg-black rounded-lg shadow-sm ring-1 w-[1275px] ring-gray-200 h-[148px] mb-8 ml-2 "> <div className="bg-black rounded-lg shadow-sm ring-1 w-[1275px] ring-gray-200 h-[148px] mb-8 ml-2 ">
<div className="rounded-none bg-[#F2ECCF] px-8 py-8 min-h-[148px] flex items-center justify-between transition-all duration-500"> <div className="rounded-none bg-[#F2ECCF] px-8 py-10 min-h-[148px] flex items-center justify-between transition-all duration-500">
<div className="flex-1"> <div className="flex-1">
<h3 className="text-[18px] leading-[28px] font-medium text-[#232528]"> <h3 className="text-[18px] leading-[28px] font-medium text-[#232528]">
{current?.title || '—'} {current?.title || '—'}

View File

@ -84,18 +84,17 @@ export const SurveyStatus = () => {
}, []); }, []);
const handleStartSurvey = (survey) => { const handleStartSurvey = (survey) => {
// The survey object contains all the data from survey_ready // Store the survey data in localStorage
console.log('Survey data being passed to survey screen:', { localStorage.setItem('currentSurvey', JSON.stringify({
quarter: survey.quarter, quarter: survey.quarter,
year: survey.year, year: survey.year,
startDate: survey.startDate, startDate: survey.startDate,
endDate: survey.endDate, endDate: survey.endDate,
title: survey.title title: survey.title
}); }));
// You can add any additional processing here before navigation // Navigate to the survey page
// For example, you might want to store the selected survey in state navigate('/survey');
// or make an API call to initialize the survey
}; };
const nextDeadline = dashboardData?.next_deadline; const nextDeadline = dashboardData?.next_deadline;
@ -133,7 +132,7 @@ export const SurveyStatus = () => {
: 'Complete your quarterly industrial production data submission'; : 'Complete your quarterly industrial production data submission';
return ( return (
<section className="max-w-[1340px] mx-auto px-0"> <section className="max-w-[1340px] mx-auto px-0 pb-15">
<div className="p-6"> <div className="p-6">
{loading ? ( {loading ? (
<div className="text-center text-gray-500 text-sm py-10"> <div className="text-center text-gray-500 text-sm py-10">

View File

@ -1,38 +1,38 @@
import React from 'react'; import React from 'react';
import HeaderBar from '@/components/layout/HeaderBar'; import HeaderBar from '@/components/layout/HeaderBar';
const getCurrentQuarterAndYear = () => { // const getCurrentQuarterAndYear = () => {
const now = new Date(); // const now = new Date();
const month = now.getMonth() + 1; // const month = now.getMonth() + 1;
const year = now.getFullYear(); // const year = now.getFullYear();
let quarter = ''; // let quarter = '';
if (month >= 1 && month <= 3) quarter = 'Q1'; // if (month >= 1 && month <= 3) quarter = 'Q1';
else if (month >= 4 && month <= 6) quarter = 'Q2'; // else if (month >= 4 && month <= 6) quarter = 'Q2';
else if (month >= 7 && month <= 9) quarter = 'Q3'; // else if (month >= 7 && month <= 9) quarter = 'Q3';
else quarter = 'Q4'; // else quarter = 'Q4';
return { quarter, year }; // return { quarter, year };
}; // };
export const WelcomeSection = ({ data = null, loading = false, error = '' }) => { export const WelcomeSection = ({ data = null, loading = false, error = '' }) => {
const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear(); // const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear();
let description = 'Current reporting information unavailable.'; // let description = 'Current reporting information unavailable.';
if (loading) { // if (loading) {
description = 'Loading dashboard information…'; // description = 'Loading dashboard information';
} else if (error) { // } else if (error) {
description = error; // description = error;
} else if (currentQuarter && currentYear) { // } else if (currentQuarter && currentYear) {
description = `Current reporting period: ${currentQuarter} ${currentYear}`; // description = `Current reporting period: ${currentQuarter} ${currentYear}`;
} // }
return ( return (
<div className="min-h-[4rem] bg-gray-50"> <div className="min-h-[4rem] bg-gray-50">
<HeaderBar /> <HeaderBar />
<div className="max-w-[1280px] mx-auto px-4 pt-4 pb-2"> <div className="max-w-[1280px] mx-auto px-4 pt-4 ">
<div className="space-y-1"> <div className="space-y-1">
<h2 className="w-[360px] text-[18px] leading-[28px] font-medium text-[#232528]"> <h2 className="w-[360px] text-[18px] pt-4 leading-[28px] font-medium text-[#232528]">
Welcome{' '} Welcome{' '}
{(() => { {(() => {
try { try {
@ -44,13 +44,13 @@ export const WelcomeSection = ({ data = null, loading = false, error = '' }) =>
} }
})()}! })()}!
</h2> </h2>
<p {/* <p
className={`w-[360px] text-[14px] leading-[24px] font-normal ${ className={`w-[360px] text-[14px] leading-[24px] font-normal ${
error ? 'text-red-600' : 'text-[#5F646D]' error ? 'text-red-600' : 'text-[#5F646D]'
}`} }`}
> >
{description} {description}
</p> </p> */}
</div> </div>
</div> </div>
</div> </div>

View File

@ -81,11 +81,26 @@ const HeaderBar = () => {
</NavLink> </NavLink>
<NavLink <NavLink
to="/survey" to="/survey"
className={({ isActive }) => `inline-flex items-center gap-2 pb-1 border-b-2 ${isActive ? 'text-[#92722A] font-medium border-[#92722A]' : 'text-[#232528] hover:text-gray-900 border-transparent'}`} className={({ isActive, isPending }) => `inline-flex items-center gap-2 pb-1 border-b-2 ${
isActive
? 'text-[#92722A] font-medium border-[#92722A]'
: window.location.pathname === '/dashboard'
? 'text-gray-400 cursor-not-allowed'
: 'text-[#232528] hover:text-gray-900 border-transparent'
}`}
onClick={(e) => {
if (window.location.pathname === '/dashboard') {
e.preventDefault();
}
}}
> >
{({ isActive }) => ( {({ isActive }) => (
<> <>
<img src={isActive ? surveyIconActiveSrc : surveyIconInactiveSrc} alt="Survey" className="h-[18px] w-[18px]" /> <img
src={isActive ? surveyIconActiveSrc : surveyIconInactiveSrc}
alt="Survey"
className={`h-[18px] w-[18px] ${window.location.pathname === '/dashboard' ? 'opacity-50' : ''}`}
/>
<span>Survey</span> <span>Survey</span>
</> </>
)} )}
@ -163,8 +178,28 @@ const HeaderBar = () => {
<img src={dashboardIconInactiveSrc} alt="Dashboard" className="h-[18px] w-[18px]" /> <img src={dashboardIconInactiveSrc} alt="Dashboard" className="h-[18px] w-[18px]" />
<span>Dashboard</span> <span>Dashboard</span>
</NavLink> </NavLink>
<NavLink to="/survey" onClick={() => setOpen(false)} className={({ isActive }) => `inline-flex items-center gap-2 px-2 py-2 rounded border-b-2 ${isActive ? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]' : 'text-[#232528] hover:bg-gray-100 border-transparent'}`}> <NavLink
<img src={surveyIconInactiveSrc} alt="Survey" className="h-[18px] w-[18px]" /> to="/survey"
onClick={(e) => {
if (window.location.pathname === '/dashboard') {
e.preventDefault();
} else {
setOpen(false);
}
}}
className={({ isActive }) => `inline-flex items-center gap-2 px-2 py-2 rounded border-b-2 ${
isActive
? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]'
: window.location.pathname === '/dashboard'
? 'text-gray-400 cursor-not-allowed bg-gray-100'
: 'text-[#232528] hover:bg-gray-100 border-transparent'
}`}
>
<img
src={surveyIconInactiveSrc}
alt="Survey"
className={`h-[18px] w-[18px] ${window.location.pathname === '/dashboard' ? 'opacity-50' : ''}`}
/>
<span>Survey</span> <span>Survey</span>
</NavLink> </NavLink>
<NavLink to="/overview" onClick={() => setOpen(false)} className={({ isActive }) => `inline-flex items-center gap-2 px-2 py-2 rounded border-b-2 ${isActive ? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]' : 'text-[#232528] hover:bg-gray-100 border-transparent'}`}> <NavLink to="/overview" onClick={() => setOpen(false)} className={({ isActive }) => `inline-flex items-center gap-2 px-2 py-2 rounded border-b-2 ${isActive ? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]' : 'text-[#232528] hover:bg-gray-100 border-transparent'}`}>

View File

@ -105,6 +105,7 @@ const createEmptyProfile = () => ({
permanentFactoryCode: '', permanentFactoryCode: '',
uniqueLicenseNumber: '', uniqueLicenseNumber: '',
industryCodeBusiness: '', industryCodeBusiness: '',
industryCodeProduction: '',
industryCodeCurrent: '', industryCodeCurrent: '',
industryDescription: '', industryDescription: '',
// Establishment contact details // Establishment contact details
@ -2026,7 +2027,7 @@ const requiredFields = [
factory_name: form.establishmentName || form.contactName || '', factory_name: form.establishmentName || form.contactName || '',
permanent_factory_code: form.permanentFactoryCode || '', permanent_factory_code: form.permanentFactoryCode || '',
industry_code: form.industryCodeBusiness || form.industryCodeCurrent || '', industry_code: form.industryCodeBusiness || form.industryCodeCurrent || '',
industry_code_production: form.industryCodeBusiness || form.industryCodeCurrent || '', industry_code_production: form.industryCodeProduction || '',
license_number: form.uniqueLicenseNumber || '', license_number: form.uniqueLicenseNumber || '',
isic_code: form.isicCode || form.industryCodeBusiness || '', isic_code: form.isicCode || form.industryCodeBusiness || '',
description: form.industryDescription || '', description: form.industryDescription || '',

View File

@ -250,7 +250,7 @@ const UnitMaster = () => {
const handleSave = async () => { const handleSave = async () => {
const selectedProducts = Array.isArray(form.productsMapped) ? form.productsMapped : []; const selectedProducts = Array.isArray(form.productsMapped) ? form.productsMapped : [];
console.log(selectedProducts,"selectedProducts");
// Validation checks // Validation checks
if (!form.unitName) { if (!form.unitName) {
setToastData({ setToastData({
@ -292,8 +292,9 @@ const UnitMaster = () => {
uom: form.unitName, uom: form.unitName,
uom_short_name: form.description, uom_short_name: form.description,
is_active: form.status === 'Active', is_active: form.status === 'Active',
productsMapped: selectedProducts, productsMapped: selectedProducts.length,
}; };
console.log("unitData",unitData)
try { try {
setLoading(true); setLoading(true);

View File

@ -884,8 +884,9 @@ const tableRows = auditHistory.map((entry, index) => {
{ width: 80, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Quarter { width: 80, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Quarter
{ width: 120, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // HS Code { width: 120, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // HS Code
{ width: 200, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Product { width: 200, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Product
{ width: 130, align: 'center', style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Status { width: 150, align: 'center', style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Status
{ width: 150, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Actors { width: 100, style: { padding: 10, margin: 0 } }, // Gap between Status and Actors
{ width: 200, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Actors
{ width: 270, style: { whiteSpace: 'normal', wordWrap: 'break-word' } } // Details { width: 270, style: { whiteSpace: 'normal', wordWrap: 'break-word' } } // Details
]} ]}
pagination={{ pagination={{

View File

@ -157,8 +157,8 @@ const Overview = () => {
const toolbar = ( const toolbar = (
<div className="px-6 pt-6 pb-4 flex flex-col gap-4 md:flex-row md:items-center md:justify-between"> <div className="px-6 pt-6 pb-4 flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
<div> <div className="flex items-center gap-2">
<h2 className="text-[18px] font-medium text-[#232528]">Quarter Overview</h2> <h2 className="text-[18px] font-medium text-[#232528]">Quarter Overview ({filteredRows.length})</h2>
</div> </div>
<div className="flex flex-col md:flex-row md:items-center gap-3"> <div className="flex flex-col md:flex-row md:items-center gap-3">
<div className="relative w-full md:w-72"> <div className="relative w-full md:w-72">
@ -228,7 +228,7 @@ const Overview = () => {
<div className="min-h-screen bg-[#F8FAFC]"> <div className="min-h-screen bg-[#F8FAFC]">
<HeaderBar /> <HeaderBar />
<main className="max-w-[1280px] mx-auto px-4 py-6"> <main className="max-w-[1280px] mx-auto px-4 py-6">
<button {/* <button
onClick={() => setSelectedSubmission(null)} onClick={() => setSelectedSubmission(null)}
className="mb-4 flex items-center text-[#9E792B] hover:text-[#7b5f22] font-medium" className="mb-4 flex items-center text-[#9E792B] hover:text-[#7b5f22] font-medium"
> >
@ -236,7 +236,7 @@ const Overview = () => {
<path fillRule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clipRule="evenodd" /> <path fillRule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clipRule="evenodd" />
</svg> </svg>
Back to Submissions Back to Submissions
</button> </button> */}
<DetailedOverview submission={selectedSubmission} onBack={() => setSelectedSubmission(null)} /> <DetailedOverview submission={selectedSubmission} onBack={() => setSelectedSubmission(null)} />
</main> </main>
</div> </div>

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { submitSurvey, fetchSubmissionDetail, resubmitSurvey } from '@/services/submissions/submissionService'; import { submitSurvey, fetchSubmissionDetail, resubmitSurvey } from '@/services/submissions/submissionService';
import { fetchEstablishmentDetail, fetchEstablishmentDashboard } from '@/services/establishments/establishmentService'; import { fetchEstablishmentDetail, fetchEstablishmentDashboard } from '@/services/establishments/establishmentService';
@ -70,6 +70,7 @@ const Survey = () => {
const [viewError, setViewError] = React.useState(''); const [viewError, setViewError] = React.useState('');
const [establishmentLoading, setEstablishmentLoading] = React.useState(false); const [establishmentLoading, setEstablishmentLoading] = React.useState(false);
const [establishmentError, setEstablishmentError] = React.useState(''); const [establishmentError, setEstablishmentError] = React.useState('');
const [surveyData, setSurveyData] = React.useState(null);
const isViewMode = React.useMemo(() => Boolean(locationState.submission), [locationState.submission]); const isViewMode = React.useMemo(() => Boolean(locationState.submission), [locationState.submission]);
const isResubmit = React.useMemo(() => locationState?.isResubmit === true, [locationState?.isResubmit]); const isResubmit = React.useMemo(() => locationState?.isResubmit === true, [locationState?.isResubmit]);
const submissionId = React.useMemo(() => locationState?.submissionId || locationState?.submission?.id, [locationState]); const submissionId = React.useMemo(() => locationState?.submissionId || locationState?.submission?.id, [locationState]);
@ -79,6 +80,20 @@ const Survey = () => {
setStep(initialStepFromState); setStep(initialStepFromState);
}, [initialStepFromState]); }, [initialStepFromState]);
useEffect(() => {
const savedSurvey = localStorage.getItem('currentSurvey');
if (savedSurvey) {
const surveyData = JSON.parse(savedSurvey);
setSurveyData(surveyData);
// Update the establishmentData with the saved survey data
setEstablishmentData(prev => ({
...prev,
quarter: surveyData.quarter || '',
year: surveyData.year || ''
}));
}
}, []);
// Function to fetch current quarter and year from dashboard // Function to fetch current quarter and year from dashboard
const fetchCurrentQuarterAndYear = async () => { const fetchCurrentQuarterAndYear = async () => {
try { try {
@ -373,9 +388,14 @@ const Survey = () => {
const buildSubmissionPayload = React.useCallback((isResubmitFlow = false) => { const buildSubmissionPayload = React.useCallback((isResubmitFlow = false) => {
const info = establishmentData?.employeeInfo ?? {}; const info = establishmentData?.employeeInfo ?? {};
// Get quarter and year from surveyData if available, otherwise from establishmentData
const quarter = surveyData?.quarter || '';
const year = surveyData?.year || '';
return { return {
quarter: establishmentData?.quarter ?? '', quarter: quarter,
year: parseNumber(establishmentData?.year), year: year,
status: 'Submitted', status: 'Submitted',
emirati_male: parseNumber(info.emiratiMale), emirati_male: parseNumber(info.emiratiMale),
emirati_female: parseNumber(info.emiratiFemale), emirati_female: parseNumber(info.emiratiFemale),
@ -511,6 +531,8 @@ const Survey = () => {
showToast('success', response?.message || 'You have successfully submitted the survey.'); showToast('success', response?.message || 'You have successfully submitted the survey.');
setShowSuccessPopup(true); setShowSuccessPopup(true);
setHasSubmitted(true); setHasSubmitted(true);
// Clear the stored survey data after successful submission
localStorage.removeItem('currentSurvey');
} catch (error) { } catch (error) {
console.error('Failed to submit survey', error); console.error('Failed to submit survey', error);
const message = error?.response?.data?.message || error?.message || 'Failed to submit survey.'; const message = error?.response?.data?.message || error?.message || 'Failed to submit survey.';
@ -537,6 +559,9 @@ const Survey = () => {
setShowSuccessPopup(true); setShowSuccessPopup(true);
setHasSubmitted(true); setHasSubmitted(true);
showToast('success', 'Survey resubmitted successfully!'); showToast('success', 'Survey resubmitted successfully!');
localStorage.removeItem('surveyRemarks');
// Clear the stored survey data after successful resubmission
localStorage.removeItem('currentSurvey');
} catch (error) { } catch (error) {
console.error('Resubmission failed:', error); console.error('Resubmission failed:', error);
const message = error?.response?.data?.message || error?.message || 'Failed to resubmit survey. Please try again.'; const message = error?.response?.data?.message || error?.message || 'Failed to resubmit survey. Please try again.';
@ -558,12 +583,17 @@ const Survey = () => {
try { try {
const payload = buildSubmissionPayload(); const payload = buildSubmissionPayload();
console.log('Submission Payload:', JSON.stringify(payload, null, 2));
await submitSurvey(payload); await submitSurvey(payload);
setShowSuccessPopup(true); setShowSuccessPopup(true);
setHasSubmitted(true); setHasSubmitted(true);
showToast('success', 'Survey submitted successfully!'); showToast('success', 'Survey submitted successfully!');
localStorage.removeItem('surveyRemarks');
// Clear the stored survey data after successful submission
localStorage.removeItem('currentSurvey');
} catch (error) { } catch (error) {
const message = error?.response?.data?.message || error?.message || 'Failed to submit survey. Please try again.'; const message = error?.response?.data?.message || error?.message || 'Failed to submit survey. Please try again.';
console.error('Submission Error:', error);
setError(message); setError(message);
showToast('error', message); showToast('error', message);
} finally { } finally {
@ -819,7 +849,9 @@ const Survey = () => {
{/* Message */} {/* Message */}
<p className="text-sm text-gray-700"> <p className="text-sm text-gray-700">
Thank you. Your IP Quarterly Survey for <span className="font-semibold text-gray-900">{establishmentData?.quarter} {establishmentData?.year}</span> has been {isResubmit ? 'resubmitted' : 'submitted'}. Thank you. Your IP Quarterly Survey for <span className="font-semibold text-gray-900">
{surveyData?.quarter} {surveyData?.year}
</span> has been {isResubmit ? 'resubmitted' : 'submitted'}.
</p> </p>
{/* Button */} {/* Button */}