From 23e889f84fa64b819acc02fa17d6a897c5753719 Mon Sep 17 00:00:00 2001 From: alaca Date: Mon, 31 Jul 2023 15:56:52 +0200 Subject: [PATCH] feature: use toast component --- .../components/DonationFormsListTable.tsx | 27 +++++++++++++++---- .../components/DonationFormsRowActions.tsx | 14 +++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx index ee0f1af8b2..d2f2660dec 100644 --- a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx +++ b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx @@ -1,5 +1,5 @@ import {createContext, useState, useCallback} from 'react'; -import {__} from '@wordpress/i18n'; +import {__, sprintf} from '@wordpress/i18n'; import {ListTableApi, ListTablePage} from '@givewp/components'; import {DonationFormsRowActions} from './DonationFormsRowActions'; import MigrationBanner from './Migration'; @@ -10,6 +10,7 @@ import {BulkActionsConfig, FilterConfig} from '@givewp/components/ListTable/List import Select from '@givewp/components/ListTable/Select'; import {Interweave} from 'interweave'; import BlankSlate from '@givewp/components/ListTable/BlankSlate'; +import Toast from "@givewp/components/AdminUI/Toast"; declare global { interface Window { @@ -31,10 +32,11 @@ declare global { } } -interface OnboardingStateProps { +interface MigrationTransferStateProps { migrationOnboardingCompleted: boolean; showMigrationSuccessDialog: boolean; showTransferSuccessDialog: boolean; + showMigrationCompletedToast: boolean; formId: number | null; formName: string | null; } @@ -95,7 +97,7 @@ const v2FormBadge = item => { if (item.v2form) { return
- + V2
; @@ -211,10 +213,11 @@ const ListTableBlankSlate = ( export default function DonationFormsListTable() { - const [state, setState] = useState({ + const [state, setState] = useState({ migrationOnboardingCompleted: Boolean(window.GiveDonationForms.migrationOnboardingCompleted), showMigrationSuccessDialog: false, showTransferSuccessDialog: false, + showMigrationCompletedToast: false, formId: null, formName: null, }) @@ -229,6 +232,11 @@ export default function DonationFormsListTable() { showTransferSuccessDialog: false })), []); + const closeMigrationCompletedToast = useCallback(() => setState(prev => ({ + ...prev, + showMigrationCompletedToast: false + })), []); + return ( )} {state.showTransferSuccessDialog && ( - + + )} + {state.showMigrationCompletedToast && ( + + {sprintf(__('Migration of the form "%s" completed successfully', 'give'), state.formName)} + )} ); diff --git a/src/DonationForms/V2/resources/components/DonationFormsRowActions.tsx b/src/DonationForms/V2/resources/components/DonationFormsRowActions.tsx index aaf18f2d8c..05084b9d02 100644 --- a/src/DonationForms/V2/resources/components/DonationFormsRowActions.tsx +++ b/src/DonationForms/V2/resources/components/DonationFormsRowActions.tsx @@ -14,7 +14,7 @@ const donationFormsApi = new ListTableApi(window.GiveDonationForms); export function DonationFormsRowActions({data, item, removeRow, addRow, setUpdateErrors, parameters}) { const {mutate} = useSWRConfig(); const showConfirmModal = useContext(ShowConfirmModalContext); - const [onboardingState, setOnboardingState] = useContext(MigrationOnboardingContext); + const [MigrationTransferState, setMigrationTransferState] = useContext(MigrationOnboardingContext); const trashEnabled = Boolean(data?.trash); const deleteEndpoint = trashEnabled && !item.status.includes('trash') ? '/trash' : '/delete'; @@ -75,14 +75,20 @@ export function DonationFormsRowActions({data, item, removeRow, addRow, setUpdat onClick={addRow(async (id) => { const response = await fetchAndUpdateErrors(parameters, '/migrate', id, 'POST'); - if (!onboardingState.migrationOnboardingCompleted) { + if (!MigrationTransferState.migrationOnboardingCompleted) { updateOnboardingOption('migration_onboarding_completed').then((data) => { - setOnboardingState(prev => ({ + setMigrationTransferState(prev => ({ ...prev, showMigrationSuccessDialog: true, formId: response.successes[0] })) }) + } else { + setMigrationTransferState(prev => ({ + ...prev, + formName: item?.name, + showMigrationCompletedToast: true + })) } return response @@ -95,7 +101,7 @@ export function DonationFormsRowActions({data, item, removeRow, addRow, setUpdat {item.transfer && ( { - setOnboardingState(prev => ({ + setMigrationTransferState(prev => ({ ...prev, showTransferSuccessDialog: true, formName: item?.name,