From aac2f270fa282260326e5dc0677c80fed23353b3 Mon Sep 17 00:00:00 2001 From: Jessy Pappachan <32092402+jessy-p@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:11:27 +0530 Subject: [PATCH] Save selected date preset into session (#8983) Co-authored-by: Jessy Co-authored-by: Rua Haszard --- .../update-8972-save-payment-activity-preset-session | 5 +++++ client/components/payment-activity/hooks.ts | 8 +++++--- client/components/payment-activity/index.tsx | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelog/update-8972-save-payment-activity-preset-session diff --git a/changelog/update-8972-save-payment-activity-preset-session b/changelog/update-8972-save-payment-activity-preset-session new file mode 100644 index 00000000000..869e0b298e5 --- /dev/null +++ b/changelog/update-8972-save-payment-activity-preset-session @@ -0,0 +1,5 @@ +Significance: patch +Type: update +Comment: Part of Payment Activity Card. Persist selected preset date in session. + + diff --git a/client/components/payment-activity/hooks.ts b/client/components/payment-activity/hooks.ts index 2f5d04da975..967ca6cf73a 100644 --- a/client/components/payment-activity/hooks.ts +++ b/client/components/payment-activity/hooks.ts @@ -108,12 +108,14 @@ export const usePaymentActivityDateRangePresets = (): { }, }; + const defaultPreset = + sessionStorage.getItem( 'selectedPresetName' ) ?? 'last_7_days'; const defaultDateRange = { - preset_name: 'last_7_days', - date_start: dateRangePresets.last_7_days.start.format( + preset_name: defaultPreset, + date_start: dateRangePresets[ defaultPreset ].start.format( 'YYYY-MM-DD\\THH:mm:ss' ), - date_end: dateRangePresets.last_7_days.end.format( + date_end: dateRangePresets[ defaultPreset ].end.format( 'YYYY-MM-DD\\THH:mm:ss' ), }; diff --git a/client/components/payment-activity/index.tsx b/client/components/payment-activity/index.tsx index 2e1f8fe2196..4649497cfdf 100644 --- a/client/components/payment-activity/index.tsx +++ b/client/components/payment-activity/index.tsx @@ -130,6 +130,10 @@ const PaymentActivity: React.FC = () => { .clone() .format( 'YYYY-MM-DD\\THH:mm:ss' ); const { key: presetName } = selectedItem; + sessionStorage.setItem( + 'selectedPresetName', + selectedItem.key + ); recordEvent( 'wcpay_overview_payment_activity_period_change', {