From d93689735e736245387e0d0041740e585db2d7dd Mon Sep 17 00:00:00 2001 From: Malini Date: Wed, 28 Jan 2026 12:21:45 +0530 Subject: [PATCH] changes in view submissions --- .../src/components/admin/SubmissionTable.jsx | 4 +- .../components/dashboard/WelcomeSection.jsx | 83 +++++++++++-------- .../components/overview/DetailedOverview.jsx | 6 +- .../components/overview/ProductDetails.jsx | 10 +++ .../src/pages/Admin/ValidationReview.jsx | 16 ++-- .../src/pages/Admin/Validations.jsx | 4 +- .../ManufacturingIndex/ManufacturingIndex.jsx | 3 - .../pages/OTPVerification/OTPVerification.jsx | 1 - 8 files changed, 80 insertions(+), 47 deletions(-) diff --git a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx index a7a9305..7a749b3 100644 --- a/ipi-survey-platform/src/components/admin/SubmissionTable.jsx +++ b/ipi-survey-platform/src/components/admin/SubmissionTable.jsx @@ -176,7 +176,7 @@ const handleApproveConfirm = async () => { try { const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, { approve_reject_status: 1, - remarks: '' + reject_reason: '' }); const ok = (response && response.data) || response?.status === 200 || response?.status === 'success'; @@ -230,7 +230,7 @@ const handleRejectConfirm = async () => { try { const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, { approve_reject_status: 0, - remarks: rejectionReason.trim() + reject_reason: rejectionReason.trim() }); const ok = (response && response.data) || response?.status === 200 || response?.status === 'success'; diff --git a/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx b/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx index 1549acf..db26fa2 100644 --- a/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx +++ b/ipi-survey-platform/src/components/dashboard/WelcomeSection.jsx @@ -1,5 +1,6 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import HeaderBar from '@/components/layout/HeaderBar'; +import { fetchEstablishmentDashboard } from '@/services/establishments/establishmentService'; // const getCurrentQuarterAndYear = () => { // const now = new Date(); @@ -28,45 +29,61 @@ const formatName = (name = '') => { .join(' '); }; - export const WelcomeSection = ({ data = null, loading = false, error = '' }) => { -// const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear(); + const [pendingSurveys, setPendingSurveys] = useState(0); + const [isLoading, setIsLoading] = useState(true); + const [apiError, setApiError] = useState(''); -// 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}`; -// } + useEffect(() => { + const fetchDashboardData = async () => { + try { + setIsLoading(true); + // Get establishment ID from localStorage or props as needed + const establishmentId = localStorage.getItem('establishment_id'); // Adjust this line based on how you store the establishment ID + const dashboardData = await fetchEstablishmentDashboard(establishmentId); + // Get the count of pending surveys from survey_ready array + const pendingSurveysCount = dashboardData?.data?.survey_ready?.length || 0; + setPendingSurveys(pendingSurveysCount); + } catch (error) { + console.error('Error fetching dashboard data:', error); + setApiError('Failed to load survey information'); + } finally { + setIsLoading(false); + } + }; + + fetchDashboardData(); + }, []); return (
-
+
-

- Welcome{' '} - {(() => { - try { - const userProfile = JSON.parse(localStorage.getItem('user_profile')); - return userProfile?.name ? formatName(userProfile.name) : ''; - } catch (error) { - console.error('Error reading user_profile from localStorage:', error); - return ''; - } - })()} - ! -

- - {/*

- {description} -

*/} +

+ Welcome{' '} + {(() => { + try { + const userProfile = JSON.parse(localStorage.getItem('user_profile')); + return userProfile?.name ? formatName(userProfile.name) : ''; + } catch (error) { + console.error('Error reading user_profile from localStorage:', error); + return ''; + } + })()} + ! +

+
+ {isLoading ? ( + Loading survey information... + ) : apiError ? ( + {apiError} + ) : pendingSurveys > 0 ? ( + You currently have {pendingSurveys} pending surveys to complete. + ) : ( + You have no pending surveys. + )} +
diff --git a/ipi-survey-platform/src/components/overview/DetailedOverview.jsx b/ipi-survey-platform/src/components/overview/DetailedOverview.jsx index c01ac8e..284b670 100644 --- a/ipi-survey-platform/src/components/overview/DetailedOverview.jsx +++ b/ipi-survey-platform/src/components/overview/DetailedOverview.jsx @@ -450,7 +450,11 @@ export const DetailedOverview = ({ submission, onBack }) => { if (selectedProduct) { return ( setShowToast(false)} onBack={() => setSelectedProduct(null)} // Add this line to handle back navigation showToast={showToast} diff --git a/ipi-survey-platform/src/components/overview/ProductDetails.jsx b/ipi-survey-platform/src/components/overview/ProductDetails.jsx index 3d5e37f..f02ac83 100644 --- a/ipi-survey-platform/src/components/overview/ProductDetails.jsx +++ b/ipi-survey-platform/src/components/overview/ProductDetails.jsx @@ -440,6 +440,16 @@ const ProductDetails = ({ })()}
+ {String(submissionStatus).toLowerCase() === 'rejected' && ( +
+ +
+

+ {product.reject_reason || 'No reason provided'} +

+
+
+ )} diff --git a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx index 1c4de44..3209cbd 100644 --- a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx +++ b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx @@ -637,7 +637,7 @@ setAdditionalForecastMonths([ try { const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, { approve_reject_status: 1, - remarks: '' + reject_reason: '' }); const ok = @@ -675,7 +675,7 @@ setAdditionalForecastMonths([ try { const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, { approve_reject_status: 0, - remarks: rejectReason.trim() + reject_reason: rejectReason.trim() }); const ok = @@ -1786,12 +1786,18 @@ setAdditionalForecastMonths([ -
+
Remarks:{' '} {product.remarks || 'NA'}
+ {submissionData?.status === 'Rejected' && ( +
+ Reason for Rejection:{' '} + {submissionData.reject_reason || 'No reason provided'} +
+ )} -
+ {/*
@@ -1800,7 +1806,7 @@ setAdditionalForecastMonths([ className="w-[580px] rounded-[10px] border border-[#D1D5DB] bg-[#FFFCF2] px-4 py-2 mb-4 text-sm text-[#232528] focus:ring-2 focus:ring-[#92722A] focus:outline-none" placeholder="Please enter remarks here" > -
+
*/}
); diff --git a/ipi-survey-platform/src/pages/Admin/Validations.jsx b/ipi-survey-platform/src/pages/Admin/Validations.jsx index 2549feb..792b2ee 100644 --- a/ipi-survey-platform/src/pages/Admin/Validations.jsx +++ b/ipi-survey-platform/src/pages/Admin/Validations.jsx @@ -156,7 +156,7 @@ const ManageSubmissions = () => { try { const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, { approve_reject_status: 1, - remarks: '' + reject_reason: '' }); const ok = (response && response.data) || response?.status === 200 || response?.status === 'success'; @@ -209,7 +209,7 @@ const ManageSubmissions = () => { try { const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, { approve_reject_status: 0, - remarks: rejectReason.trim() + reject_reason: rejectReason.trim() }); const ok = (response && response.data) || response?.status === 200 || response?.status === 'success'; diff --git a/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx b/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx index bafa3a2..9aff204 100644 --- a/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx +++ b/ipi-survey-platform/src/pages/ManufacturingIndex/ManufacturingIndex.jsx @@ -184,12 +184,10 @@ const ManufacturingIndex = () => { })); // Log the full response for debugging - console.log('Full API Response:', response); // Extract next scheduled run date from response // The API response has the date in response.data.next_scheduled_run const nextRunDateString = response?.data?.nextScheduleDate; - console.log('Extracted next_scheduled_run:', nextRunDateString); if (nextRunDateString) { const nextRunDate = new Date(nextRunDateString); @@ -204,7 +202,6 @@ const ManufacturingIndex = () => { timeZoneName: 'short' }).replace(',', ''); // Remove comma after the day for cleaner format - console.log('Formatted next run date:', formattedDate); setNextScheduledRun(formattedDate); } else { console.error('Invalid date format from API:', nextRunDateString); diff --git a/ipi-survey-platform/src/pages/OTPVerification/OTPVerification.jsx b/ipi-survey-platform/src/pages/OTPVerification/OTPVerification.jsx index 811a4de..ab11977 100644 --- a/ipi-survey-platform/src/pages/OTPVerification/OTPVerification.jsx +++ b/ipi-survey-platform/src/pages/OTPVerification/OTPVerification.jsx @@ -159,7 +159,6 @@ const OTPVerification = () => { // Check if user is admin (case-insensitive check) if (userRole && userRole.toLowerCase() === 'admin') { redirectPath = '/admin/dashboard'; - console.log('Admin user detected, redirecting to admin dashboard'); } // If there's a saved path from before login, use that