diff --git a/frontend/src/pages/Applications/Applications.js b/frontend/src/pages/Applications/Applications.js index 641ff8f..238c68a 100644 --- a/frontend/src/pages/Applications/Applications.js +++ b/frontend/src/pages/Applications/Applications.js @@ -211,14 +211,41 @@ const Applications = () => { }; const handleArchiveApplication = async (applicationId) => { - if (!window.confirm('Are you sure you want to archive this application? It will be moved to the archive and hidden from the main list.')) { + if (!window.confirm('Are you sure you want to archive this application? It will be hidden from the main list but preserved in your records.')) { return; } try { - await applicationsAPI.updatePlanStatus(applicationId, 'archived'); + // Try different possible status values that might work for archiving + const possibleArchiveStatuses = ['archived', 'hidden', 'inactive', 'done']; + + for (const status of possibleArchiveStatuses) { + try { + await applicationsAPI.updatePlanStatus(applicationId, status); + toast.success('Application archived successfully'); + fetchApplications(); // Refresh the list + return; + } catch (statusError) { + // Continue to next status if this one fails + console.log(`Status '${status}' failed, trying next...`); + } + } + + // If all status updates fail, we need to use a different approach + // Let's try updating the plan with a custom archived flag + const planResponse = await applicationsAPI.getPlan(applicationId); + const planData = planResponse.data.data.plan; + + // Update the plan with an archived flag + await applicationsAPI.updatePlan(applicationId, { + ...planData, + archived: true, + notes: planData.notes ? `${planData.notes} [ARCHIVED]` : '[ARCHIVED]' + }); + toast.success('Application archived successfully'); fetchApplications(); // Refresh the list + } catch (error) { console.error('Failed to archive application:', error); toast.error('Failed to archive application'); @@ -228,13 +255,22 @@ const Applications = () => { // Filter and sort applications const filteredAndSortedApplications = React.useMemo(() => { let filtered = applications.filter(app => { - // Hide archived applications unless specifically filtering for them - if (app.status === 'archived' && filters.status !== 'archived') { + // Hide archived applications unless specifically viewing archived ones + const isArchived = app.archived === true || + app.notes?.includes('[ARCHIVED]') || + ['archived', 'hidden', 'inactive', 'done'].includes(app.status); + + if (isArchived && filters.status !== 'archived') { return false; } - // Status filter - if (filters.status !== 'all' && app.status !== filters.status) { + // If filtering for archived, only show archived items + if (filters.status === 'archived' && !isArchived) { + return false; + } + + // Status filter (excluding archived since we handle it separately) + if (filters.status !== 'all' && filters.status !== 'archived' && app.status !== filters.status) { return false; }