import React, { useState, useEffect } from 'react'; import { API } from '../../api/API'; import { toast } from 'sonner'; import { useNavigate } from 'react-router-dom'; import { Plus, Edit2, Calendar, CheckCircle, XCircle } from 'lucide-react'; import { format } from 'date-fns'; interface QuestionnaireVersion { id: string; version: string; isActive: boolean; createdAt: string; } const QuestionnaireList: React.FC = () => { const [versions, setVersions] = useState([]); const [loading, setLoading] = useState(true); const navigate = useNavigate(); useEffect(() => { fetchVersions(); }, []); const fetchVersions = async () => { try { setLoading(true); const response = await API.getAllQuestionnaires() as any; if (response.data?.success) { setVersions(response.data.data); } else { toast.error('Failed to load questionnaire versions'); } } catch (error) { console.error(error); toast.error('Error fetching versions'); } finally { setLoading(false); } }; return (

Questionnaire Versions

Manage your questionnaire templates and versions

{loading ? (
) : versions.length === 0 ? (

No questionnaire versions found.

) : (
{versions.map((v) => ( ))}
Version Name Status Created At Actions
{v.version} {v.isActive ? ( Active ) : ( Inactive )}
{format(new Date(v.createdAt), 'MMM dd, yyyy HH:mm')}
)}
); }; export default QuestionnaireList;