added draft in slide
This commit is contained in:
parent
e00a597b83
commit
45557271a2
@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { ChevronLeft, ChevronRight, Pause } from 'lucide-react';
|
import { ChevronLeft, ChevronRight, Pause } from 'lucide-react';
|
||||||
import { CalendarDays, Clock3 } from 'lucide-react';
|
import { CalendarDays, Clock3 } from 'lucide-react';
|
||||||
|
import { fetchSubmissionDetail } from '@/services/submissions/submissionService';
|
||||||
|
|
||||||
const SurveyCarousel = ({
|
const SurveyCarousel = ({
|
||||||
surveys = [],
|
surveys = [],
|
||||||
autoRotate = true,
|
autoRotate = true,
|
||||||
@ -62,10 +64,27 @@ const SurveyCarousel = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
localStorage.removeItem('currentSubmission');
|
|
||||||
onStartSurvey?.(current);
|
if (current?.status?.toLowerCase() === 'draft') {
|
||||||
navigate('/survey', { state: { survey: current } });
|
try {
|
||||||
|
const submissionData = await fetchSubmissionDetail(current.draftId);
|
||||||
|
localStorage.removeItem('currentSubmission');
|
||||||
|
navigate('/survey', {
|
||||||
|
state: {
|
||||||
|
submission: submissionData,
|
||||||
|
isEdit: true,
|
||||||
|
fromDraft: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching submission details:', error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('currentSubmission');
|
||||||
|
onStartSurvey?.(current);
|
||||||
|
navigate('/survey', { state: { survey: current } });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
className="w-full sm:w-auto mt-0 flex-shrink-0 items-center justify-center px-5 py-3 text-base font-medium rounded-lg text-white bg-[#92722A] hover:bg-[#7b5c1f] cursor-pointer whitespace-nowrap transition-colors"
|
className="w-full sm:w-auto mt-0 flex-shrink-0 items-center justify-center px-5 py-3 text-base font-medium rounded-lg text-white bg-[#92722A] hover:bg-[#7b5c1f] cursor-pointer whitespace-nowrap transition-colors"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -112,10 +112,21 @@ export const SurveyStatus = () => {
|
|||||||
const nextDeadline = dashboardData?.next_deadline;
|
const nextDeadline = dashboardData?.next_deadline;
|
||||||
const formattedDueDate = formatDate(nextDeadline);
|
const formattedDueDate = formatDate(nextDeadline);
|
||||||
const relativeDue = formatRelativeDays(nextDeadline);
|
const relativeDue = formatRelativeDays(nextDeadline);
|
||||||
|
//here add condition to check q1 and year based on that check submission_history status and store in variable here
|
||||||
const surveys = dashboardData?.survey_ready?.map(survey => {
|
const surveys = dashboardData?.survey_ready?.map(survey => {
|
||||||
// Get the quarter and year from the survey_ready item
|
// Get the quarter and year from the survey_ready item
|
||||||
const { quarter, year, start_date, end_date } = survey;
|
const { quarter, year, start_date, end_date, survey_name } = survey;
|
||||||
|
|
||||||
|
// Check if there's a draft submission for this survey
|
||||||
|
const draftSubmission = dashboardData?.submission_history?.find(
|
||||||
|
submission =>
|
||||||
|
submission.quarter === quarter &&
|
||||||
|
submission.year === year &&
|
||||||
|
submission.status.toLowerCase() === 'draft' &&
|
||||||
|
submission.survey_name === survey_name
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: `${quarter} ${year} Survey`,
|
title: `${quarter} ${year} Survey`,
|
||||||
@ -123,11 +134,13 @@ export const SurveyStatus = () => {
|
|||||||
dueDate: formatDate(end_date),
|
dueDate: formatDate(end_date),
|
||||||
relativeDue: formatRelativeDays(end_date),
|
relativeDue: formatRelativeDays(end_date),
|
||||||
estTime: '15–20 minutes',
|
estTime: '15–20 minutes',
|
||||||
status: 'Pending',
|
status: draftSubmission ? 'Draft' : 'Pending',
|
||||||
startDate: start_date,
|
startDate: start_date,
|
||||||
endDate: end_date,
|
endDate: end_date,
|
||||||
quarter: quarter, // This will be used in the navigation
|
quarter: quarter, // This will be used in the navigation
|
||||||
year: year // This will be used in the navigation
|
year: year, // This will be used in the navigation
|
||||||
|
survey_name: survey_name, // Add survey_name for matching
|
||||||
|
draftId: draftSubmission?.id || null // Include draft ID if exists
|
||||||
};
|
};
|
||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user