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 103 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 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
be35e50
WIP: add tooltip
mgascam Nov 5, 2024
cfce030
Add date format notice component
mgascam Nov 27, 2024
bf30d56
Revert "WIP: add tooltip"
mgascam Nov 27, 2024
857dbf0
Fix capital dates not converted to UTC
mgascam Nov 28, 2024
18db802
Use unix utc timestamps
mgascam Nov 28, 2024
d80cf69
Convert unix utc timestamp
mgascam Nov 28, 2024
ea67199
Convert to utc and remove call to local
mgascam Nov 29, 2024
fa2808d
Use unix to handle timestamps and utc conversion
mgascam Nov 29, 2024
d59ad85
Add explicit utc conversion
mgascam Nov 29, 2024
46ef7d2
Convert unix utc timestamp
mgascam Nov 29, 2024
4cbbb52
Convert unix utc timestamp
mgascam Nov 29, 2024
4ee476b
Convert to utc
mgascam Nov 29, 2024
777f722
Introduce formatDateTimeFromString and formatDateTimeFromTimestamp
mgascam Nov 29, 2024
0a93485
Remove useGmt parameter
mgascam Dec 2, 2024
177c0dd
Remove useGmt parameter and fix tests
mgascam Dec 2, 2024
a2816d4
Merge remote-tracking branch 'origin/develop' into fix/6567-user-set-…
mgascam Dec 2, 2024
a1ba648
Fix test
mgascam Dec 2, 2024
38760c8
Enhance docs
mgascam Dec 2, 2024
281c05b
Update failing snapshot
mgascam Dec 2, 2024
f73356b
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 2, 2024
298fe08
PR feedback: Improve docs formatting
mgascam Dec 2, 2024
ff4ad70
Fix leftovers
mgascam Dec 2, 2024
6b16bef
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 3, 2024
933422e
Add timezone support
mgascam Dec 3, 2024
f6c5d62
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 3, 2024
d167e34
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 3, 2024
0086c7c
Initial implementation of notice in transactions list and overview page
mgascam Dec 4, 2024
c2b3afc
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 4, 2024
b4a95b2
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 5, 2024
4080824
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 5, 2024
ae5f6a4
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 5, 2024
707f966
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 10, 2024
1b542a3
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 13, 2024
3d46117
Revert "Initial implementation of notice in transactions list and ove…
mgascam Dec 13, 2024
31a6aac
Use BannerNotice to implement the date format change notice
mgascam Dec 13, 2024
49ae609
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 13, 2024
403e9cc
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 13, 2024
fb4fbee
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 13, 2024
3fe3a52
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 13, 2024
c16454e
Merge branch 'develop' into fix/6567-user-set-date-and-time-formattin…
mgascam Dec 16, 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
12 changes: 8 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,8 @@ import Chip from 'components/chip';
import { useLoans } from 'wcpay/data';
import { getAdminUrl } from 'wcpay/utils';
import './style.scss';
import { formatDateTimeFromString } from 'wcpay/utils/date-time';
import DateFormatNotice from 'wcpay/components/date-format-notice';

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

Expand Down Expand Up @@ -112,7 +113,9 @@ 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(
formatDateTimeFromString( loan.paid_out_at )
),
},
status: {
value: getLoanStatusText( loan ),
Expand Down Expand Up @@ -150,7 +153,7 @@ const getRowsData = ( loans: CapitalLoan[] ) =>
value: loan.first_paydown_at,
display: clickable(
loan.first_paydown_at
? dateI18n( 'M j, Y', loan.first_paydown_at )
? formatDateTimeFromString( loan.first_paydown_at )
: '-'
),
},
Expand Down Expand Up @@ -207,6 +210,7 @@ const CapitalPage = (): JSX.Element => {

return (
<Page>
<DateFormatNotice />
<TestModeNotice currentPage="loans" />

{ wcpaySettings.accountLoans.has_active_loan && (
Expand Down
48 changes: 48 additions & 0 deletions client/capital/test/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@ exports[`CapitalPage renders the TableCard component with loan data 1`] = `
<div
class=" woocommerce-payments-page"
>
<div
class="date-format-notice wcpay-banner-notice is-info"
>
<svg
aria-hidden="true"
class="wcpay-banner-notice__icon"
focusable="false"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"
/>
</svg>
<div
class="wcpay-banner-notice__content"
>
The date and time formats now match your preferences. You can update them anytime in the
<a
data-link-type="external"
href="/wp-admin/options-general.php"
>
settings
</a>
.
</div>
<button
aria-label="Dismiss this notice"
class="components-button wcpay-banner-notice__dismiss has-icon"
type="button"
>
<svg
class="gridicon gridicons-cross-small"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<g>
<path
d="M17.705 7.705l-1.41-1.41L12 10.59 7.705 6.295l-1.41 1.41L10.59 12l-4.295 4.295 1.41 1.41L12 13.41l4.295 4.295 1.41-1.41L13.41 12l4.295-4.295z"
/>
</g>
</svg>
</button>
</div>
<div
class="wcpay-banner-notice is-warning"
>
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,12 @@
* 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 { formatDateTimeFromString } from 'wcpay/utils/date-time';

const ExpirationDescription = ( {
feeData: { volume_allowance: volumeAllowance, end_time: endTime, ...rest },
Expand All @@ -26,7 +25,7 @@ const ExpirationDescription = ( {
'woocommerce-payments'
),
formatCurrency( volumeAllowance, currencyCode ),
dateI18n( 'F j, Y', moment( endTime ).toISOString() )
formatDateTimeFromString( endTime )
);
} else if ( volumeAllowance ) {
description = sprintf(
Expand All @@ -44,7 +43,7 @@ const ExpirationDescription = ( {
'Discounted base fee expires on %1$s.',
'woocommerce-payments'
),
dateI18n( 'F j, Y', moment( endTime ).toISOString() )
formatDateTimeFromString( endTime )
);
} 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: 7 additions & 13 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 { formatDateTimeFromTimestamp } from 'wcpay/utils/date-time';

const Block = ( {
title,
Expand Down Expand Up @@ -210,12 +210,8 @@ const ActiveLoanSummary = (): JSX.Element => {
'Repaid this period (until %s)',
'woocommerce-payments'
),
dateI18n(
'M j, Y',
new Date(
details.current_repayment_interval.due_at *
1000
)
formatDateTimeFromTimestamp(
details.current_repayment_interval.due_at
)
) }
>
Expand Down Expand Up @@ -251,9 +247,8 @@ const ActiveLoanSummary = (): JSX.Element => {
<Block
title={ __( 'Loan disbursed', 'woocommerce-payments' ) }
>
{ dateI18n(
'M j, Y',
new Date( details.advance_paid_out_at * 1000 )
{ formatDateTimeFromTimestamp(
details.advance_paid_out_at
) }
</Block>
<Block
Expand All @@ -278,9 +273,8 @@ const ActiveLoanSummary = (): JSX.Element => {
<Block
title={ __( 'First paydown', 'woocommerce-payments' ) }
>
{ dateI18n(
'M j, Y',
new Date( details.repayments_begin_at * 1000 )
{ formatDateTimeFromTimestamp(
details.repayments_begin_at
) }
</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
10 changes: 10 additions & 0 deletions client/components/active-loan-summary/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ jest.mock( 'wcpay/data', () => ( {
useActiveLoanSummary: jest.fn(),
} ) );

// Mock dateI18n
jest.mock( '@wordpress/date', () => ( {
dateI18n: jest.fn( ( format, date ) => {
return jest
.requireActual( '@wordpress/date' )
.dateI18n( format, date, 'UTC' ); // Ensure UTC is used
} ),
} ) );

describe( 'Active loan summary', () => {
beforeEach( () => {
global.wcpaySettings = {
Expand All @@ -34,6 +43,7 @@ describe( 'Active loan summary', () => {
precision: 2,
},
},
dateFormat: 'M j, Y',
};
} );
afterEach( () => {
Expand Down
64 changes: 64 additions & 0 deletions client/components/date-format-notice/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* External dependencies
*/
import React, { useState } from 'react';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import BannerNotice from 'components/banner-notice';
import interpolateComponents from '@automattic/interpolate-components';
import { Link } from '@woocommerce/components';
import './style.scss';

// eslint-disable-next-line @typescript-eslint/naming-convention
const STORAGE_KEY = 'woopayments_date_format_notice_dismissed';

const DateFormatNotice: React.FC = () => {
const [ isBannerVisible, setIsBannerVisible ] = useState( () => {
// Initialize state from localStorage
return localStorage.getItem( STORAGE_KEY ) !== 'true';
} );

const handleDismiss = () => {
setIsBannerVisible( false );
localStorage.setItem( STORAGE_KEY, 'true' );
};

const handleSettingsClick = () => {
handleDismiss();
};

if ( ! isBannerVisible ) {
return null;
}

return (
<BannerNotice
status="info"
icon={ true }
isDismissible={ true }
onRemove={ handleDismiss }
className="date-format-notice"
>
{ interpolateComponents( {
components: {
settingsLink: (
<Link
href={ '/wp-admin/options-general.php' }
onClick={ handleSettingsClick }
type="external"
/>
),
},
mixedString: __(
'The date and time formats now match your preferences. You can update them anytime in the {{settingsLink}}settings{{/settingsLink}}.',
'woocommerce-payments'
),
} ) }
</BannerNotice>
);
};

export default DateFormatNotice;
5 changes: 5 additions & 0 deletions client/components/date-format-notice/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.date-format-notice {
.wcpay-banner-notice__content {
align-self: center; // Align the content to the center of the notice and the icon.
}
}
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 @@ -240,6 +241,7 @@ describe( 'Deposits Overview information', () => {
precision: 2,
},
},
dateFormat: 'F j, Y',
};
mockUseDepositIncludesLoan.mockReturnValue( {
includesFinancingPayout: false,
Expand Down
12 changes: 7 additions & 5 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 { formatDateTimeFromString } from 'wcpay/utils/date-time';

const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
const { data: charge } = useCharge( chargeId );
Expand Down Expand Up @@ -84,8 +84,10 @@ const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
return null;
}

const now = moment();
const dueBy = moment.unix( dispute.evidence_details?.due_by );
// Get current time in UTC for consistent timezone-independent comparison
const now = moment().utc();
// Parse the Unix timestamp as UTC since it's stored that way in the API
const dueBy = moment.unix( dispute.evidence_details?.due_by ).utc();

// If the dispute is due in the past, don't show notice.
if ( ! now.isBefore( dueBy ) ) {
Expand Down Expand Up @@ -131,7 +133,7 @@ const UrgentDisputeNoticeBody = ( {
formatString,
formattedAmount,
reasons[ disputeReason ].display,
dateI18n( 'M j, Y', dueBy.local().toISOString() )
formatDateTimeFromString( dueBy.toISOString() )
);

let suffix = sprintf(
Expand Down Expand Up @@ -182,7 +184,7 @@ 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() )
formatDateTimeFromString( dueBy.toISOString() )
);

return (
Expand Down
Loading
Loading