Skip to content

Commit

Permalink
Remove format function and replace with formatDate
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgain committed Dec 16, 2024
1 parent 79df8cb commit 0d1f14f
Show file tree
Hide file tree
Showing 54 changed files with 294 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import Task from '../../../../../../client/components/Task'

import { REFERRAL_DETAILS } from '../../../../../../client/actions'

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

export const AdviserDetails = ({ name, email, team }) => (
<>
Expand Down Expand Up @@ -87,14 +90,14 @@ export default connect(({ referrerUrl, ...state }) => ({
{receivingAdviser && <AdviserDetails {...receivingAdviser} />}
</SummaryTable.Row>
<SummaryTable.Row heading="Date of referral">
{format(date)}
{formatDate(date, DATE_FORMAT_COMPACT)}
</SummaryTable.Row>
<SummaryTable.Row heading="Notes">{notes}</SummaryTable.Row>
</SummaryTable>
{completed ? (
<SummaryTable caption="Referral accepted">
<SummaryTable.Row heading="Date">
{format(completed.on)}
{formatDate(completed.on, DATE_FORMAT_COMPACT)}
</SummaryTable.Row>
<SummaryTable.Row heading="By">
<AdviserDetails {...completed.by} />
Expand Down
7 changes: 5 additions & 2 deletions src/apps/interactions/client/transformers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { get } from 'lodash'

import { format } from '../../../client/utils/date'
import {
formatDate,
DATE_FORMAT_DAY_MONTH_YEAR,
} from '../../../client/utils/date-utils'
import urls from '../../../lib/urls'
import { LABELS } from './constants'

Expand Down Expand Up @@ -52,7 +55,7 @@ export const transformInteractionToListItem = ({
} = {}) => ({
id,
metadata: [
{ label: 'Date', value: format(date, 'dd MMMM yyyy') },
{ label: 'Date', value: formatDate(date, DATE_FORMAT_DAY_MONTH_YEAR) },
{
label: 'Contact(s)',
value: contacts && formatContacts(contacts),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'
import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper'

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

export default class CompaniesHouseAccount extends React.PureComponent {
static propTypes = {
Expand All @@ -32,21 +32,28 @@ export default class CompaniesHouseAccount extends React.PureComponent {
const { activity, isOverview } = this.props
const startTime = get(activity, 'object.startTime')
const summary = get(activity, 'summary')
const balanceSheetDate = format(
get(activity, 'object.dit:balanceSheetDate')
const balanceSheetDate = formatDate(
get(activity, 'object.dit:balanceSheetDate'),
DATE_FORMAT_COMPACT
)
const netAssetsLiabilities = currencyGBP(
get(
activity,
'object.dit:netAssetsLiabilitiesIncludingPensionAssetLiability'
)
)
const periodEnd = format(get(activity, 'object.dit:periodEnd'))
const periodStart = format(get(activity, 'object.dit:periodStart'))
const periodEnd = formatDate(
get(activity, 'object.dit:periodEnd'),
DATE_FORMAT_COMPACT
)
const periodStart = formatDate(
get(activity, 'object.dit:periodStart'),
DATE_FORMAT_COMPACT
)
const shareholderFunds = currencyGBP(
get(activity, 'object.dit:shareholderFunds')
)
const date = format(startTime)
const date = formatDate(startTime, DATE_FORMAT_COMPACT)
const metadata = [
{ label: 'Date', value: date },
{ label: 'Balance sheet date', value: balanceSheetDate },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'
import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper'

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

export default class CompaniesHouseCompany extends React.PureComponent {
static propTypes = {
Expand All @@ -35,21 +35,27 @@ export default class CompaniesHouseCompany extends React.PureComponent {
const subject = get(activity, 'summary')
const address = get(activity, 'object.location:dit:address')
const postcode = get(activity, 'object.location:dit:postcode')
const confStmtLastMadeUpDate = format(
const confStmtLastMadeUpDate = formatDate(
get(activity, 'object.dit:confStmtLastMadeUpDate')
)
const confStmtNextDueDate = format(
get(activity, 'object.dit:confStmtNextDueDate')
const confStmtNextDueDate = formatDate(
get(activity, 'object.dit:confStmtNextDueDate'),
DATE_FORMAT_COMPACT
)
const incorporationDate = format(
const incorporationDate = formatDate(
get(activity, 'object.dit:incorporationDate')
)
const nextDueDate = format(get(activity, 'object.dit:nextDueDate'))
const returnsLastMadeUpDate = format(
get(activity, 'object.dit:returnsLastMadeUpDate')
const nextDueDate = formatDate(
get(activity, 'object.dit:nextDueDate'),
DATE_FORMAT_COMPACT
)
const returnsNextDueDate = format(
get(activity, 'object.dit:returnsNextDueDate')
const returnsLastMadeUpDate = formatDate(
get(activity, 'object.dit:returnsLastMadeUpDate'),
DATE_FORMAT_COMPACT
)
const returnsNextDueDate = formatDate(
get(activity, 'object.dit:returnsNextDueDate'),
DATE_FORMAT_COMPACT
)
const sicCodes = get(activity, 'object.dit:sicCodes')

Expand All @@ -60,7 +66,7 @@ export default class CompaniesHouseCompany extends React.PureComponent {
</span>
))

const date = format(startTime)
const date = formatDate(startTime, DATE_FORMAT_COMPACT)

const metadata = [
{ label: 'Date', value: date },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ActivityCardNotes from './card/ActivityCardNotes'
import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'

import { format } from '../../../utils/date'
import { formatDate, DATE_FORMAT_COMPACT } from '../../../utils/date-utils'
import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper'

export default class DirectoryFormsApi extends React.PureComponent {
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class DirectoryFormsApi extends React.PureComponent {
)
)
const metadata = [
{ label: 'Date', value: format(sentDate) },
{ label: 'Date', value: formatDate(sentDate, DATE_FORMAT_COMPACT) },
{
label: 'Contact(s)',
value: formattedContacts(),
Expand All @@ -84,7 +84,7 @@ export default class DirectoryFormsApi extends React.PureComponent {
<OverviewActivityCardWrapper dataTest="export-support-service-summary">
<ActivityOverviewSummary
activity={activity}
date={format(sentDate)}
date={formatDate(sentDate, DATE_FORMAT_COMPACT)}
kind={kind}
url={url}
subject={subject}
Expand All @@ -107,7 +107,7 @@ export default class DirectoryFormsApi extends React.PureComponent {
} else {
kind = 'great.gov.uk Enquiry'
const metadata = [
{ label: 'Date', value: format(sentDate) },
{ label: 'Date', value: formatDate(sentDate, DATE_FORMAT_COMPACT) },
{
label: 'Name',
value: `${formData.first_name} ${formData.last_name}`,
Expand All @@ -119,7 +119,7 @@ export default class DirectoryFormsApi extends React.PureComponent {
<ActivityOverviewSummary
dataTest="export-support-service-great-summary"
activity={activity}
date={format(sentDate)}
date={formatDate(sentDate, DATE_FORMAT_COMPACT)}
kind={kind}
subject="Enquiry"
summary={`Enquirer ${formData.first_name} ${formData.last_name}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'
import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper'

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

export default class HmrcExporter extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class HmrcExporter extends React.PureComponent {
</span>
)
)
const date = format(startTime)
const date = formatDate(startTime, DATE_FORMAT_COMPACT)
const metadata = [
{ label: 'Date', value: date },
{ label: 'Export item code(s)', value: exportItemCodesList },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ActivityCardLabels from './card/ActivityCardLabels'
import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityCardMetadata from './card/ActivityCardMetadata'

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

export default class MaxemailCampaign extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class MaxemailCampaign extends React.PureComponent {
))

const metadata = [
{ label: 'Date', value: format(published) },
{ label: 'Date', value: formatDate(published, DATE_FORMAT_COMPACT) },
{ label: 'Senders name', value: name },
{ label: 'Senders email', value: from },
{ label: 'Content', value: content },
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/ActivityFeed/activities/Omis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityOverviewSummary from './card/item-renderers/ActivityOverviewSummary'
import OverviewActivityCardWrapper from './card/OverviewActivityCardWrapper'

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

export default class Omis extends React.PureComponent {
static propTypes = {
Expand All @@ -36,7 +36,7 @@ export default class Omis extends React.PureComponent {
const url = get(activity, 'object.url')
const adviser = CardUtils.getAdviser(activity)
const contacts = CardUtils.getContacts(activity)
const date = format(published)
const date = formatDate(published, DATE_FORMAT_COMPACT)

const metadata = [
{ label: 'Date', value: date },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { BLUE, GREY_1, GREY_4 } from '../../../../utils/colours'
import Badge from '../../../Badge'
import { SOURCE_TYPES } from '../../constants'

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

const StyledBlockText = styled(H3)`
display: inline-block;
Expand Down Expand Up @@ -118,7 +121,9 @@ const CardHeader = ({
</StyledHeadingWrapper>

<StyledMetaItems>
{startTime && <ListItem>{format(startTime)}</ListItem>}
{startTime && (
<ListItem>{formatDate(startTime, DATE_FORMAT_COMPACT)}</ListItem>
)}

{badge && (
<ListItem>
Expand Down
9 changes: 5 additions & 4 deletions src/client/components/ArchivePanel/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SPACING, FONT_SIZE, FONT_WEIGHTS } from '@govuk-react/constants'
import Link from '@govuk-react/link'

import StatusMessage from '../../../client/components/StatusMessage'
import { format } from '../../utils/date'
import { formatDate, DATE_FORMAT_COMPACT } from '../../utils/date-utils'

const negativeSpacing = '-' + SPACING.SCALE_4

Expand Down Expand Up @@ -48,10 +48,11 @@ const ArchivePanel = ({
<StatusMessage>
<StyledMessage data-test="archive-message">
{archivedBy
? `This ${type} was ${archiveMessage} on ${format(
archivedOn
? `This ${type} was ${archiveMessage} on ${formatDate(
archivedOn,
DATE_FORMAT_COMPACT
)} by ${checkArchiverFormat(archivedBy)}.`
: `This ${type} was automatically archived on ${format(archivedOn)}.`}
: `This ${type} was automatically archived on ${formatDate(archivedOn, DATE_FORMAT_COMPACT)}.`}
</StyledMessage>
<StyledReason data-test="archive-reason">{`Reason: ${archiveReason}`}</StyledReason>
{unarchiveUrl && (
Expand Down
6 changes: 4 additions & 2 deletions src/client/components/CompanyLists/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import urls from '../../../lib/urls'
import { MEDIA_QUERIES } from '../../utils/responsive'
import SecondaryButton from '../SecondaryButton'

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

const StyledButtonLink = styled.a({
marginBottom: 0,
Expand Down Expand Up @@ -159,7 +159,9 @@ const CompaniesTable = ({ companies }) => (
/>
</StyledLink>
</TitleCell>
<ColumnLabelCell>{date ? format(date) : '-'}</ColumnLabelCell>
<ColumnLabelCell>
{date ? formatDate(date, DATE_FORMAT_COMPACT) : '-'}
</ColumnLabelCell>
<StyledTableCell>
{interactionId ? (
<StyledLink href={urls.interactions.detail(interactionId)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SPACING, FONT_SIZE, FONT_WEIGHTS } from '@govuk-react/constants'
import { companies, interactions } from '../../../lib/urls'
import { GREY_3, DARK_GREY } from '../../utils/colours'

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

const StyledDiv = styled('div')({
height: '100%',
Expand Down Expand Up @@ -75,7 +75,9 @@ const InvestmentDetails = ({
{latestInteraction && (
<>
<StyledDT>Last interaction:</StyledDT>
<StyledDD>{format(latestInteraction.date)}</StyledDD>
<StyledDD>
{formatDate(latestInteraction.date, DATE_FORMAT_COMPACT)}
</StyledDD>
<StyledDT>Interaction subject:</StyledDT>
<StyledDD>
<Link href={interactions.detail(latestInteraction.id)}>
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/ReferralList/Referral.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AdviserDetails } from '../../../apps/companies/apps/referrals/details/c
import { Card, CardHeader } from '../ActivityFeed/activities/card'
import SummaryList from '../../components/SummaryList'
import urls from '../../../lib/urls'
import { format } from '../../utils/date'
import { formatDate, DATE_FORMAT_COMPACT } from '../../utils/date-utils'

const StyledSummaryListWrapper = styled.div({
flexGrow: 1,
Expand Down Expand Up @@ -75,7 +75,7 @@ const Referral = ({
? [
{
label: 'Accepted on',
value: format(dateAccepted),
value: formatDate(dateAccepted, DATE_FORMAT_COMPACT),
},
]
: []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../../components/Resource'
import { buildCompanyBreadcrumbs } from '../utils'
import { DARK_GREY, GREY_2 } from '../../../utils/colours'
import { format } from '../../../utils/date'
import { formatDate, DATE_FORMAT_COMPACT } from '../../../utils/date-utils'
import urls from '../../../../lib/urls'

const BorderContainer = styled('div')`
Expand Down Expand Up @@ -42,7 +42,7 @@ const objectiveMetadata = (objective) => {
},
{
label: 'Due date',
value: format(objective.targetDate),
value: formatDate(objective.targetDate, DATE_FORMAT_COMPACT),
},
{
label: 'Progress',
Expand Down Expand Up @@ -102,13 +102,13 @@ const ArchivedObjectives = () => {
<LastUpdatedHeading data-test="last-updated-details">
<span>{`Objective complete. Updated by ${
objective?.modifiedBy?.name
}: ${format(objective.modifiedOn)}`}</span>
}: ${formatDate(objective.modifiedOn, DATE_FORMAT_COMPACT)}`}</span>
</LastUpdatedHeading>
) : (
<LastUpdatedHeading data-test="last-updated-details">
<span>{`Objective incomplete. Archived by ${
objective?.modifiedBy?.name
}: ${format(objective.modifiedOn)}`}</span>
}: ${formatDate(objective.modifiedOn, DATE_FORMAT_COMPACT)}`}</span>
</LastUpdatedHeading>
)}
</GridCol>
Expand Down
Loading

0 comments on commit 0d1f14f

Please sign in to comment.