Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the legacy format functions with formatDate #7387

Merged
merged 16 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/apps/investments/client/projects/transformers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { formatMediumDateTime } = require('../../../../client/utils/date')
const {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} = require('../../../../client/utils/date-utils')

const { addressToString } = require('../../../../client/utils/addresses')

Expand All @@ -9,7 +12,7 @@ const transformCompanyToListItem = (company) => ({
meta: [
{
label: 'Updated on',
value: formatMediumDateTime(company.modified_on),
value: formatDate(company.modified_on, DATE_FORMAT_MEDIUM_WITH_TIME),
},
{
label: 'Company address',
Expand Down
10 changes: 8 additions & 2 deletions src/apps/investments/middleware/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const { getDitCompany } = require('../../companies/repos')
const { getAdviser } = require('../../adviser/repos')
const { getInvestment } = require('../repos')
const { companies, investments } = require('../../../lib/urls')
const { formatMediumDateTime } = require('../../../client/utils/date')
const {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} = require('../../../client/utils/date-utils')

function getCompanyDetails(req, res, next) {
getDitCompany(req, req.params.companyId)
Expand Down Expand Up @@ -82,7 +85,10 @@ async function getInvestmentDetails(req, res, next) {
},
{
label: 'Created on',
value: formatMediumDateTime(investment.created_on),
value: formatDate(
investment.created_on,
DATE_FORMAT_MEDIUM_WITH_TIME
),
},
...(investment.created_by?.dit_team?.name
? [
Expand Down
7 changes: 5 additions & 2 deletions src/client/components/AuditHistory/transformers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react'
import { capitalize, isEmpty, lowerCase } from 'lodash'

import { formatMediumDateTime } from '../../utils/date'
import {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} from '../../utils/date-utils'
import { AUTOMATIC_UPDATE } from './constants'

export const transformFieldName = (fieldName) =>
Expand All @@ -24,7 +27,7 @@ const transformChanges = (changes, fieldMapper, excludedFields) =>
}))

const getUpdatedBy = (timestamp, user) => {
const formattedTime = formatMediumDateTime(timestamp)
const formattedTime = formatDate(timestamp, DATE_FORMAT_MEDIUM_WITH_TIME)
const changedBy = user
? isEmpty(user?.name)
? user?.email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Filters from './MyCompaniesFilters'
import { GREY_1, GREY_3, TEXT_COLOUR } from '../../../../client/utils/colours'
import urls from '../../../../lib/urls'

const { formatMediumDate } = require('../../../utils/date')
const { formatDate, DATE_FORMAT_MEDIUM } = require('../../../utils/date-utils')

const StyledCellHeader = styled(Table.CellHeader)(
typography.font({ size: 14, weight: 'bold' }),
Expand Down Expand Up @@ -100,7 +100,7 @@ function MyCompaniesTable() {
</Table.Cell>
<StyledDateCell setWidth="15%">
{latestInteraction.date
? formatMediumDate(latestInteraction.date)
? formatDate(latestInteraction.date, DATE_FORMAT_MEDIUM)
: '-'}
</StyledDateCell>
<Table.Cell setWidth="50%">
Expand Down
6 changes: 3 additions & 3 deletions src/client/components/Dashboard/my-tasks/MyTasksTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link, Table } from 'govuk-react'

import styled from 'styled-components'

import { formatMediumDateParsed } from '../../../utils/date'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'
import { STATUS } from '../../../modules/Tasks/TaskForm/constants'

Expand Down Expand Up @@ -34,9 +34,9 @@ const rows = ({ results }) => {
<Table.Row key={`task_row_${index}`} data-test="task-item">
<Table.Cell setWidth="12%">
{task.due_date
? formatMediumDateParsed(task.due_date)
? formatDate(task.due_date, DATE_FORMAT_MEDIUM)
: task.dueDate
? formatMediumDateParsed(task.dueDate)
? formatDate(task.dueDate, DATE_FORMAT_MEDIUM)
: ''}
</Table.Cell>
<Table.Cell setWidth="23%">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { kebabCase, upperFirst } from 'lodash'

import Timeline from '../Timeline'

import { formatMediumDateTime } from '../../utils/date'
import {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} from '../../utils/date-utils'
import timelineTheme from './timeline-theme'
import urls from '../../../lib/urls'
import { INVESTMENT_PROJECT_STAGES } from '../../modules/Investments/Projects/constants'
Expand Down Expand Up @@ -87,7 +90,9 @@ const InvestmentProjectLocalHeader = ({ investment }) => (
{investment.valueComplete ? 'Project valued' : 'Not yet valued'}
</MetaListItem>
<MetaListItem text="Created on">
{investment.createdOn ? formatMediumDateTime(investment.createdOn) : ''}
{investment.createdOn
? formatDate(investment.createdOn, DATE_FORMAT_MEDIUM_WITH_TIME)
: ''}
</MetaListItem>
{investment.createdBy?.ditTeam?.name && (
<MetaListItem text="Created by">
Expand Down
12 changes: 9 additions & 3 deletions src/client/filters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const { formatLongDate, formatShortDate } = require('./utils/date')
const {
formatDate,
DATE_FORMAT_FULL,
DATE_FORMAT_MONTH_YEAR,
} = require('./utils/date-utils')

const getDateLabel = (value) => (value ? formatLongDate(value) : '')
const getShortDateLabel = (value) => (value ? formatShortDate(value) : '')
const getDateLabel = (value) =>
value ? formatDate(value, DATE_FORMAT_FULL) : ''
const getShortDateLabel = (value) =>
value ? formatDate(value, DATE_FORMAT_MONTH_YEAR) : ''

export const buildOptionsFilter = ({
options = [],
Expand Down
8 changes: 6 additions & 2 deletions src/client/modules/Companies/CollectionList/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import urls from '../../../../lib/urls'

import { addressToString } from '../../../utils/addresses'

const { format, formatMediumDateTime } = require('../../../utils/date')
const { format } = require('../../../utils/date')
const {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} = require('../../../utils/date-utils')

export const transformArchivedToApi = (archivedParam) => {
const archived = Array.isArray(archivedParam)
Expand Down Expand Up @@ -79,7 +83,7 @@ const transformCompanyToListItem = ({
return {
id,
subheading: modified_on
? `Updated on ${formatMediumDateTime(modified_on)}`
? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.companies.detail(id),
Expand Down
62 changes: 31 additions & 31 deletions src/client/modules/Companies/CompanyActivity/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from '@govuk-react/link'

import { TAGS } from './constants'
import urls from '../../../../lib/urls'
import { formatMediumDateParsed } from '../../../utils/date'
import { formatDate, DATE_FORMAT_MEDIUM } from '../../../utils/date-utils'
import { truncateData } from '../utils'
import { AdviserResource } from '../../../components/Resource'
import { INTERACTION_NAMES } from '../../../../apps/interactions/constants'
Expand Down Expand Up @@ -93,7 +93,8 @@ export const transformInteractionToListItem = (activity) => {
metadata: [
{
label: 'Date',
value: interaction.date ? formatMediumDateParsed(interaction.date) : '',
value:
interaction.date && formatDate(interaction.date, DATE_FORMAT_MEDIUM),
},
{
label: verifyLabel(interaction.contacts, 'Contact'),
Expand All @@ -116,9 +117,7 @@ export const transformInteractionToListItem = (activity) => {
dataTest: 'activity-kind-label',
},
{
text: interaction.service
? getServiceText(interaction.service?.name)
: '',
text: interaction.service && getServiceText(interaction.service?.name),
colour: 'blue',
dataTest: 'activity-service-label',
},
Expand All @@ -135,13 +134,13 @@ export const transformReferralToListItem = (activity) => {
metadata: [
{
label: 'Created on',
value: formatMediumDateParsed(referral.created_on),
value: formatDate(referral.created_on, DATE_FORMAT_MEDIUM),
},
{
label: 'Completed on',
value: referral.completed_on
? formatMediumDateParsed(referral.completed_on)
: '',
value:
referral.completed_on &&
formatDate(referral.completed_on, DATE_FORMAT_MEDIUM),
},
{
label: 'Sending adviser',
Expand Down Expand Up @@ -177,19 +176,22 @@ export const transformInvestmentToListItem = (activity) => {
return {
id: activity.investment.id,
metadata: [
{ label: 'Created Date', value: formatMediumDateParsed(activity.date) },
{
label: 'Created Date',
value: formatDate(activity.date, DATE_FORMAT_MEDIUM),
},
{
label: 'Investment Type',
value: activity.investment.investment_type.name,
},
{
label: 'Added by',
value: activity.investment.created_by
? AdviserRenderer({
adviser: activity.investment.created_by,
team: activity.investment.created_by.dit_team,
})
: '',
value:
activity.investment.created_by &&
AdviserRenderer({
adviser: activity.investment.created_by,
team: activity.investment.created_by.dit_team,
}),
},
{
label: 'Estimated land date',
Expand Down Expand Up @@ -234,32 +236,30 @@ export const transformOrderToListItem = (activity) => {
return {
id: activity.order.id,
metadata: [
{ label: 'Date', value: formatMediumDateParsed(activity.date) },
{ label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Country',
value: activity.order.primary_market.name,
},
activity.order.uk_region
? {
label: 'UK region',
value: activity.order.uk_region.name,
}
: '',
activity.order.uk_region && {
label: 'UK region',
value: activity.order.uk_region.name,
},
{
label: 'Added by',
value: activity.order.created_by
? AdviserRenderer({
adviser: activity.order.created_by,
team: activity.order.created_by.dit_team,
})
: '',
value:
activity.order.created_by &&
AdviserRenderer({
adviser: activity.order.created_by,
team: activity.order.created_by.dit_team,
}),
},
{
label: 'Company Contact',
value:
activity.order.contact.name + ' ' + activity.order.contact.job_title,
},
].filter(({ value }) => Boolean(value)),
].filter((entry) => entry && Boolean(entry.value)),
tags: [
{
text: 'Orders (OMIS)',
Expand Down Expand Up @@ -287,7 +287,7 @@ export const transformGreatExportEnquiryToListItem = (activity) => {
return {
id: great.id,
metadata: [
{ label: 'Date', value: formatMediumDateParsed(activity.date) },
{ label: 'Date', value: formatDate(activity.date, DATE_FORMAT_MEDIUM) },
{
label: 'Contact',
value: formattedContacts([great.contact]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { isBoolean, isNumber } from 'lodash'

import {
formatMediumDateTimeWithoutParsing,
isUnparsedDateValid,
} from '../../../../utils/date'
import { COMPANY_FIELD_NAME_TO_LABEL_MAP, HEADQUARTER_TYPES } from './constants'
import {
ARCHIVED,
Expand Down Expand Up @@ -31,17 +27,21 @@ const getValueFromBoolean = (value, field) => {
}
}

export const getValue = (value, field) =>
isBoolean(value)
? getValueFromBoolean(value, field)
: isNumber(value)
? field === 'Turnover'
? currencyGBP(value, {
maximumSignificantDigits: 2,
})
: value.toString()
: isUnparsedDateValid(value)
? formatMediumDateTimeWithoutParsing(value)
: field === 'Headquarter type'
? HEADQUARTER_TYPES[value] || NOT_SET
: value || NOT_SET
export const getValue = (value, field) => {
if (isBoolean(value)) {
return getValueFromBoolean(value, field)
}

if (isNumber(value)) {
if (field === 'Turnover') {
return currencyGBP(value, { maximumSignificantDigits: 2 })
}
return value.toString()
}

if (field === 'Headquarter type') {
return HEADQUARTER_TYPES[value] || NOT_SET
}

return value || NOT_SET
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import urls from '../../../../../lib/urls'

import { addressToString } from '../../../../utils/addresses'

const { format, formatMediumDateTime } = require('../../../../utils/date')
const { format } = require('../../../../utils/date')
const {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} = require('../../../../utils/date-utils')

const transformGlobalHQToListItem = (childCompanyId) => (company) => {
const {
Expand Down Expand Up @@ -54,7 +58,7 @@ const transformGlobalHQToListItem = (childCompanyId) => (company) => {
return {
id,
subheading: modified_on
? `Updated on ${formatMediumDateTime(modified_on)}`
? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: urls.companies.hierarchies.ghq.add(childCompanyId, id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import urls from '../../../../../lib/urls'

import { addressToString } from '../../../../utils/addresses'

const { format, formatMediumDateTime } = require('../../../../utils/date')
const { format } = require('../../../../utils/date')
const {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} = require('../../../../utils/date-utils')

const isGlobalHQ = (hqId) => hqId == '43281c5e-92a4-4794-867b-b4d5f801e6f3'

Expand Down Expand Up @@ -70,7 +74,7 @@ const transformSubsidiaryToListItem = (parentCompanyId) => (company) => {
return {
id,
subheading: modified_on
? `Updated on ${formatMediumDateTime(modified_on)}`
? `Updated on ${formatDate(modified_on, DATE_FORMAT_MEDIUM_WITH_TIME)}`
: undefined,
headingText: name,
headingUrl: buildUrl(id, parentCompanyId, headquarter_type),
Expand Down
Loading
Loading