Skip to content

Commit

Permalink
Merge pull request #83 from ibi-group/pretty-survey-response-dates
Browse files Browse the repository at this point in the history
fix(CDPUserDashboard): pretty date rendering for merged surveys
  • Loading branch information
miles-grant-ibigroup authored Apr 7, 2023
2 parents 68006dc + 2629bf1 commit efc0fe7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions components/CDPUserDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CDPZipProps = {
downloadedAt?: number
file: CDPFile
onClick: (key: string) => void
tripDataSuffix: string
}

const CDP_FILES_URL = `${process.env.API_BASE_URL}/api/secure/connected-data`
Expand All @@ -33,7 +34,9 @@ const CDPZip = (props: CDPZipProps): JSX.Element => (
onClick={() => props.onClick(props.file.key)}
title={`Download ${props.file.key}`}
>
<div className="ms-2 me-auto">{getDateFromCDPFileName(props.file.key)}</div>
<div className="ms-2 me-auto">
{getDateFromCDPFileName(props.file.key, props.tripDataSuffix)}
</div>
<div>
{props.downloadedAt && (
<Badge className="mr-1" pill variant="success">
Expand All @@ -52,12 +55,14 @@ const FileListing = ({
cdpUser,
downloadedFiles,
files,
setCurrentlyDownloadingFile
setCurrentlyDownloadingFile,
tripDataSuffix
}: {
cdpUser?: CDPUser
downloadedFiles: string[]
files: CDPFile[]
setCurrentlyDownloadingFile: (file: string) => void
tripDataSuffix: string
}): JSX.Element =>
files?.length === 0 ? (
<Alert variant="info">
Expand All @@ -76,6 +81,7 @@ const FileListing = ({
file={file}
key={file.key}
onClick={setCurrentlyDownloadingFile}
tripDataSuffix={tripDataSuffix}
/>
)
})}
Expand Down Expand Up @@ -168,6 +174,7 @@ const CDPUserDashboard = (props: Props): JSX.Element => {
downloadedFiles={downloadedFiles}
files={files.filter(isSurveyResponse(false))}
setCurrentlyDownloadingFile={setCurrentlyDownloadingFile}
tripDataSuffix="-anon-trip-data"
/>
</Tab>
{surveyResponses.length > 0 && (
Expand All @@ -187,6 +194,7 @@ const CDPUserDashboard = (props: Props): JSX.Element => {
(b.key.match(/\//g) || []).length
)}
setCurrentlyDownloadingFile={setCurrentlyDownloadingFile}
tripDataSuffix="-merged"
/>
</Tab>
)}
Expand Down
10 changes: 6 additions & 4 deletions util/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ export const getActiveUserTypes = (): {
*
* Able to handle all the date/time formats that are generated by the CDP.
*/
export const getDateFromCDPFileName = (filename: string): string => {
const TRIP_DATA_SUFFIX = '-anon-trip-data'
const date = filename.split(TRIP_DATA_SUFFIX)?.[0].split('/')?.[1]
if (!date || !filename.includes(TRIP_DATA_SUFFIX)) return filename
export const getDateFromCDPFileName = (
filename: string,
tripDataSuffix: string
): string => {
const date = filename.split(tripDataSuffix)?.[0].split('/')?.[1]
if (!date || !filename.includes(tripDataSuffix)) return filename

const parsedDate =
getDateOnlyFromCDPFileName(date) || getDateAndTimeFromCDPFileName(date)
Expand Down

1 comment on commit efc0fe7

@vercel
Copy link

@vercel vercel bot commented on efc0fe7 Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

otp-admin-ui – ./

otp-admin-ui-git-dev-ibi-group.vercel.app
otp-admin-ui-ibi-group.vercel.app
otp-admin-ui.vercel.app

Please sign in to comment.