Skip to content

Commit

Permalink
fix no correspondences in payload breaking page, ordering of accordio…
Browse files Browse the repository at this point in the history
…n, Reply to VA (#33813)
  • Loading branch information
hemeshvpatel authored Jan 6, 2025
1 parent 770092b commit 5bcaa9d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 21 deletions.
33 changes: 25 additions & 8 deletions src/applications/ask-va/config/helpers.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { format, isValid, parse } from 'date-fns';
import { utcToZonedTime } from 'date-fns-tz';
import { formatInTimeZone } from 'date-fns-tz';
import { enUS } from 'date-fns/locale';
import React from 'react';

import {
Expand Down Expand Up @@ -691,15 +692,31 @@ export const getDescriptiveTextFromCRM = status => {
// Function to convert date to Response Inbox format using date-fns
export const convertDateForInquirySubheader = dateString => {
// Parse the input date string as UTC
const utcDate = parse(dateString, 'MM/dd/yyyy h:mm:ss a', new Date());
let utcDate;
try {
utcDate = parse(dateString, 'M/d/yyyy h:mm:ss a', new Date(0));
utcDate.setUTCFullYear(utcDate.getFullYear());
utcDate.setUTCMonth(utcDate.getMonth());
utcDate.setUTCDate(utcDate.getDate());
utcDate.setUTCHours(utcDate.getHours());
utcDate.setUTCMinutes(utcDate.getMinutes());
utcDate.setUTCSeconds(utcDate.getSeconds());
} catch (error) {
return 'Invalid Date';
}

// Convert UTC to Eastern Time
const easternTime = utcToZonedTime(utcDate, 'America/New_York');
// Ensure the date is valid
if (isNaN(utcDate.getTime())) {
return 'Invalid Date';
}

// Format the date in Eastern Time
return format(easternTime, "MMM. d, yyyy 'at' h:mm aaaa 'E.T'", {
timeZone: 'America/New_York',
}).replace(/AM|PM/, match => `${match.toLowerCase()}.`);
// Format the UTC date in Eastern Time
return formatInTimeZone(
utcDate,
'America/New_York',
"MMM. d, yyyy 'at' h:mm aaaa 'E.T'",
{ locale: enUS },
).replace(/AM|PM/, match => `${match.toLowerCase()}.`);
};

export const formatDate = (dateString, formatType = 'short') => {
Expand Down
46 changes: 33 additions & 13 deletions src/applications/ask-va/containers/ResponseInboxPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { isLoggedIn } from '@department-of-veterans-affairs/platform-user/selectors';
import { apiRequest } from '@department-of-veterans-affairs/platform-utilities/api';
import { focusElement } from '@department-of-veterans-affairs/platform-utilities/ui';
import { parse } from 'date-fns';
import DOMPurify from 'dompurify';
import PropTypes from 'prop-types';
import React, { useCallback, useEffect, useState } from 'react';
Expand Down Expand Up @@ -37,6 +38,7 @@ const emptyMessage = message => (
const getReplySubHeader = messageType => {
if (!messageType) return 'No messageType';
if (messageType === 'ResponseFromVA') return 'Response from VA';
if (messageType === 'ReplyToVA') return 'Reply to VA';
// Split the string at capital letters and join with spaces
return messageType.split(/(?=[A-Z])/).join(' ');
};
Expand Down Expand Up @@ -232,21 +234,39 @@ const ResponseInboxPage = ({ router }) => {
),
messageType: 'Your question',
description: inquiryData.attributes.submitterQuestion,
originalCreatedOn: inquiryData.attributes.createdOn,
},
},
...inquiryData.attributes.correspondences.data
.filter(corr => corr.attributes.messageType !== 'Notification')
.map(corr => ({
...corr,
attributes: {
...corr.attributes,
createdOn: convertDateForInquirySubheader(corr.attributes.createdOn),
modifiedOn: convertDateForInquirySubheader(
corr.attributes.modifiedOn,
),
},
})),
];
...(inquiryData.attributes.correspondences.data
? inquiryData.attributes.correspondences.data
.filter(corr => corr.attributes.messageType !== 'Notification')
.map(corr => ({
...corr,
attributes: {
...corr.attributes,
createdOn: convertDateForInquirySubheader(
corr.attributes.createdOn,
),
modifiedOn: convertDateForInquirySubheader(
corr.attributes.modifiedOn,
),
originalCreatedOn: corr.attributes.createdOn,
},
}))
: []),
].sort((a, b) => {
const dateA = parse(
a.attributes.originalCreatedOn,
'MM/dd/yyyy h:mm:ss a',
new Date(),
);
const dateB = parse(
b.attributes.originalCreatedOn,
'MM/dd/yyyy h:mm:ss a',
new Date(),
);
return dateA.getTime() - dateB.getTime();
});

return (
<div className="row vads-u-padding-x--1">
Expand Down

0 comments on commit 5bcaa9d

Please sign in to comment.