added draft in slide

This commit is contained in:
Malini 2026-02-10 14:55:01 +05:30
parent e00a597b83
commit 45557271a2
2 changed files with 40 additions and 8 deletions

View File

@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { ChevronLeft, ChevronRight, Pause } from 'lucide-react';
import { CalendarDays, Clock3 } from 'lucide-react';
import { fetchSubmissionDetail } from '@/services/submissions/submissionService';
const SurveyCarousel = ({
surveys = [],
autoRotate = true,
@ -62,10 +64,27 @@ const SurveyCarousel = ({
</div>
<button
onClick={() => {
localStorage.removeItem('currentSubmission');
onStartSurvey?.(current);
navigate('/survey', { state: { survey: current } });
onClick={async () => {
if (current?.status?.toLowerCase() === 'draft') {
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"
>

View File

@ -112,10 +112,21 @@ export const SurveyStatus = () => {
const nextDeadline = dashboardData?.next_deadline;
const formattedDueDate = formatDate(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 => {
// 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 {
title: `${quarter} ${year} Survey`,
@ -123,11 +134,13 @@ export const SurveyStatus = () => {
dueDate: formatDate(end_date),
relativeDue: formatRelativeDays(end_date),
estTime: '1520 minutes',
status: 'Pending',
status: draftSubmission ? 'Draft' : 'Pending',
startDate: start_date,
endDate: end_date,
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
};
}) || [];