Skip to content

Commit

Permalink
Merge branch 'main' into 977/correct-and-remove-work-addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgarrye authored Dec 9, 2024
2 parents 7471010 + 7eda5d8 commit f65f141
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions sites/partners/src/lib/applications/formatApplicationData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TimeFieldPeriod } from "@bloom-housing/ui-components"
import { DateFieldValues, TimeFieldPeriod, TimeFieldValues } from "@bloom-housing/ui-components"
import {
fieldGroupObjectToArray,
adaFeatureKeys,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f65f141

Please sign in to comment.