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

Apply User-Defined Date Formatting Settings to WP Admin React Components #9635

Open
wants to merge 63 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e463fdd
Include date and time format options in the wcpaySettings object
mgascam Oct 24, 2024
305a339
Add utility function to format time
mgascam Oct 24, 2024
16479fb
Refactor transactions list
mgascam Oct 24, 2024
92eb3b0
Refactor deposits list
mgascam Oct 24, 2024
65f0534
Refactor deposits details
mgascam Oct 24, 2024
44786e3
Refactor deposits overview
mgascam Oct 24, 2024
3ec71d3
Refactor disputes
mgascam Oct 24, 2024
80a05ef
Refactor disputes test
mgascam Oct 25, 2024
4bbea05
Refactor documents list
mgascam Oct 25, 2024
9f74ccc
Refactor single currency settings
mgascam Oct 25, 2024
91e62cd
Fix error with custom format
mgascam Oct 25, 2024
e23a980
Refactor custom format
mgascam Oct 25, 2024
dca862c
Refactor update business details modal
mgascam Oct 25, 2024
172b39c
Refactor task list of overview page
mgascam Oct 25, 2024
619282e
Refactor payment details summary
mgascam Oct 25, 2024
47406f3
Refactor dispute details in payment details
mgascam Oct 25, 2024
1816897
Refactor dispute resolution in payment details
mgascam Oct 25, 2024
6e12e7a
Refactor dispute steps in payment details
mgascam Oct 25, 2024
d24dcef
Refactor dispute summary row in dispute details
mgascam Oct 25, 2024
4dbca9c
Refactor dispute details
mgascam Oct 25, 2024
792ad58
Refactor payment details timeline
mgascam Oct 25, 2024
3f825a1
Refactor blocked transactions
mgascam Oct 25, 2024
72f15df
Refactor transactions risk review
mgascam Oct 25, 2024
31e7946
Refactor uncaptured transactions
mgascam Oct 25, 2024
4b969ff
Refactor account fees
mgascam Oct 25, 2024
88a43fb
Remove unused dependency
mgascam Oct 25, 2024
62c1396
Refactor deposits list
mgascam Oct 26, 2024
5633382
Remove unused dependency
mgascam Oct 26, 2024
58c0860
Remove unused dependencies
mgascam Oct 28, 2024
a4a53b7
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 28, 2024
dc77273
Merge remote-tracking branch 'origin/develop' into fix/6567-user-set-…
mgascam Oct 28, 2024
114a85d
Merge remote-tracking branch 'origin/develop' into fix/6567-user-set-…
mgascam Oct 28, 2024
365a4cf
Refactor capital loan page
mgascam Oct 28, 2024
b5aef87
Remove unused dependencies
mgascam Oct 28, 2024
284592d
Refactor disputes
mgascam Oct 28, 2024
906f088
Add unit test for disputed order notice
mgascam Oct 28, 2024
b257e24
Add changelog
mgascam Oct 28, 2024
a0ca76f
Merge branch 'develop' into dev/add-unit-tests-for-diputed-order-notice
mgascam Oct 29, 2024
b357e63
Merge branch 'dev/add-unit-tests-for-diputed-order-notice' into fix/6…
mgascam Oct 29, 2024
959c3d7
Refactor disputed order notice
mgascam Oct 29, 2024
99fa577
Add unit tests
mgascam Oct 29, 2024
4eae670
Refactor function name
mgascam Oct 29, 2024
58af60b
Tweak comments
mgascam Oct 29, 2024
b716201
Refactor tests
mgascam Oct 29, 2024
a6487e7
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 29, 2024
efe28cf
Refactor to default to local time (useGmt: false)
mgascam Oct 29, 2024
655e814
Remove default option from function call
mgascam Oct 29, 2024
280c820
Add changelog
mgascam Oct 29, 2024
25bf46b
Delete file
mgascam Oct 29, 2024
3334417
Revert multi-currency changes
mgascam Oct 29, 2024
f2479bd
Remove redundant comments
mgascam Oct 29, 2024
3664b73
Fix payment details summary not respecting user settings
mgascam Oct 29, 2024
98955f0
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 30, 2024
129994f
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 30, 2024
70b3c92
PR feedback: exclude time by default
mgascam Oct 30, 2024
00a66e3
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 30, 2024
66b15d7
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Oct 31, 2024
368e80e
Add test case for escaping characters with custom format
mgascam Oct 31, 2024
666473d
Add test case for output unrecognized characters as-is
mgascam Oct 31, 2024
28f8408
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Nov 4, 2024
6ee2e25
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
deepakpathania Nov 4, 2024
5a58342
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Nov 4, 2024
9340ea0
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Nov 5, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Apply User-Defined Date Formatting Settings to WP Admin React Components
14 changes: 10 additions & 4 deletions client/capital/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as React from 'react';
import { __, _n } from '@wordpress/i18n';
import { TableCard } from '@woocommerce/components';
import { dateI18n } from '@wordpress/date';

/**
* Internal dependencies.
Expand All @@ -25,6 +24,7 @@ import Chip from 'components/chip';
import { useLoans } from 'wcpay/data';
import { getAdminUrl } from 'wcpay/utils';
import './style.scss';
import { formatUserDateTime } from 'wcpay/utils/date-time';

const columns = [
{
Expand Down Expand Up @@ -80,7 +80,7 @@ const getLoanStatusText = ( loan: CapitalLoan ) => {
return loan.fully_paid_at
? __( 'Paid off', 'woocommerce-payments' ) +
': ' +
dateI18n( 'M j, Y', loan.fully_paid_at )
formatUserDateTime( loan.fully_paid_at, { includeTime: false } )
: __( 'Active', 'woocommerce-payments' );
};

Expand Down Expand Up @@ -112,7 +112,11 @@ const getRowsData = ( loans: CapitalLoan[] ) =>
const data = {
paid_out_at: {
value: loan.paid_out_at,
display: clickable( dateI18n( 'M j, Y', loan.paid_out_at ) ),
display: clickable(
formatUserDateTime( loan.paid_out_at, {
includeTime: false,
} )
),
},
status: {
value: getLoanStatusText( loan ),
Expand Down Expand Up @@ -150,7 +154,9 @@ const getRowsData = ( loans: CapitalLoan[] ) =>
value: loan.first_paydown_at,
display: clickable(
loan.first_paydown_at
? dateI18n( 'M j, Y', loan.first_paydown_at )
? formatUserDateTime( loan.first_paydown_at, {
includeTime: false,
} )
: '-'
),
},
Expand Down
2 changes: 2 additions & 0 deletions client/capital/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare const global: {
accountLoans: {
has_active_loan: boolean;
};
dateFormat: string;
};
};

Expand All @@ -37,6 +38,7 @@ describe( 'CapitalPage', () => {
},
accountLoans: { has_active_loan: true },
testMode: true,
dateFormat: 'M j, Y',
};
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { dateI18n } from '@wordpress/date';
import moment from 'moment';

/**
* Internal dependencies
*/
import { formatCurrency } from 'multi-currency/interface/functions';
import { formatUserDateTime } from 'wcpay/utils/date-time';

const ExpirationDescription = ( {
feeData: { volume_allowance: volumeAllowance, end_time: endTime, ...rest },
Expand All @@ -26,7 +26,9 @@ const ExpirationDescription = ( {
'woocommerce-payments'
),
formatCurrency( volumeAllowance, currencyCode ),
dateI18n( 'F j, Y', moment( endTime ).toISOString() )
formatUserDateTime( moment( endTime ).toISOString(), {
includeTime: false,
} )
);
} else if ( volumeAllowance ) {
description = sprintf(
Expand All @@ -44,7 +46,9 @@ const ExpirationDescription = ( {
'Discounted base fee expires on %1$s.',
'woocommerce-payments'
),
dateI18n( 'F j, Y', moment( endTime ).toISOString() )
formatUserDateTime( moment( endTime ).toISOString(), {
includeTime: false,
} )
);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe( 'AccountFees', () => {
precision: 2,
},
},
dateFormat: 'F j, Y',
};
} );

Expand Down
20 changes: 10 additions & 10 deletions client/components/active-loan-summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { dateI18n } from '@wordpress/date';

/**
* Internal dependencies.
Expand All @@ -24,6 +23,7 @@ import { useActiveLoanSummary } from 'wcpay/data';
import { getAdminUrl } from 'wcpay/utils';

import './style.scss';
import { formatUserDateTime } from 'wcpay/utils/date-time';

const Block = ( {
title,
Expand Down Expand Up @@ -210,12 +210,12 @@ const ActiveLoanSummary = (): JSX.Element => {
'Repaid this period (until %s)',
'woocommerce-payments'
),
dateI18n(
'M j, Y',
formatUserDateTime(
new Date(
details.current_repayment_interval.due_at *
1000
)
),
{ includeTime: false, useGmt: true }
)
) }
>
Expand Down Expand Up @@ -251,9 +251,9 @@ const ActiveLoanSummary = (): JSX.Element => {
<Block
title={ __( 'Loan disbursed', 'woocommerce-payments' ) }
>
{ dateI18n(
'M j, Y',
new Date( details.advance_paid_out_at * 1000 )
{ formatUserDateTime(
new Date( details.advance_paid_out_at * 1000 ),
{ includeTime: false, useGmt: true }
) }
</Block>
<Block
Expand All @@ -278,9 +278,9 @@ const ActiveLoanSummary = (): JSX.Element => {
<Block
title={ __( 'First paydown', 'woocommerce-payments' ) }
>
{ dateI18n(
'M j, Y',
new Date( details.repayments_begin_at * 1000 )
{ formatUserDateTime(
new Date( details.repayments_begin_at * 1000 ),
{ includeTime: false, useGmt: true }
) }
</Block>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ exports[`Active loan summary renders correctly 1`] = `
<div
class="wcpay-loan-summary-block__title"
>
Repaid this period (until Feb 14, 2022)
Repaid this period (until Feb 15, 2022)
</div>
<div
class="wcpay-loan-summary-block__value"
Expand Down
1 change: 1 addition & 0 deletions client/components/active-loan-summary/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe( 'Active loan summary', () => {
precision: 2,
},
},
dateFormat: 'M j, Y',
};
} );
afterEach( () => {
Expand Down
2 changes: 2 additions & 0 deletions client/components/deposits-overview/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ declare const global: {
connect: {
country: string;
};
dateFormat: string;
};
};

Expand Down Expand Up @@ -231,6 +232,7 @@ describe( 'Deposits Overview information', () => {
precision: 2,
},
},
dateFormat: 'F j, Y',
};
mockUseDepositIncludesLoan.mockReturnValue( {
includesFinancingPayout: false,
Expand Down
10 changes: 7 additions & 3 deletions client/components/disputed-order-notice/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import moment from 'moment';
import React, { useEffect } from 'react';
import { __, _n, sprintf } from '@wordpress/i18n';
import { dateI18n } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';

/**
Expand All @@ -20,6 +19,7 @@ import {
import { useCharge } from 'wcpay/data';
import { recordEvent } from 'tracks';
import './style.scss';
import { formatUserDateTime } from 'wcpay/utils/date-time';

const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
const { data: charge } = useCharge( chargeId );
Expand Down Expand Up @@ -131,7 +131,9 @@ const UrgentDisputeNoticeBody = ( {
formatString,
formattedAmount,
reasons[ disputeReason ].display,
dateI18n( 'M j, Y', dueBy.local().toISOString() )
formatUserDateTime( dueBy.local().toISOString(), {
includeTime: false,
} )
);

let suffix = sprintf(
Expand Down Expand Up @@ -182,7 +184,9 @@ const RegularDisputeNoticeBody = ( {
const suffix = sprintf(
// Translators: %1$s is the dispute due date.
__( 'Please respond before %1$s.', 'woocommerce-payments' ),
dateI18n( 'M j, Y', dueBy.local().toISOString() )
formatUserDateTime( dueBy.local().toISOString(), {
includeTime: false,
} )
);

return (
Expand Down
1 change: 1 addition & 0 deletions client/components/disputed-order-notice/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe( 'DisputedOrderNoticeHandler', () => {
connect: {
country: 'US',
},
dateFormat: 'M j, Y',
};
useCharge.mockReturnValue( { data: mockCharge } );
} );
Expand Down
11 changes: 5 additions & 6 deletions client/deposits/details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* External dependencies
*/
import React from 'react';
import { dateI18n } from '@wordpress/date';
import { __, sprintf } from '@wordpress/i18n';
import moment from 'moment';
import {
Expand Down Expand Up @@ -40,6 +39,7 @@ import {
} from 'multi-currency/interface/functions';
import { displayStatus } from '../strings';
import './style.scss';
import { formatUserDateTime } from 'wcpay/utils/date-time';

/**
* Renders the deposit status indicator UI, re-purposing the OrderStatus component from @woocommerce/components.
Expand Down Expand Up @@ -111,11 +111,10 @@ export const DepositOverview: React.FC< DepositOverviewProps > = ( {
key="depositDate"
label={
`${ depositDateLabel }: ` +
dateI18n(
'M j, Y',
moment.utc( deposit.date ).toISOString(),
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
)
formatUserDateTime( moment.utc( deposit.date ).toISOString(), {
useGmt: true,
includeTime: false,
} )
}
value={ <Status status={ deposit.status } /> }
detail={ deposit.bankAccount }
Expand Down
2 changes: 2 additions & 0 deletions client/deposits/details/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare const global: {
connect: {
country: string;
};
dateFormat: string;
};
wcSettings: { countries: Record< string, string > };
};
Expand All @@ -54,6 +55,7 @@ describe( 'Deposit overview', () => {
precision: 2,
},
},
dateFormat: 'M j, Y',
};
} );

Expand Down
15 changes: 8 additions & 7 deletions client/deposits/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DepositsTableHeader } from 'wcpay/types/deposits';
import React, { useState } from 'react';
import { recordEvent } from 'tracks';
import { useMemo } from '@wordpress/element';
import { dateI18n } from '@wordpress/date';
import { __, _n, sprintf } from '@wordpress/i18n';
import moment from 'moment';
import { TableCard, Link } from '@woocommerce/components';
Expand Down Expand Up @@ -48,6 +47,7 @@ import { ReportingExportLanguageHook } from 'wcpay/settings/reporting-settings/i

import './style.scss';
import { parseInt } from 'lodash';
import { formatUserDateTime } from 'wcpay/utils/date-time';

const getColumns = ( sortByDate?: boolean ): DepositsTableHeader[] => [
{
Expand Down Expand Up @@ -135,10 +135,12 @@ export const DepositsList = (): JSX.Element => {
href={ getDetailsURL( deposit.id, 'deposits' ) }
onClick={ () => recordEvent( 'wcpay_deposits_row_click' ) }
>
{ dateI18n(
'M j, Y',
{ formatUserDateTime(
moment.utc( deposit.date ).toISOString(),
true // TODO Change call to gmdateI18n and remove this deprecated param once WP 5.4 support ends.
{
includeTime: false,
useGmt: true,
}
) }
</Link>
);
Expand Down Expand Up @@ -328,10 +330,9 @@ export const DepositsList = (): JSX.Element => {
row[ 0 ],
{
...row[ 1 ],
value: dateI18n(
'Y-m-d',
value: formatUserDateTime(
moment.utc( row[ 1 ].value ).toISOString(),
true
{ useGmt: true, includeTime: false }
),
},
...row.slice( 2 ),
Expand Down
8 changes: 4 additions & 4 deletions client/deposits/list/test/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ exports[`Deposits list renders correctly a single deposit 1`] = `
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdeposits%2Fdetails&id=po_mock1"
>
Jan 2, 2020
Jan 2 2020
</a>
</td>
<td
Expand Down Expand Up @@ -432,7 +432,7 @@ exports[`Deposits list renders correctly a single deposit 1`] = `
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdeposits%2Fdetails&id=po_mock2"
>
Jan 3, 2020
Jan 3 2020
</a>
</td>
<td
Expand Down Expand Up @@ -894,7 +894,7 @@ exports[`Deposits list renders correctly with multiple currencies 1`] = `
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdeposits%2Fdetails&id=po_mock1"
>
Jan 2, 2020
Jan 2 2020
</a>
</td>
<td
Expand Down Expand Up @@ -981,7 +981,7 @@ exports[`Deposits list renders correctly with multiple currencies 1`] = `
data-link-type="wc-admin"
href="admin.php?page=wc-admin&path=%2Fpayments%2Fdeposits%2Fdetails&id=po_mock2"
>
Jan 3, 2020
Jan 3 2020
</a>
</td>
<td
Expand Down
Loading
Loading