diff --git a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx index 78259e1..a11e90e 100644 --- a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx +++ b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx @@ -57,13 +57,13 @@ const SubmissionTable = ({ selectedQuarter, selectedYear }) => { const titleText = useMemo(() => { const count = filtered.length; 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') { - return `Recent 10 Submissions for Selected Quarter ${selectedQuarter} (${count})`; + return `Recent Submissions for Selected Quarter ${selectedQuarter} (${count})`; } else if (selectedYear !== 'All') { - return `Recent 10 Submissions for Selected Year ${selectedYear} (${count})`; + return `Recent Submissions for Selected Year ${selectedYear} (${count})`; } else { - return `Recent 10 Submissions (${count})`; + return `Recent Submissions (${count})`; } }, [selectedQuarter, selectedYear, filtered]); diff --git a/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx b/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx index 648c7f1..5d14ad0 100644 --- a/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx +++ b/ipi-survey-platform/src/components/dashboard/SubmissionHistory.jsx @@ -115,15 +115,22 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' }) const normalizedHistory = React.useMemo(() => { if (!Array.isArray(history)) return []; - return history.map((entry, index) => ({ - id: entry?.id ?? index, - survey_name: 'Industrial Production Survey', - year: entry?.year || '—', - quarter: entry?.quarter || '—', - status: entry?.status || 'Pending', - submission_on: formatDateTime(entry?.created_at || entry?.submitted_on), - products: entry?.product_count ?? 0, - })); + return history.map((entry, index) => { + const quarter = entry?.quarter || ''; + const year = entry?.year || ''; + const surveyName = `IPI ${quarter} ${year} Survey`; + + return { + id: entry?.id ?? index, + survey_name: surveyName, + year: year || '—', + quarter: quarter || '—', + status: entry?.status || 'Pending', + submission_on: formatDateTime(entry?.created_at || entry?.submitted_on), + products: entry?.product_count ?? 0, + originalData: entry // Keep original data for reference + }; + }); }, [history]); const filtered = normalizedHistory.filter((entry) => { @@ -165,88 +172,90 @@ export const SubmissionHistory = ({ history = [], loading = false, error = '' }) return ( <> -
-
-

- Submission History -

+
+
+
+

+ Submission History +

-
-
- setSearchTerm(e.target.value)} - placeholder="Search Establishment" - className="w-full h-10 rounded-md border border-[#E5E7EB] pl-10 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-[#92722A]" - /> - Search -
- - -
-
- -
- {loading ? ( -
- Loading submissions... -
- ) : filtered.length === 0 ? ( -
- No Submission Found -
- ) : ( -
-
- + + - )} + + +
+ {loading ? ( +
+ Loading submissions... +
+ ) : filtered.length === 0 ? ( +
+ No Submission Found +
+ ) : ( +
+
+
+ + + )} + +
); diff --git a/ipi-survey-platform/src/components/dashboard/SurveyCarousel.jsx b/ipi-survey-platform/src/components/dashboard/SurveyCarousel.jsx index 19b39cd..9f280a8 100644 --- a/ipi-survey-platform/src/components/dashboard/SurveyCarousel.jsx +++ b/ipi-survey-platform/src/components/dashboard/SurveyCarousel.jsx @@ -31,7 +31,7 @@ const SurveyCarousel = ({ return (
-
+

{current?.title || '—'} diff --git a/ipi-survey-platform/src/components/dashboard/SurveyStatus.jsx b/ipi-survey-platform/src/components/dashboard/SurveyStatus.jsx index 3cb7218..dfcac28 100644 --- a/ipi-survey-platform/src/components/dashboard/SurveyStatus.jsx +++ b/ipi-survey-platform/src/components/dashboard/SurveyStatus.jsx @@ -83,20 +83,19 @@ export const SurveyStatus = () => { fetchData(); }, []); - const handleStartSurvey = (survey) => { - // The survey object contains all the data from survey_ready - console.log('Survey data being passed to survey screen:', { - quarter: survey.quarter, - year: survey.year, - startDate: survey.startDate, - endDate: survey.endDate, - title: survey.title - }); - - // You can add any additional processing here before navigation - // For example, you might want to store the selected survey in state - // or make an API call to initialize the survey - }; + const handleStartSurvey = (survey) => { + // Store the survey data in localStorage + localStorage.setItem('currentSurvey', JSON.stringify({ + quarter: survey.quarter, + year: survey.year, + startDate: survey.startDate, + endDate: survey.endDate, + title: survey.title + })); + + // Navigate to the survey page + navigate('/survey'); + }; const nextDeadline = dashboardData?.next_deadline; const formattedDueDate = formatDate(nextDeadline); @@ -133,7 +132,7 @@ export const SurveyStatus = () => { : 'Complete your quarterly industrial production data submission'; return ( -
+
{loading ? (
diff --git a/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx b/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx index 94db262..39197cf 100644 --- a/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx +++ b/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx @@ -1,38 +1,38 @@ import React from 'react'; import HeaderBar from '@/components/layout/HeaderBar'; -const getCurrentQuarterAndYear = () => { - const now = new Date(); - const month = now.getMonth() + 1; - const year = now.getFullYear(); - let quarter = ''; +// const getCurrentQuarterAndYear = () => { +// const now = new Date(); +// const month = now.getMonth() + 1; +// const year = now.getFullYear(); +// let quarter = ''; - if (month >= 1 && month <= 3) quarter = 'Q1'; - else if (month >= 4 && month <= 6) quarter = 'Q2'; - else if (month >= 7 && month <= 9) quarter = 'Q3'; - else quarter = 'Q4'; +// if (month >= 1 && month <= 3) quarter = 'Q1'; +// else if (month >= 4 && month <= 6) quarter = 'Q2'; +// else if (month >= 7 && month <= 9) quarter = 'Q3'; +// else quarter = 'Q4'; - return { quarter, year }; -}; +// return { quarter, year }; +// }; 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.'; - if (loading) { - description = 'Loading dashboard information…'; - } else if (error) { - description = error; - } else if (currentQuarter && currentYear) { - description = `Current reporting period: ${currentQuarter} ${currentYear}`; - } +// let description = 'Current reporting information unavailable.'; +// if (loading) { +// description = 'Loading dashboard information…'; +// } else if (error) { +// description = error; +// } else if (currentQuarter && currentYear) { +// description = `Current reporting period: ${currentQuarter} ${currentYear}`; +// } return (
-
+
-

+

Welcome{' '} {(() => { try { @@ -44,13 +44,13 @@ export const WelcomeSection = ({ data = null, loading = false, error = '' }) => } })()}!

-

{description} -

+

*/}
diff --git a/ipi-survey-platform/src/components/layout/HeaderBar.jsx b/ipi-survey-platform/src/components/layout/HeaderBar.jsx index 5591bda..063d03c 100644 --- a/ipi-survey-platform/src/components/layout/HeaderBar.jsx +++ b/ipi-survey-platform/src/components/layout/HeaderBar.jsx @@ -81,11 +81,26 @@ const HeaderBar = () => { `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 }) => ( <> - Survey + Survey Survey )} @@ -163,8 +178,28 @@ const HeaderBar = () => { Dashboard Dashboard - 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'}`}> - Survey + { + 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' + }`} + > + Survey Survey 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'}`}> diff --git a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx index 49f77eb..b447c2d 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/CompanyProfile.jsx @@ -105,6 +105,7 @@ const createEmptyProfile = () => ({ permanentFactoryCode: '', uniqueLicenseNumber: '', industryCodeBusiness: '', + industryCodeProduction: '', industryCodeCurrent: '', industryDescription: '', // Establishment contact details @@ -2026,7 +2027,7 @@ const requiredFields = [ factory_name: form.establishmentName || form.contactName || '', permanent_factory_code: form.permanentFactoryCode || '', industry_code: form.industryCodeBusiness || form.industryCodeCurrent || '', - industry_code_production: form.industryCodeBusiness || form.industryCodeCurrent || '', + industry_code_production: form.industryCodeProduction || '', license_number: form.uniqueLicenseNumber || '', isic_code: form.isicCode || form.industryCodeBusiness || '', description: form.industryDescription || '', diff --git a/ipi-survey-platform/src/pages/Admin/configuration/UnitMaster.jsx b/ipi-survey-platform/src/pages/Admin/configuration/UnitMaster.jsx index 54d310b..cc1e10e 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/UnitMaster.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/UnitMaster.jsx @@ -250,7 +250,7 @@ const UnitMaster = () => { const handleSave = async () => { const selectedProducts = Array.isArray(form.productsMapped) ? form.productsMapped : []; - + console.log(selectedProducts,"selectedProducts"); // ✅ Validation checks if (!form.unitName) { setToastData({ @@ -292,8 +292,9 @@ const UnitMaster = () => { uom: form.unitName, uom_short_name: form.description, is_active: form.status === 'Active', - productsMapped: selectedProducts, + productsMapped: selectedProducts.length, }; + console.log("unitData",unitData) try { setLoading(true); diff --git a/ipi-survey-platform/src/pages/History/History.jsx b/ipi-survey-platform/src/pages/History/History.jsx index 8c2ff1c..d961406 100644 --- a/ipi-survey-platform/src/pages/History/History.jsx +++ b/ipi-survey-platform/src/pages/History/History.jsx @@ -884,8 +884,9 @@ const tableRows = auditHistory.map((entry, index) => { { width: 80, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Quarter { width: 120, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // HS Code { width: 200, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Product - { width: 130, align: 'center', style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Status - { width: 150, style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Actors + { width: 150, align: 'center', style: { whiteSpace: 'normal', wordWrap: 'break-word' } }, // Status + { 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 ]} pagination={{ diff --git a/ipi-survey-platform/src/pages/Overview/Overview.jsx b/ipi-survey-platform/src/pages/Overview/Overview.jsx index 31d98f1..ed72c07 100644 --- a/ipi-survey-platform/src/pages/Overview/Overview.jsx +++ b/ipi-survey-platform/src/pages/Overview/Overview.jsx @@ -157,8 +157,8 @@ const Overview = () => { const toolbar = (
-
-

Quarter Overview

+
+

Quarter Overview ({filteredRows.length})

@@ -228,7 +228,7 @@ const Overview = () => {
- + */} setSelectedSubmission(null)} />
diff --git a/ipi-survey-platform/src/pages/Survey/Survey.jsx b/ipi-survey-platform/src/pages/Survey/Survey.jsx index 2d7402a..0ce4e9f 100644 --- a/ipi-survey-platform/src/pages/Survey/Survey.jsx +++ b/ipi-survey-platform/src/pages/Survey/Survey.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import { submitSurvey, fetchSubmissionDetail, resubmitSurvey } from '@/services/submissions/submissionService'; import { fetchEstablishmentDetail, fetchEstablishmentDashboard } from '@/services/establishments/establishmentService'; @@ -70,6 +70,7 @@ const Survey = () => { const [viewError, setViewError] = React.useState(''); const [establishmentLoading, setEstablishmentLoading] = React.useState(false); const [establishmentError, setEstablishmentError] = React.useState(''); + const [surveyData, setSurveyData] = React.useState(null); const isViewMode = React.useMemo(() => Boolean(locationState.submission), [locationState.submission]); const isResubmit = React.useMemo(() => locationState?.isResubmit === true, [locationState?.isResubmit]); const submissionId = React.useMemo(() => locationState?.submissionId || locationState?.submission?.id, [locationState]); @@ -79,6 +80,20 @@ const Survey = () => { setStep(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 const fetchCurrentQuarterAndYear = async () => { try { @@ -373,9 +388,14 @@ const Survey = () => { const buildSubmissionPayload = React.useCallback((isResubmitFlow = false) => { const info = establishmentData?.employeeInfo ?? {}; + + // Get quarter and year from surveyData if available, otherwise from establishmentData + const quarter = surveyData?.quarter || ''; + const year = surveyData?.year || ''; + return { - quarter: establishmentData?.quarter ?? '', - year: parseNumber(establishmentData?.year), + quarter: quarter, + year: year, status: 'Submitted', emirati_male: parseNumber(info.emiratiMale), emirati_female: parseNumber(info.emiratiFemale), @@ -511,6 +531,8 @@ const Survey = () => { showToast('success', response?.message || 'You have successfully submitted the survey.'); setShowSuccessPopup(true); setHasSubmitted(true); + // Clear the stored survey data after successful submission + localStorage.removeItem('currentSurvey'); } catch (error) { console.error('Failed to submit survey', error); const message = error?.response?.data?.message || error?.message || 'Failed to submit survey.'; @@ -537,6 +559,9 @@ const Survey = () => { setShowSuccessPopup(true); setHasSubmitted(true); showToast('success', 'Survey resubmitted successfully!'); + localStorage.removeItem('surveyRemarks'); + // Clear the stored survey data after successful resubmission + localStorage.removeItem('currentSurvey'); } catch (error) { console.error('Resubmission failed:', error); const message = error?.response?.data?.message || error?.message || 'Failed to resubmit survey. Please try again.'; @@ -558,12 +583,17 @@ const Survey = () => { try { const payload = buildSubmissionPayload(); + console.log('Submission Payload:', JSON.stringify(payload, null, 2)); await submitSurvey(payload); setShowSuccessPopup(true); setHasSubmitted(true); showToast('success', 'Survey submitted successfully!'); + localStorage.removeItem('surveyRemarks'); + // Clear the stored survey data after successful submission + localStorage.removeItem('currentSurvey'); } catch (error) { const message = error?.response?.data?.message || error?.message || 'Failed to submit survey. Please try again.'; + console.error('Submission Error:', error); setError(message); showToast('error', message); } finally { @@ -819,7 +849,9 @@ const Survey = () => { {/* Message */}

- Thank you. Your IP Quarterly Survey for {establishmentData?.quarter} {establishmentData?.year} has been {isResubmit ? 'resubmitted' : 'submitted'}. + Thank you. Your IP Quarterly Survey for + {surveyData?.quarter} {surveyData?.year} + has been {isResubmit ? 'resubmitted' : 'submitted'}.

{/* Button */}