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 11 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
19 changes: 12 additions & 7 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 { 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,9 @@
metadata: [
{
label: 'Date',
value: interaction.date ? formatMediumDateParsed(interaction.date) : '',
value: interaction.date
? formatDate(interaction.date, DATE_FORMAT_MEDIUM)
: '',

Check warning on line 98 in src/client/modules/Companies/CompanyActivity/transformers.js

View check run for this annotation

Codecov / codecov/patch

src/client/modules/Companies/CompanyActivity/transformers.js#L98

Added line #L98 was not covered by tests
},
{
label: verifyLabel(interaction.contacts, 'Contact'),
Expand Down Expand Up @@ -135,12 +137,12 @@
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)
? formatDate(referral.completed_on, DATE_FORMAT_MEDIUM)
: '',
},
{
Expand Down Expand Up @@ -177,7 +179,10 @@
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,
Expand Down Expand Up @@ -234,7 +239,7 @@
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,
Expand Down Expand Up @@ -287,7 +292,7 @@
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,10 @@
import { isBoolean, isNumber } from 'lodash'

import {
formatMediumDateTimeWithoutParsing,
isUnparsedDateValid,
} from '../../../../utils/date'
formatDate,
normaliseToDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} from '../../../../utils/date-utils'
import { COMPANY_FIELD_NAME_TO_LABEL_MAP, HEADQUARTER_TYPES } from './constants'
import {
ARCHIVED,
Expand Down Expand Up @@ -31,17 +32,27 @@
}
}

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) => {
const date = normaliseToDate(value)

if (isBoolean(value)) {
return getValueFromBoolean(value, field)
}

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

if (date) {
return formatDate(date, DATE_FORMAT_MEDIUM_WITH_TIME)

Check warning on line 50 in src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js

View check run for this annotation

Codecov / codecov/patch

src/client/modules/Companies/CompanyBusinessDetails/CompanyEditHistory/transformers.js#L50

Added line #L50 was not covered by tests
}

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { formatMediumDateTime } from '../../../../utils/date'
import {
formatDate,
DATE_FORMAT_MEDIUM_WITH_TIME,
} from '../../../../utils/date-utils'
import { GREEN } from '../../../../utils/colours'
import urls from '../../../../../lib/urls'
import groupExportCountries from '../../../../../lib/group-export-countries'
Expand Down Expand Up @@ -48,7 +51,10 @@ function createHistory(item) {
label: 'By',
value: item.history_user?.name ?? 'unknown',
},
{ label: 'Date', value: formatMediumDateTime(item.date) },
{
label: 'Date',
value: formatDate(item.date, DATE_FORMAT_MEDIUM_WITH_TIME),
},
],
}
}
Expand Down Expand Up @@ -91,7 +97,7 @@ function createInteraction(item) {
return {
headingText: item.subject,
headingUrl: urls.interactions.detail(item.id),
subheading: `Created ${formatMediumDateTime(item.date)}`,
subheading: `Created ${formatDate(item.date, DATE_FORMAT_MEDIUM_WITH_TIME)}`,
badges: [
{
text: 'Interaction',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import CompanyExportWins from '../../../../components/Resource/CompanyExportWins
import { WIN_STATUS } from '../../../../modules/ExportWins/Status/constants'
import { createRoleTags } from '../../../ExportWins/Status/utils'
import { currencyGBP } from '../../../../utils/number-utils'
import { formatShortDate } from '../../../../utils/date'
import {
formatDate,
DATE_FORMAT_MONTH_YEAR,
} from '../../../../utils/date-utils'
import { CollectionItem } from '../../../../components'
import { BLACK } from '../../../../utils/colours'
import State from '../../../../components/State'
Expand Down Expand Up @@ -44,7 +47,9 @@ export const CompanyExportWinsList = ({ exportWins, currentAdviserId }) =>
},
{
label: 'Date won',
value: <Black>{formatShortDate(item.date)}</Black>,
value: (
<Black>{formatDate(item.date, DATE_FORMAT_MONTH_YEAR)}</Black>
),
},
{
label: 'Type of win',
Expand Down
Loading
Loading