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/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. + + 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..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( id ); - - return { dispute, isLoading, error, doAccept }; + return { dispute, isLoading, error }; }; /** @@ -72,8 +68,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 }; }; diff --git a/client/data/disputes/test/actions.js b/client/data/disputes/test/actions.js index f70a2d8da5e..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( () => { @@ -27,7 +29,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', [ @@ -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', @@ -65,7 +69,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( 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`] = ` -
-
- - View submitted evidence - -
-
-`; 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: - - - - -
-
-
- -
-