diff --git a/client/src/pages/ApplicationsPage/ApplicationsPage.tsx b/client/src/pages/ApplicationsPage/ApplicationsPage.tsx index e46f299..0bdbe1c 100644 --- a/client/src/pages/ApplicationsPage/ApplicationsPage.tsx +++ b/client/src/pages/ApplicationsPage/ApplicationsPage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; import { useAppSelector } from '../../app/hooks'; @@ -14,6 +14,7 @@ const ApplicationsPage = (): JSX.Element => { async function fetchApplications() { try { const response = await axios.get(`/api/applications?user_id=${user?._id}`); + setApplications(response.data); } catch (error) { console.error('Error fetching applications:', error); @@ -23,6 +24,37 @@ const ApplicationsPage = (): JSX.Element => { fetchApplications(); }, []); + const calculateIsInactive = (application: IApplication) => { + const { last_updated, notification_period, notifications_paused } = application; + if (notifications_paused) return false; + + const lastUpdatedDate = new Date(last_updated); + const notificationPeriodMs = (notification_period * 24 * 60 * 60 * 1000) / 60 / 60 / 24; + return new Date().getTime() - lastUpdatedDate.getTime() > notificationPeriodMs; + }; + + const handleTogglePause = async (id: number, pause: boolean) => { + try { + await axios.put(`/api/applications/${id}/pause-notifications`, { pause }); + setApplications((prevApps) => + prevApps.map((app) => (app.id === id ? { ...app, notifications_paused: pause } : app)), + ); + } catch (error) { + console.error('Error updating notification pause:', error); + } + }; + + const handlePeriodChange = async (id: number, period: number) => { + try { + await axios.put(`/api/applications/${id}/notification-period`, { period }); + setApplications((prevApps) => + prevApps.map((app) => (app.id === id ? { ...app, notification_period: period } : app)), + ); + } catch (error) { + console.error('Error updating notification period:', error); + } + }; + return (
@@ -42,6 +74,37 @@ const ApplicationsPage = (): JSX.Element => {
Status: {application.status}
Notes: {application.general_notes}
+ {calculateIsInactive(application) && ( +
+ This application needs attention! +
+ )} +
+ + +
+
+ + handleTogglePause(application.id, !e.target.checked)} + className="bg-gray-700 text-white p-1 rounded" + /> + + {application.notifications_paused ? 'Paused' : 'Active'} + +