changes in view submissions
This commit is contained in:
parent
7cd45e53da
commit
d93689735e
@ -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';
|
||||
|
||||
@ -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 (
|
||||
<div className="bg-gray-50">
|
||||
<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">
|
||||
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
||||
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 '';
|
||||
}
|
||||
})()}
|
||||
!
|
||||
</h2>
|
||||
|
||||
{/* <p
|
||||
className={`w-[360px] text-[14px] leading-[24px] font-normal ${
|
||||
error ? 'text-red-600' : 'text-[#5F646D]'
|
||||
}`}
|
||||
>
|
||||
{description}
|
||||
</p> */}
|
||||
<h2 className="w-[360px] text-[18px] pt-2 leading-[28px] font-medium text-[#232528]">
|
||||
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 '';
|
||||
}
|
||||
})()}
|
||||
!
|
||||
</h2>
|
||||
<div className="text-base text-black mt-2">
|
||||
{isLoading ? (
|
||||
<span>Loading survey information...</span>
|
||||
) : apiError ? (
|
||||
<span className="text-red-600">{apiError}</span>
|
||||
) : pendingSurveys > 0 ? (
|
||||
<span>You currently have <span className="font-bold">{pendingSurveys}</span> pending surveys to complete.</span>
|
||||
) : (
|
||||
<span>You have no pending surveys.</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -450,7 +450,11 @@ export const DetailedOverview = ({ submission, onBack }) => {
|
||||
if (selectedProduct) {
|
||||
return (
|
||||
<ProductDetails
|
||||
product={selectedProduct}
|
||||
// product={selectedProduct}
|
||||
product={{
|
||||
...selectedProduct,
|
||||
reject_reason: submissionData?.reject_reason // Add this line
|
||||
}}
|
||||
onClose={() => setShowToast(false)}
|
||||
onBack={() => setSelectedProduct(null)} // Add this line to handle back navigation
|
||||
showToast={showToast}
|
||||
|
||||
@ -440,6 +440,16 @@ const ProductDetails = ({
|
||||
})()}
|
||||
</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>
|
||||
|
||||
|
||||
@ -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([
|
||||
</tbody>
|
||||
</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>{' '}
|
||||
{product.remarks || 'NA'}
|
||||
</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]">
|
||||
Admin Remarks
|
||||
</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"
|
||||
placeholder="Please enter remarks here"
|
||||
></textarea>
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user