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

Rename dispute action from acceptTransactionDetailsDispute() to acceptDispute() #7456

Merged
merged 9 commits into from
Oct 12, 2023
5 changes: 5 additions & 0 deletions changelog/remove-7363-legacy-dispute-details
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Removing unused legacy dispute details code that does not affect user facing UX.


5 changes: 5 additions & 0 deletions changelog/remove-7363-unused-dispute-details-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Removing unused legacy dispute details code that does not affect user facing UX.


62 changes: 1 addition & 61 deletions client/data/disputes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions client/data/disputes/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -29,7 +29,6 @@ export const useDispute = (
dispute?: Dispute;
error?: ApiError;
isLoading: boolean;
doAccept: () => void;
} => {
const { dispute, error, isLoading } = useSelect(
( select ) => {
Expand All @@ -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 };
};

/**
Expand All @@ -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 };
};

Expand Down
10 changes: 7 additions & 3 deletions client/data/disputes/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( () => {
Expand All @@ -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', [
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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(
Expand Down
74 changes: 0 additions & 74 deletions client/disputes/details/actions.tsx

This file was deleted.

Loading