establishment dashboard bug solved
This commit is contained in:
parent
6c20f2d769
commit
7f666b13b3
@ -2,11 +2,6 @@ import React from 'react';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import SurveyCarousel from './SurveyCarousel';
|
import SurveyCarousel from './SurveyCarousel';
|
||||||
|
|
||||||
const formatQuarterYear = (quarter, year) => {
|
|
||||||
if (!quarter || !year) return '—';
|
|
||||||
return `${quarter} ${year}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatDate = (value) => {
|
const formatDate = (value) => {
|
||||||
if (!value) return '—';
|
if (!value) return '—';
|
||||||
const date = new Date(value);
|
const date = new Date(value);
|
||||||
@ -31,12 +26,42 @@ const formatRelativeDays = (value) => {
|
|||||||
return `Due in ${diffDays} day${diffDays === 1 ? '' : 's'}`;
|
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 = '' }) => {
|
export const SurveyStatus = ({ data = null, loading = false, error = '' }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleStartSurvey = (survey) => {
|
const handleStartSurvey = (survey) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { previous, current, next } = getQuarterData();
|
||||||
|
|
||||||
const surveyData = data || {};
|
const surveyData = data || {};
|
||||||
const nextDeadline = surveyData?.next_deadline;
|
const nextDeadline = surveyData?.next_deadline;
|
||||||
const formattedDueDate = formatDate(nextDeadline);
|
const formattedDueDate = formatDate(nextDeadline);
|
||||||
@ -44,28 +69,28 @@ export const SurveyStatus = ({ data = null, loading = false, error = '' }) => {
|
|||||||
|
|
||||||
const surveys = [
|
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',
|
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
|
||||||
dueDate: formattedDueDate,
|
dueDate: formattedDueDate,
|
||||||
relativeDue,
|
relativeDue,
|
||||||
estTime: '15–20 minutes',
|
estTime: '15–20 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',
|
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
|
||||||
dueDate: formattedDueDate,
|
dueDate: formattedDueDate,
|
||||||
relativeDue,
|
relativeDue,
|
||||||
estTime: '15–20 minutes',
|
estTime: '15–20 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',
|
subtitle: 'Complete your quarterly Industrial Production Index (IPI) data submission',
|
||||||
dueDate: formattedDueDate,
|
dueDate: formattedDueDate,
|
||||||
relativeDue,
|
relativeDue,
|
||||||
estTime: '15–20 minutes',
|
estTime: '15–20 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">
|
<section className="max-w-[1340px] mx-auto px-0">
|
||||||
<div className="p-6">
|
<div className="p-6">
|
||||||
{loading ? (
|
{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 ? (
|
) : error ? (
|
||||||
<div className="text-center text-red-600 text-sm py-10">{error}</div>
|
<div className="text-center text-red-600 text-sm py-10">{error}</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -1,16 +1,22 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import HeaderBar from '@/components/layout/HeaderBar';
|
import HeaderBar from '@/components/layout/HeaderBar';
|
||||||
|
|
||||||
const formatDate = (value) => {
|
const getCurrentQuarterAndYear = () => {
|
||||||
if (!value) return '—';
|
const now = new Date();
|
||||||
const date = new Date(value);
|
const month = now.getMonth() + 1;
|
||||||
if (Number.isNaN(date.getTime())) return '—';
|
const year = now.getFullYear();
|
||||||
return date.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' });
|
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 = '' }) => {
|
export const WelcomeSection = ({ data = null, loading = false, error = '' }) => {
|
||||||
const currentQuarter = data?.current_quarter;
|
const { quarter: currentQuarter, year: currentYear } = getCurrentQuarterAndYear();
|
||||||
const currentYear = data?.current_quarter_year;
|
|
||||||
|
|
||||||
let description = 'Current reporting information unavailable.';
|
let description = 'Current reporting information unavailable.';
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@ -50,3 +56,5 @@ export const WelcomeSection = ({ data = null, loading = false, error = '' }) =>
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default WelcomeSection;
|
||||||
Loading…
Reference in New Issue
Block a user