establishment dashboard bug solved

This commit is contained in:
Senthamilselvi 2025-11-06 12:25:29 +05:30
parent 6c20f2d769
commit 7f666b13b3
2 changed files with 56 additions and 21 deletions

View File

@ -2,11 +2,6 @@ import React from 'react';
import { useNavigate } from 'react-router-dom';
import SurveyCarousel from './SurveyCarousel';
const formatQuarterYear = (quarter, year) => {
if (!quarter || !year) return '—';
return `${quarter} ${year}`;
};
const formatDate = (value) => {
if (!value) return '—';
const date = new Date(value);
@ -31,12 +26,42 @@ const formatRelativeDays = (value) => {
return `Due in ${diffDays} day${diffDays === 1 ? '' : 's'}`;
};
const getQuarterData = () => {
const now = new Date();
const month = now.getMonth() + 1;
const year = now.getFullYear();
let currentQuarter = '';
if (month >= 1 && month <= 3) currentQuarter = 'Q1';
else if (month >= 4 && month <= 6) currentQuarter = 'Q2';
else if (month >= 7 && month <= 9) currentQuarter = 'Q3';
else currentQuarter = 'Q4';
const quarters = ['Q1', 'Q2', 'Q3', 'Q4'];
const currentIndex = quarters.indexOf(currentQuarter);
const previousQuarter =
currentIndex === 0 ? 'Q4' : quarters[currentIndex - 1];
const nextQuarter =
currentIndex === 3 ? 'Q1' : quarters[currentIndex + 1];
const previousYear = currentIndex === 0 ? year - 1 : year;
const nextYear = currentIndex === 3 ? year + 1 : year;
return {
previous: { quarter: previousQuarter, year: previousYear },
current: { quarter: currentQuarter, year },
next: { quarter: nextQuarter, year: nextYear },
};
};
export const SurveyStatus = ({ data = null, loading = false, error = '' }) => {
const navigate = useNavigate();
const handleStartSurvey = (survey) => {
};
const { previous, current, next } = getQuarterData();
const surveyData = data || {};
const nextDeadline = surveyData?.next_deadline;
const formattedDueDate = formatDate(nextDeadline);
@ -44,28 +69,28 @@ export const SurveyStatus = ({ data = null, loading = false, error = '' }) => {
const surveys = [
{
title: `${formatQuarterYear(surveyData.previous_quarter, surveyData.previous_quarter_year)} Survey Ready`,
title: `${previous.quarter} ${previous.year} Survey Ready`,
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
dueDate: formattedDueDate,
relativeDue,
estTime: '1520 minutes',
status: surveyData?.submission_status || 'Pending',
status: 'Pending',
},
{
title: `${formatQuarterYear(surveyData.current_quarter, surveyData.current_quarter_year)} Survey Ready`,
title: `${current.quarter} ${current.year} Survey Ready`,
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
dueDate: formattedDueDate,
relativeDue,
estTime: '1520 minutes',
status: surveyData?.submission_status || 'Pending',
status: 'Pending',
},
{
title: `${formatQuarterYear(surveyData.next_quarter, surveyData.next_quarter_year)} Survey Ready`,
title: `${next.quarter} ${next.year} Survey Ready`,
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
dueDate: formattedDueDate,
relativeDue,
estTime: '1520 minutes',
status: surveyData?.submission_status || 'Pending',
status: 'Pending',
},
];
@ -85,7 +110,9 @@ export const SurveyStatus = ({ data = null, loading = false, error = '' }) => {
<section className="max-w-[1340px] mx-auto px-0">
<div className="p-6">
{loading ? (
<div className="text-center text-gray-500 text-sm py-10">Loading survey status...</div>
<div className="text-center text-gray-500 text-sm py-10">
Loading survey status...
</div>
) : error ? (
<div className="text-center text-red-600 text-sm py-10">{error}</div>
) : (

View File

@ -1,16 +1,22 @@
import React from 'react';
import HeaderBar from '@/components/layout/HeaderBar';
const formatDate = (value) => {
if (!value) return '—';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return '—';
return date.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' });
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';
return { quarter, year };
};
export const WelcomeSection = ({ data = null, loading = false, error = '' }) => {
const currentQuarter = data?.current_quarter;
const currentYear = data?.current_quarter_year;
const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear();
let description = 'Current reporting information unavailable.';
if (loading) {
@ -49,4 +55,6 @@ export const WelcomeSection = ({ data = null, loading = false, error = '' }) =>
</div>
</div>
);
};
};
export default WelcomeSection;