changes in view submissions
This commit is contained in:
parent
7cd45e53da
commit
d93689735e
@ -176,7 +176,7 @@ const handleApproveConfirm = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
||||||
approve_reject_status: 1,
|
approve_reject_status: 1,
|
||||||
remarks: ''
|
reject_reason: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
||||||
@ -230,7 +230,7 @@ const handleRejectConfirm = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
||||||
approve_reject_status: 0,
|
approve_reject_status: 0,
|
||||||
remarks: rejectionReason.trim()
|
reject_reason: rejectionReason.trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import HeaderBar from '@/components/layout/HeaderBar';
|
import HeaderBar from '@/components/layout/HeaderBar';
|
||||||
|
import { fetchEstablishmentDashboard } from '@/services/establishments/establishmentService';
|
||||||
|
|
||||||
// const getCurrentQuarterAndYear = () => {
|
// const getCurrentQuarterAndYear = () => {
|
||||||
// const now = new Date();
|
// const now = new Date();
|
||||||
@ -28,45 +29,61 @@ const formatName = (name = '') => {
|
|||||||
.join(' ');
|
.join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const WelcomeSection = ({ data = null, loading = false, error = '' }) => {
|
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.';
|
useEffect(() => {
|
||||||
// if (loading) {
|
const fetchDashboardData = async () => {
|
||||||
// description = 'Loading dashboard information…';
|
try {
|
||||||
// } else if (error) {
|
setIsLoading(true);
|
||||||
// description = error;
|
// Get establishment ID from localStorage or props as needed
|
||||||
// } else if (currentQuarter && currentYear) {
|
const establishmentId = localStorage.getItem('establishment_id'); // Adjust this line based on how you store the establishment ID
|
||||||
// description = `Current reporting period: ${currentQuarter} ${currentYear}`;
|
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 (
|
return (
|
||||||
<div className="bg-gray-50">
|
<div className="bg-gray-50">
|
||||||
<HeaderBar />
|
<HeaderBar />
|
||||||
<div className="max-w-[1280px] mx-auto px-4 pt-2 pb-1">
|
<div className="max-w-[1280px] mx-auto pt-2 pb-1">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
||||||
Welcome{' '}
|
Welcome{' '}
|
||||||
{(() => {
|
{(() => {
|
||||||
try {
|
try {
|
||||||
const userProfile = JSON.parse(localStorage.getItem('user_profile'));
|
const userProfile = JSON.parse(localStorage.getItem('user_profile'));
|
||||||
return userProfile?.name ? formatName(userProfile.name) : '';
|
return userProfile?.name ? formatName(userProfile.name) : '';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error reading user_profile from localStorage:', error);
|
console.error('Error reading user_profile from localStorage:', error);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
})()}
|
})()}
|
||||||
!
|
!
|
||||||
</h2>
|
</h2>
|
||||||
|
<div className="text-base text-black mt-2">
|
||||||
{/* <p
|
{isLoading ? (
|
||||||
className={`w-[360px] text-[14px] leading-[24px] font-normal ${
|
<span>Loading survey information...</span>
|
||||||
error ? 'text-red-600' : 'text-[#5F646D]'
|
) : apiError ? (
|
||||||
}`}
|
<span className="text-red-600">{apiError}</span>
|
||||||
>
|
) : pendingSurveys > 0 ? (
|
||||||
{description}
|
<span>You currently have <span className="font-bold">{pendingSurveys}</span> pending surveys to complete.</span>
|
||||||
</p> */}
|
) : (
|
||||||
|
<span>You have no pending surveys.</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -450,7 +450,11 @@ export const DetailedOverview = ({ submission, onBack }) => {
|
|||||||
if (selectedProduct) {
|
if (selectedProduct) {
|
||||||
return (
|
return (
|
||||||
<ProductDetails
|
<ProductDetails
|
||||||
product={selectedProduct}
|
// product={selectedProduct}
|
||||||
|
product={{
|
||||||
|
...selectedProduct,
|
||||||
|
reject_reason: submissionData?.reject_reason // Add this line
|
||||||
|
}}
|
||||||
onClose={() => setShowToast(false)}
|
onClose={() => setShowToast(false)}
|
||||||
onBack={() => setSelectedProduct(null)} // Add this line to handle back navigation
|
onBack={() => setSelectedProduct(null)} // Add this line to handle back navigation
|
||||||
showToast={showToast}
|
showToast={showToast}
|
||||||
|
|||||||
@ -440,6 +440,16 @@ const ProductDetails = ({
|
|||||||
})()}
|
})()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{String(submissionStatus).toLowerCase() === 'rejected' && (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="block text-sm font-medium text-[#6B7280]">Reason for Rejection</label>
|
||||||
|
<div className="mt-1">
|
||||||
|
<p className="block w-full rounded-md border-0 py-1.5 text-gray-900 bg-white break-words whitespace-normal">
|
||||||
|
{product.reject_reason || 'No reason provided'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -637,7 +637,7 @@ setAdditionalForecastMonths([
|
|||||||
try {
|
try {
|
||||||
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
|
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
|
||||||
approve_reject_status: 1,
|
approve_reject_status: 1,
|
||||||
remarks: ''
|
reject_reason: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok =
|
const ok =
|
||||||
@ -675,7 +675,7 @@ setAdditionalForecastMonths([
|
|||||||
try {
|
try {
|
||||||
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
|
const response = await apiClient.put(`/approveOrRejectSubmission/${id}`, {
|
||||||
approve_reject_status: 0,
|
approve_reject_status: 0,
|
||||||
remarks: rejectReason.trim()
|
reject_reason: rejectReason.trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok =
|
const ok =
|
||||||
@ -1786,12 +1786,18 @@ setAdditionalForecastMonths([
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div className="mt-3 ml-4 text-sm text-[#4B5563]">
|
<div className="mt-6 ml-4 mb-3 text-sm text-[#4B5563]">
|
||||||
<strong className="font-semibold text-[#232528]">Remarks:</strong>{' '}
|
<strong className="font-semibold text-[#232528]">Remarks:</strong>{' '}
|
||||||
{product.remarks || 'NA'}
|
{product.remarks || 'NA'}
|
||||||
</div>
|
</div>
|
||||||
|
{submissionData?.status === 'Rejected' && (
|
||||||
|
<div className="mt-1 ml-4 mb-5 text-sm text-[#4B5563]">
|
||||||
|
<strong className="font-semibold text-[#232528]">Reason for Rejection:</strong>{' '}
|
||||||
|
{submissionData.reject_reason || 'No reason provided'}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="mt-3 ml-4">
|
{/* <div className="mt-3 ml-4">
|
||||||
<label className="block text-sm font-semibold mb-1 text-[#232528]">
|
<label className="block text-sm font-semibold mb-1 text-[#232528]">
|
||||||
Admin Remarks
|
Admin Remarks
|
||||||
</label>
|
</label>
|
||||||
@ -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"
|
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"
|
placeholder="Please enter remarks here"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -156,7 +156,7 @@ const ManageSubmissions = () => {
|
|||||||
try {
|
try {
|
||||||
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
||||||
approve_reject_status: 1,
|
approve_reject_status: 1,
|
||||||
remarks: ''
|
reject_reason: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
||||||
@ -209,7 +209,7 @@ const ManageSubmissions = () => {
|
|||||||
try {
|
try {
|
||||||
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
const response = await putRequest(`/approveOrRejectSubmission/${selectedSubmission.id}`, {
|
||||||
approve_reject_status: 0,
|
approve_reject_status: 0,
|
||||||
remarks: rejectReason.trim()
|
reject_reason: rejectReason.trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
const ok = (response && response.data) || response?.status === 200 || response?.status === 'success';
|
||||||
|
|||||||
@ -184,12 +184,10 @@ const ManufacturingIndex = () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Log the full response for debugging
|
// Log the full response for debugging
|
||||||
console.log('Full API Response:', response);
|
|
||||||
|
|
||||||
// Extract next scheduled run date from response
|
// Extract next scheduled run date from response
|
||||||
// The API response has the date in response.data.next_scheduled_run
|
// The API response has the date in response.data.next_scheduled_run
|
||||||
const nextRunDateString = response?.data?.nextScheduleDate;
|
const nextRunDateString = response?.data?.nextScheduleDate;
|
||||||
console.log('Extracted next_scheduled_run:', nextRunDateString);
|
|
||||||
|
|
||||||
if (nextRunDateString) {
|
if (nextRunDateString) {
|
||||||
const nextRunDate = new Date(nextRunDateString);
|
const nextRunDate = new Date(nextRunDateString);
|
||||||
@ -204,7 +202,6 @@ const ManufacturingIndex = () => {
|
|||||||
timeZoneName: 'short'
|
timeZoneName: 'short'
|
||||||
}).replace(',', ''); // Remove comma after the day for cleaner format
|
}).replace(',', ''); // Remove comma after the day for cleaner format
|
||||||
|
|
||||||
console.log('Formatted next run date:', formattedDate);
|
|
||||||
setNextScheduledRun(formattedDate);
|
setNextScheduledRun(formattedDate);
|
||||||
} else {
|
} else {
|
||||||
console.error('Invalid date format from API:', nextRunDateString);
|
console.error('Invalid date format from API:', nextRunDateString);
|
||||||
|
|||||||
@ -159,7 +159,6 @@ const OTPVerification = () => {
|
|||||||
// Check if user is admin (case-insensitive check)
|
// Check if user is admin (case-insensitive check)
|
||||||
if (userRole && userRole.toLowerCase() === 'admin') {
|
if (userRole && userRole.toLowerCase() === 'admin') {
|
||||||
redirectPath = '/admin/dashboard';
|
redirectPath = '/admin/dashboard';
|
||||||
console.log('Admin user detected, redirecting to admin dashboard');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a saved path from before login, use that
|
// If there's a saved path from before login, use that
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user