From 7eda5d89c8755a5c08128d701950f95bba4e6d63 Mon Sep 17 00:00:00 2001 From: Emily Jablonski <65367387+emilyjablonski@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:37:41 -0700 Subject: [PATCH] fix: partial date formatting on paper app (#979) --- .../lib/applications/formatApplicationData.ts | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/sites/partners/src/lib/applications/formatApplicationData.ts b/sites/partners/src/lib/applications/formatApplicationData.ts index b56608eefb..2101caa8fb 100644 --- a/sites/partners/src/lib/applications/formatApplicationData.ts +++ b/sites/partners/src/lib/applications/formatApplicationData.ts @@ -1,4 +1,4 @@ -import { TimeFieldPeriod } from "@bloom-housing/ui-components" +import { DateFieldValues, TimeFieldPeriod, TimeFieldValues } from "@bloom-housing/ui-components" import { fieldGroupObjectToArray, adaFeatureKeys, @@ -85,42 +85,30 @@ export const mapFormToApi = ({ ? data.application?.language : null - const submissionDate: Date | null = (() => { - // rename default (wrong property names) - const { - day: submissionDay, - month: submissionMonth, - year: submissionYear, - } = data.dateSubmitted || {} - const { hours, minutes = 0, seconds = 0, period } = data?.timeSubmitted || {} + const getDateTime = (date: DateFieldValues, time: TimeFieldValues) => { + let day = date?.day + let month = date?.month + const year = date?.year + const { hours, minutes = 0, seconds = 0, period } = time || {} + + if (!day || !month || !year) return null - if (!submissionDay || !submissionMonth || !submissionYear) return null + if (month.length === 1) month = `0${month}` + if (day.length === 1) day = `0${day}` const dateString = dayjs( - `${submissionMonth}/${submissionDay}/${submissionYear} ${hours}:${minutes}:${seconds} ${period}`, + `${month}/${day}/${year} ${hours}:${minutes}:${seconds} ${period}`, "MM/DD/YYYY hh:mm:ss a" ).format(TIME_24H_FORMAT) const formattedDate = dayjs(dateString, TIME_24H_FORMAT).toDate() return formattedDate - })() - - const receivedAt: Date | null = (() => { - const { day: receivedDay, month: receivedMonth, year: receivedYear } = data?.dateReceived || {} - const { hours, minutes = 0, seconds = 0, period } = data?.timeReceived || {} - - if (!receivedDay || !receivedMonth || !receivedYear) return null - - const dateString = dayjs( - `${receivedMonth}/${receivedDay}/${receivedYear} ${hours}:${minutes}:${seconds} ${period}`, - "MM/DD/YYYY hh:mm:ss a" - ).format(TIME_24H_FORMAT) + } - const formattedDate = dayjs(dateString, TIME_24H_FORMAT).toDate() + const submissionDate: Date | null = getDateTime(data?.dateSubmitted, data?.timeSubmitted) - return formattedDate - })() + const receivedAt: Date | null = getDateTime(data?.dateReceived, data?.timeReceived) const receivedBy = data.application?.receivedBy || null