From 665345fd7c0540bcc6726ff7fe47ee7b47707d29 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:12:34 +0700 Subject: [PATCH 1/7] Delete legacy `acceptDispute()` action and renamed `acceptTransactionDetailsDispute()` to `acceptDispute()`. --- client/data/disputes/actions.js | 62 +-------------------------------- client/data/disputes/hooks.ts | 4 +-- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/client/data/disputes/actions.js b/client/data/disputes/actions.js index 4a0f82197e1..3979390e3cf 100644 --- a/client/data/disputes/actions.js +++ b/client/data/disputes/actions.js @@ -13,7 +13,6 @@ import { __, sprintf } from '@wordpress/i18n'; import { NAMESPACE, STORE_NAME } from '../constants'; import TYPES from './action-types'; import wcpayTracks from 'tracks'; -import { getAdminUrl } from 'wcpay/utils'; import { getPaymentIntent } from '../payment-intents/resolvers'; export function updateDispute( data ) { @@ -48,66 +47,7 @@ export function updateDisputesSummary( query, data ) { }; } -export function* acceptDispute( id ) { - try { - yield controls.dispatch( STORE_NAME, 'startResolution', 'getDispute', [ - id, - ] ); - - const dispute = yield apiFetch( { - path: `${ NAMESPACE }/disputes/${ id }/close`, - method: 'post', - } ); - - yield updateDispute( dispute ); - yield controls.dispatch( STORE_NAME, 'finishResolution', 'getDispute', [ - id, - ] ); - - // Redirect to Disputes list. - window.location.replace( - getAdminUrl( { - page: 'wc-admin', - path: '/payments/disputes', - filter: 'awaiting_response', - } ) - ); - - wcpayTracks.recordEvent( 'wcpay_dispute_accept_success' ); - const message = dispute.order - ? sprintf( - /* translators: #%s is an order number, e.g. 15 */ - __( - 'You have accepted the dispute for order #%s.', - 'woocommerce-payments' - ), - dispute.order.number - ) - : __( 'You have accepted the dispute.', 'woocommerce-payments' ); - yield controls.dispatch( - 'core/notices', - 'createSuccessNotice', - message - ); - } catch ( e ) { - const message = __( - 'There has been an error accepting the dispute. Please try again later.', - 'woocommerce-payments' - ); - wcpayTracks.recordEvent( 'wcpay_dispute_accept_failed' ); - yield controls.dispatch( 'core/notices', 'createErrorNotice', message ); - } -} - -// This function handles the dispute acceptance flow from the Transaction Details screen. -// It differs from the `acceptDispute` function above in that it also fetches and updates -// the payment intent associated with the dispute to reflect changes to the dispute -// on the Transaction Details screen. -// -// Once the '_wcpay_feature_dispute_on_transaction_page' is enabled by default, -// the `acceptDispute` function above can be removed and this function can be renamed -// to `acceptDispute`. -export function* acceptTransactionDetailsDispute( dispute ) { +export function* acceptDispute( dispute ) { const { id, payment_intent: paymentIntent } = dispute; try { diff --git a/client/data/disputes/hooks.ts b/client/data/disputes/hooks.ts index e3797499537..fac77fd28b3 100644 --- a/client/data/disputes/hooks.ts +++ b/client/data/disputes/hooks.ts @@ -72,8 +72,8 @@ export const useDisputeAccept = ( }, [ dispute.id ] ); - const { acceptTransactionDetailsDispute } = useDispatch( STORE_NAME ); - const doAccept = () => acceptTransactionDetailsDispute( dispute ); + const { acceptDispute } = useDispatch( STORE_NAME ); + const doAccept = () => acceptDispute( dispute ); return { doAccept, isLoading }; }; From a8499d99f4b7a83e2af5e147bf5006220fe45dab Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:53:15 +0700 Subject: [PATCH 2/7] Pass dispute object instead of dispute id to `acceptDispute()`. --- client/data/disputes/hooks.ts | 2 +- client/data/disputes/test/actions.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/data/disputes/hooks.ts b/client/data/disputes/hooks.ts index fac77fd28b3..57ecae1bac0 100644 --- a/client/data/disputes/hooks.ts +++ b/client/data/disputes/hooks.ts @@ -47,7 +47,7 @@ export const useDispute = ( ); const { acceptDispute } = useDispatch( STORE_NAME ); - const doAccept = () => acceptDispute( id ); + const doAccept = () => acceptDispute( dispute ); return { dispute, isLoading, error, doAccept }; }; diff --git a/client/data/disputes/test/actions.js b/client/data/disputes/test/actions.js index f70a2d8da5e..fa79fcecffc 100644 --- a/client/data/disputes/test/actions.js +++ b/client/data/disputes/test/actions.js @@ -27,7 +27,7 @@ describe( 'acceptDispute action', () => { } ); test( 'should close dispute and update state with dispute data', () => { - const generator = acceptDispute( 'dp_mock1' ); + const generator = acceptDispute( mockDispute ); expect( generator.next().value ).toEqual( controls.dispatch( 'wc/payments', 'startResolution', 'getDispute', [ @@ -65,7 +65,7 @@ describe( 'acceptDispute action', () => { } ); test( 'should show notice on error', () => { - const generator = acceptDispute( 'dp_mock1' ); + const generator = acceptDispute( mockDispute ); generator.next(); expect( generator.throw( { code: 'error' } ).value ).toEqual( From 887af5466cecc2d5ea28f92902f841e9e3396ea5 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:54:00 +0700 Subject: [PATCH 3/7] Fix unit test around `acceptDispute()` action. --- client/data/disputes/test/actions.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/data/disputes/test/actions.js b/client/data/disputes/test/actions.js index fa79fcecffc..68639fc1e20 100644 --- a/client/data/disputes/test/actions.js +++ b/client/data/disputes/test/actions.js @@ -10,12 +10,14 @@ import { controls } from '@wordpress/data'; * Internal dependencies */ import { acceptDispute, updateDispute } from '../actions'; +import { getPaymentIntent } from '../../payment-intents/resolvers'; describe( 'acceptDispute action', () => { const mockDispute = { id: 'dp_mock1', reason: 'product_unacceptable', status: 'lost', + payment_intent: 'payment_intent', }; beforeEach( () => { @@ -43,6 +45,9 @@ describe( 'acceptDispute action', () => { expect( generator.next( mockDispute ).value ).toEqual( updateDispute( mockDispute ) ); + expect( generator.next().value ).toEqual( + getPaymentIntent( mockDispute.payment_intent ) + ); expect( generator.next().value ).toEqual( controls.dispatch( 'wc/payments', @@ -53,7 +58,6 @@ describe( 'acceptDispute action', () => { ); const noticeAction = generator.next().value; - expect( window.location.replace ).toHaveBeenCalledTimes( 1 ); expect( noticeAction ).toEqual( controls.dispatch( 'core/notices', From ab9ce76644e66fd0a19c5ab2083f548347af24b2 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 01:57:25 +0700 Subject: [PATCH 4/7] Changelog. --- changelog/remove-7363-unused-dispute-details-code | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/remove-7363-unused-dispute-details-code diff --git a/changelog/remove-7363-unused-dispute-details-code b/changelog/remove-7363-unused-dispute-details-code new file mode 100644 index 00000000000..da3e0db1cf4 --- /dev/null +++ b/changelog/remove-7363-unused-dispute-details-code @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Removing unused legacy dispute details code that does not affect user facing UX. + + From 0cc1db389e250ab33eaeafe1cbf9c0c438d44ef5 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 06:42:46 +0700 Subject: [PATCH 5/7] Remove unused `LegacyDisputeDetails` / `client/disputes/details/index.tsx`. --- client/disputes/details/index.tsx | 159 ------------------------------ 1 file changed, 159 deletions(-) delete mode 100644 client/disputes/details/index.tsx diff --git a/client/disputes/details/index.tsx b/client/disputes/details/index.tsx deleted file mode 100644 index e8af4bbcf97..00000000000 --- a/client/disputes/details/index.tsx +++ /dev/null @@ -1,159 +0,0 @@ -/** @format **/ - -/** - * External dependencies - */ -import React from 'react'; -import { __, sprintf } from '@wordpress/i18n'; -import { Card, CardBody, CardFooter, CardHeader } from '@wordpress/components'; - -/** - * Internal dependencies. - */ -import { useDispute } from 'data/index'; -import { reasons } from '../strings'; -import Actions from './actions'; -import Info from '../info'; -import Paragraphs from 'components/paragraphs'; -import Page from 'components/page'; -import ErrorBoundary from 'components/error-boundary'; -import DisputeStatusChip from 'components/dispute-status-chip'; -import Loadable, { LoadableBlock } from 'components/loadable'; -import { TestModeNotice, topics } from 'components/test-mode-notice'; -import '../style.scss'; -import { Dispute } from 'wcpay/types/disputes'; - -const LegacyDisputeDetails = ( { - query: { id: disputeId }, -}: { - query: { id: string }; -} ): JSX.Element => { - const { dispute, isLoading, doAccept } = useDispute( disputeId ); - const disputeObject = dispute || ( {} as Dispute ); - const disputeIsAvailable = ! isLoading && dispute && disputeObject.id; - - const actions = disputeIsAvailable && ( - - ); - - const mapping = reasons[ disputeObject.reason ] || {}; - const testModeNotice = ; - - if ( ! isLoading && ! disputeIsAvailable ) { - return ( - - { testModeNotice } - -
- { __( 'Dispute not loaded', 'woocommerce-payments' ) } -
-
-
- ); - } - - return ( - - { testModeNotice } - - - - - { __( 'Dispute overview', 'woocommerce-payments' ) } - - - - - - - { mapping.overview } - - - - - { actions || [] } - - - - - - - - - - - - { mapping.summary } - - - - { mapping.required && ( -

- { ' ' } - { __( - 'Required to overturn dispute', - 'woocommerce-payments' - ) }{ ' ' } -

- ) } - { mapping.required } -
- - - { mapping.respond && ( -

- { __( - 'How to respond', - 'woocommerce-payments' - ) } -

- ) } - { mapping.respond } -
-
- - - { actions || [] } - - -
-
-
- ); -}; - -export default LegacyDisputeDetails; From 3d4d7a594cf4681a71b4c6b41971b0b67bf50749 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 06:50:34 +0700 Subject: [PATCH 6/7] Revert: Remove unused `LegacyDisputeDetails` / `client/disputes/details/index.tsx`. --- client/disputes/details/index.tsx | 159 ++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 client/disputes/details/index.tsx diff --git a/client/disputes/details/index.tsx b/client/disputes/details/index.tsx new file mode 100644 index 00000000000..e8af4bbcf97 --- /dev/null +++ b/client/disputes/details/index.tsx @@ -0,0 +1,159 @@ +/** @format **/ + +/** + * External dependencies + */ +import React from 'react'; +import { __, sprintf } from '@wordpress/i18n'; +import { Card, CardBody, CardFooter, CardHeader } from '@wordpress/components'; + +/** + * Internal dependencies. + */ +import { useDispute } from 'data/index'; +import { reasons } from '../strings'; +import Actions from './actions'; +import Info from '../info'; +import Paragraphs from 'components/paragraphs'; +import Page from 'components/page'; +import ErrorBoundary from 'components/error-boundary'; +import DisputeStatusChip from 'components/dispute-status-chip'; +import Loadable, { LoadableBlock } from 'components/loadable'; +import { TestModeNotice, topics } from 'components/test-mode-notice'; +import '../style.scss'; +import { Dispute } from 'wcpay/types/disputes'; + +const LegacyDisputeDetails = ( { + query: { id: disputeId }, +}: { + query: { id: string }; +} ): JSX.Element => { + const { dispute, isLoading, doAccept } = useDispute( disputeId ); + const disputeObject = dispute || ( {} as Dispute ); + const disputeIsAvailable = ! isLoading && dispute && disputeObject.id; + + const actions = disputeIsAvailable && ( + + ); + + const mapping = reasons[ disputeObject.reason ] || {}; + const testModeNotice = ; + + if ( ! isLoading && ! disputeIsAvailable ) { + return ( + + { testModeNotice } + +
+ { __( 'Dispute not loaded', 'woocommerce-payments' ) } +
+
+
+ ); + } + + return ( + + { testModeNotice } + + + + + { __( 'Dispute overview', 'woocommerce-payments' ) } + + + + + + + { mapping.overview } + + + + + { actions || [] } + + + + + + + + + + + + { mapping.summary } + + + + { mapping.required && ( +

+ { ' ' } + { __( + 'Required to overturn dispute', + 'woocommerce-payments' + ) }{ ' ' } +

+ ) } + { mapping.required } +
+ + + { mapping.respond && ( +

+ { __( + 'How to respond', + 'woocommerce-payments' + ) } +

+ ) } + { mapping.respond } +
+
+ + + { actions || [] } + + +
+
+
+ ); +}; + +export default LegacyDisputeDetails; From eac06d5220e7345e1cd14bc1ff12fbf16e726331 Mon Sep 17 00:00:00 2001 From: Shendy <73803630+shendy-a8c@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:27:09 +0700 Subject: [PATCH 7/7] Delete `client/disputes/details` (#7458) Co-authored-by: Eric Jinks <3147296+Jinksi@users.noreply.github.com> --- changelog/remove-7363-legacy-dispute-details | 5 + client/data/disputes/hooks.ts | 8 +- client/disputes/details/actions.tsx | 74 - client/disputes/details/index.tsx | 159 - .../test/__snapshots__/actions.tsx.snap | 35 - .../details/test/__snapshots__/index.tsx.snap | 5096 ----------------- client/disputes/details/test/actions.tsx | 80 - client/disputes/details/test/index.tsx | 148 - client/disputes/style.scss | 6 - 9 files changed, 7 insertions(+), 5604 deletions(-) create mode 100644 changelog/remove-7363-legacy-dispute-details delete mode 100644 client/disputes/details/actions.tsx delete mode 100644 client/disputes/details/index.tsx delete mode 100644 client/disputes/details/test/__snapshots__/actions.tsx.snap delete mode 100644 client/disputes/details/test/__snapshots__/index.tsx.snap delete mode 100644 client/disputes/details/test/actions.tsx delete mode 100644 client/disputes/details/test/index.tsx diff --git a/changelog/remove-7363-legacy-dispute-details b/changelog/remove-7363-legacy-dispute-details new file mode 100644 index 00000000000..da3e0db1cf4 --- /dev/null +++ b/changelog/remove-7363-legacy-dispute-details @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Removing unused legacy dispute details code that does not affect user facing UX. + + diff --git a/client/data/disputes/hooks.ts b/client/data/disputes/hooks.ts index 57ecae1bac0..b8a95b1e5e6 100644 --- a/client/data/disputes/hooks.ts +++ b/client/data/disputes/hooks.ts @@ -20,7 +20,7 @@ import { STORE_NAME } from '../constants'; import { disputeAwaitingResponseStatuses } from 'wcpay/disputes/filters/config'; /** - * Returns the dispute object, loading state, and accept function. + * Returns the dispute object, error object, and loading state. * Fetches the dispute object if it is not already cached. */ export const useDispute = ( @@ -29,7 +29,6 @@ export const useDispute = ( dispute?: Dispute; error?: ApiError; isLoading: boolean; - doAccept: () => void; } => { const { dispute, error, isLoading } = useSelect( ( select ) => { @@ -46,10 +45,7 @@ export const useDispute = ( [ id ] ); - const { acceptDispute } = useDispatch( STORE_NAME ); - const doAccept = () => acceptDispute( dispute ); - - return { dispute, isLoading, error, doAccept }; + return { dispute, isLoading, error }; }; /** diff --git a/client/disputes/details/actions.tsx b/client/disputes/details/actions.tsx deleted file mode 100644 index d67fa5bee28..00000000000 --- a/client/disputes/details/actions.tsx +++ /dev/null @@ -1,74 +0,0 @@ -/** @format **/ - -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; -import { Button } from '@wordpress/components'; -import React from 'react'; - -/** - * Internal dependencies - */ -import wcpayTracks from 'tracks'; -import { getAdminUrl } from 'wcpay/utils'; - -const Actions = ( { - id, - needsResponse, - isSubmitted, - onAccept, -}: { - id: string; - needsResponse: boolean; - isSubmitted: boolean | undefined; - onAccept: () => void; -} ): JSX.Element => { - if ( ! needsResponse && ! isSubmitted ) { - return <>; - } - - const challengeUrl = getAdminUrl( { - page: 'wc-admin', - path: '/payments/disputes/challenge', - id, - } ); - - const acceptMessage = __( - "Are you sure you'd like to accept this dispute? This action can not be undone.", - 'woocommerce-payments' - ); - - return ( -
- - { needsResponse && ( - - ) } -
- ); -}; - -export default Actions; diff --git a/client/disputes/details/index.tsx b/client/disputes/details/index.tsx deleted file mode 100644 index e8af4bbcf97..00000000000 --- a/client/disputes/details/index.tsx +++ /dev/null @@ -1,159 +0,0 @@ -/** @format **/ - -/** - * External dependencies - */ -import React from 'react'; -import { __, sprintf } from '@wordpress/i18n'; -import { Card, CardBody, CardFooter, CardHeader } from '@wordpress/components'; - -/** - * Internal dependencies. - */ -import { useDispute } from 'data/index'; -import { reasons } from '../strings'; -import Actions from './actions'; -import Info from '../info'; -import Paragraphs from 'components/paragraphs'; -import Page from 'components/page'; -import ErrorBoundary from 'components/error-boundary'; -import DisputeStatusChip from 'components/dispute-status-chip'; -import Loadable, { LoadableBlock } from 'components/loadable'; -import { TestModeNotice, topics } from 'components/test-mode-notice'; -import '../style.scss'; -import { Dispute } from 'wcpay/types/disputes'; - -const LegacyDisputeDetails = ( { - query: { id: disputeId }, -}: { - query: { id: string }; -} ): JSX.Element => { - const { dispute, isLoading, doAccept } = useDispute( disputeId ); - const disputeObject = dispute || ( {} as Dispute ); - const disputeIsAvailable = ! isLoading && dispute && disputeObject.id; - - const actions = disputeIsAvailable && ( - - ); - - const mapping = reasons[ disputeObject.reason ] || {}; - const testModeNotice = ; - - if ( ! isLoading && ! disputeIsAvailable ) { - return ( - - { testModeNotice } - -
- { __( 'Dispute not loaded', 'woocommerce-payments' ) } -
-
-
- ); - } - - return ( - - { testModeNotice } - - - - - { __( 'Dispute overview', 'woocommerce-payments' ) } - - - - - - - { mapping.overview } - - - - - { actions || [] } - - - - - - - - - - - - { mapping.summary } - - - - { mapping.required && ( -

- { ' ' } - { __( - 'Required to overturn dispute', - 'woocommerce-payments' - ) }{ ' ' } -

- ) } - { mapping.required } -
- - - { mapping.respond && ( -

- { __( - 'How to respond', - 'woocommerce-payments' - ) } -

- ) } - { mapping.respond } -
-
- - - { actions || [] } - - -
-
-
- ); -}; - -export default LegacyDisputeDetails; diff --git a/client/disputes/details/test/__snapshots__/actions.tsx.snap b/client/disputes/details/test/__snapshots__/actions.tsx.snap deleted file mode 100644 index f479757dcd4..00000000000 --- a/client/disputes/details/test/__snapshots__/actions.tsx.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Dispute details actions renders correctly for closed dispute 1`] = `
`; - -exports[`Dispute details actions renders correctly for dispute needing response, confirmation requested on submit 1`] = ` -
-
- - Challenge dispute - - -
-
-`; - -exports[`Dispute details actions renders correctly for dispute with evidence submitted 1`] = ` - -`; diff --git a/client/disputes/details/test/__snapshots__/index.tsx.snap b/client/disputes/details/test/__snapshots__/index.tsx.snap deleted file mode 100644 index 8baf2f66990..00000000000 --- a/client/disputes/details/test/__snapshots__/index.tsx.snap +++ /dev/null @@ -1,5096 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Dispute details screen renders correctly for bank_cannot_process dispute 1`] = ` -
-
-
-
-
- Dispute overview - - Needs response - -
-
-
-
- - Dispute date: - - - Nov 1, 2019 - -
-
- - Disputed amount: - - - $10.00 - -
-
- - Respond by: - - - Nov 8, 2019 - 2:46AM - -
-
- - Reason: - - - Bank cannot process - -
-
- - Order: - - - - 1 - - -
-
- - Transaction ID: - - - - -
-
-
- -
-