diff --git a/src/components/AdminAppointmentDetailsPopup.tsx b/src/components/AdminAppointmentDetailsPopup.tsx index 8e8097c..c05219a 100644 --- a/src/components/AdminAppointmentDetailsPopup.tsx +++ b/src/components/AdminAppointmentDetailsPopup.tsx @@ -58,6 +58,7 @@ import { Calendar as CalendarIcon } from 'lucide-react'; import { cn } from '@/lib/utils'; import ConfirmationEmailData from '@/types/ConfirmationEmailData'; import PracticeEmailData from '@/types/PracticeEmailData'; +import { updateRequestCreatedTime } from '@/utils/times'; type AdminAppointmentDetailsPopupProps = { open: boolean; @@ -94,6 +95,7 @@ const AdminAppointmentDetailsPopup = ({ scheduled_time, scheduled_by, is_cancelled, + created_at, } = clickedAppointment; const SEVEN_30_AM_IN_MINUTES = 60 * 7.5; @@ -249,6 +251,7 @@ const AdminAppointmentDetailsPopup = ({ } if (!isAppointmentScheduled && !isAppointmentCancelled) { statusList.push('Waiting'); + statusList.push(updateRequestCreatedTime(created_at!)); } return statusList.map((status, index) => ( diff --git a/src/utils/times.ts b/src/utils/times.ts new file mode 100644 index 0000000..2b88f22 --- /dev/null +++ b/src/utils/times.ts @@ -0,0 +1,31 @@ +const ONE_DAY_IN_MILLISECONDS = 86400000; +const ONE_HOUR_IN_MILLISECONDS = 3600000; + +function getDaysBetweenDates(timeBetween: number) { + const daysBetween = timeBetween / ONE_DAY_IN_MILLISECONDS; + const days = + daysBetween >= 0 ? Math.floor(daysBetween) : Math.ceil(daysBetween); + + if (days === 1) return `Requested 1 day ago`; + return `Requested ${days} days ago`; +} + +function getHoursBetweenDates(timeBetween: number) { + const hoursBetween = timeBetween / ONE_HOUR_IN_MILLISECONDS; + const hours = + hoursBetween >= 0 ? Math.floor(hoursBetween) : Math.ceil(hoursBetween); + + if (hours > 24) return getDaysBetweenDates(timeBetween); + + if (hours < 1) return `Requested < 1 hour ago`; + else if (hours === 1) return `Requested 1 hour ago`; + return `Requested ${hours} hours ago`; +} + +export function updateRequestCreatedTime(dateCreated: string) { + const today = new Date(); + const requestCreated = new Date(dateCreated); + const timeBetween = today.getTime() - requestCreated.getTime(); + + return getHoursBetweenDates(timeBetween); +}