-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add Dispute Challenge and Accept buttons to Transaction Details #7093
Merged
Jinksi
merged 63 commits into
develop
from
fix/6926-transaction-dispute-details-actions
Sep 19, 2023
Merged
Changes from 21 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
991dd84
Refactor isAwaitingResponse check to wrap entire <Card />
Jinksi 46c3f31
Add dispute actions init
Jinksi 59190f2
Add Dispute > EvidenceDetails type comments to improve devex
Jinksi b8ef1be
Show different challenge button label if has staged evidence
Jinksi 026d905
Add missing `payment_intent` to Dispute TS interface
Jinksi 10e42da
Add action func for accepting disputes on the Transaction Details screen
Jinksi 1a53f0e
Add custom hook for accepting dispute
Jinksi 7cc279b
Add accept dispute modal
Jinksi a85fea3
Improve isLoading state for accepting disputes and exceptions
Jinksi 194677b
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 3f7168d
Update accept dispute modal styles
Jinksi 347198a
Add getDisputeFee util function
Jinksi 484b60d
Populate dynamic content for accept dispute modal
Jinksi 83474fe
Add changelog entry
Jinksi b64d04b
Fix modal text content overflow
Jinksi 9ea2586
Update Dispute → Charge interface to accept `string`
Jinksi 004aaf6
Move useDisputeAccept hook to `data/disputes/hooks`
Jinksi 341d83d
Improve translators note with `<em>` element description
Jinksi da679bc
Add DisputeDetails tests
Jinksi 62cd852
Add test for clicking challenge button
Jinksi 8a349b6
Remove extraneous div
Jinksi 3545ae9
Add test for dispute with staged evidence
Jinksi 2fb3cfb
Add dispute action tracks events
Jinksi c355a77
Add missing full-stop to accept dispute modal text
Jinksi 2f59597
Add currency rendering test for accept dispute modal
Jinksi 0d0616d
Add test for Inquiry accept dispute modal
Jinksi b134595
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 39e0d7f
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 9d341a0
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 9091394
Fix formatting after merge conflict resolution
Jinksi 163d427
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 1165d67
Fix duplicate import after merge conflict resolution
Jinksi dc3a79a
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 1b2bbc3
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi fe0955b
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 3412ae0
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 47a9324
Don't render dispute actions for inquiries
Jinksi cae2394
Add more info to acceptTransactionDetailsDispute comment
Jinksi db85448
Rename onSubmit → onAccept to name intent
Jinksi 81738f0
Add dispute_status prop to tracks events
Jinksi c072af5
Update dispute hook comments
Jinksi 85490fc
Cleanup tests and remove flaky test
Jinksi cfb3709
Move challenge click handler to func improve code clarity
Jinksi 156c298
Remove redundant `null` return
Jinksi 5961f5f
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi be9ff75
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 0bb32c9
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi c5a5ffe
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi dcc5d45
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi 395a111
Move DisputeActions logic and markup into parent component
Jinksi 49158aa
Allow native browser navigation for challenge button
Jinksi f7ffc1c
Add test for challenge button click
Jinksi ef03f65
Move accept click handler inline to improve readability
Jinksi b6eed3b
Use `showDisputeActions` variable to improve readability
Jinksi 13a4fa3
Add descriptive comment about challenge link
Jinksi b52093d
Rename test `index.tsx` to `index.test.tsx` for consistency
Jinksi 939c40d
Update styles on mobile screens to match design
Jinksi d8ca8e6
Add tests for when actions are not allowed
Jinksi 3709cc0
Remove `Button` from `Link` to simplify code
Jinksi 340b5a1
Fix tests after changing Button → Link
Jinksi 203f161
Revert "Remove `Button` from `Link` to simplify code"
Jinksi 163514b
Revert "Fix tests after changing Button → Link"
Jinksi eb23605
Merge branch 'develop' into fix/6926-transaction-dispute-details-actions
Jinksi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: add | ||
Comment: Behind a feature flag: add challenge and accept action buttons to Transaction Details screen | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
client/payment-details/dispute-details/dispute-actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/** @format **/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import React, { useState } from 'react'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { backup, lock } from '@wordpress/icons'; | ||
import { createInterpolateElement } from '@wordpress/element'; | ||
import { Button, Flex, FlexItem, Icon, Modal } from '@wordpress/components'; | ||
import { getHistory } from '@woocommerce/navigation'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Dispute } from 'wcpay/types/disputes'; | ||
import { getAdminUrl } from 'wcpay/utils'; | ||
import { useDisputeAccept } from 'wcpay/data'; | ||
import { getDisputeFee } from 'wcpay/disputes/utils'; | ||
import { formatCurrency } from 'wcpay/utils/currency'; | ||
|
||
interface Props { | ||
dispute: Dispute; | ||
} | ||
const DisputeActions: React.FC< Props > = ( { dispute } ) => { | ||
const { doAccept, isLoading } = useDisputeAccept( dispute ); | ||
const [ isModalOpen, setModalOpen ] = useState( false ); | ||
|
||
const hasStagedEvidence = dispute.evidence_details?.has_evidence; | ||
const disputeFee = getDisputeFee( dispute ); | ||
|
||
const onClose = () => { | ||
setModalOpen( false ); | ||
}; | ||
|
||
const onSubmit = () => { | ||
// TODO: Tracks event | ||
// wcpayTracks.recordEvent( | ||
// 'wcpay_dispute_challenge_clicked', | ||
// {} | ||
// ); | ||
setModalOpen( false ); | ||
doAccept(); | ||
}; | ||
|
||
return ( | ||
<Flex justify="start"> | ||
<Button | ||
variant="primary" | ||
disabled={ isLoading } | ||
onClick={ () => { | ||
// TODO: Tracks event | ||
// wcpayTracks.recordEvent( | ||
// 'wcpay_dispute_challenge_clicked', | ||
// {} | ||
// ); | ||
const challengeUrl = getAdminUrl( { | ||
page: 'wc-admin', | ||
path: '/payments/disputes/challenge', | ||
id: dispute.id, | ||
} ); | ||
getHistory().push( challengeUrl ); | ||
} } | ||
> | ||
{ hasStagedEvidence | ||
? __( 'Continue with challenge', 'woocommerce-payments' ) | ||
: __( 'Challenge dispute', 'woocommerce-payments' ) } | ||
</Button> | ||
|
||
<Button | ||
variant="tertiary" | ||
disabled={ isLoading } | ||
onClick={ () => { | ||
// TODO: Tracks event | ||
// wcpayTracks.recordEvent( | ||
// 'wcpay_dispute_challenge_clicked', | ||
// {} | ||
// ); | ||
setModalOpen( true ); | ||
} } | ||
> | ||
{ __( 'Accept dispute', 'woocommerce-payments' ) } | ||
</Button> | ||
|
||
{ isModalOpen && ( | ||
<Modal | ||
title="Accept the dispute?" | ||
onRequestClose={ onClose } | ||
className="transaction-details-dispute-accept-modal" | ||
> | ||
<p> | ||
<strong> | ||
{ __( | ||
'Before proceeding, please take note of the following:', | ||
'woocommerce-payments' | ||
) } | ||
</strong> | ||
</p> | ||
<Flex justify="start"> | ||
<FlexItem className="transaction-details-dispute-accept-modal__icon"> | ||
<Icon icon={ backup } size={ 24 } /> | ||
</FlexItem> | ||
<FlexItem> | ||
{ createInterpolateElement( | ||
sprintf( | ||
/* translators: %s: dispute fee, <em>: emphasis HTML element. */ | ||
__( | ||
'Accepting the dispute marks it as <em>Lost</em>. The disputed amount will be returned to the cardholder, with a %s dispute fee deducted from your account', | ||
'woocommerce-payments' | ||
), | ||
disputeFee && | ||
formatCurrency( | ||
disputeFee.fee, | ||
disputeFee.currency | ||
) | ||
), | ||
{ | ||
em: <em />, | ||
} | ||
) } | ||
</FlexItem> | ||
</Flex> | ||
<Flex justify="start"> | ||
<FlexItem className="transaction-details-dispute-accept-modal__icon"> | ||
<Icon icon={ lock } size={ 24 } /> | ||
</FlexItem> | ||
<FlexItem> | ||
{ __( | ||
'Accepting the dispute is final and cannot be undone.', | ||
'woocommerce-payments' | ||
) } | ||
</FlexItem> | ||
</Flex> | ||
|
||
<Flex | ||
className="transaction-details-dispute-accept-modal__actions" | ||
justify="end" | ||
> | ||
<Button variant="tertiary" onClick={ onClose }> | ||
{ __( 'Cancel', 'woocommerce-payments' ) } | ||
</Button> | ||
<Button variant="primary" onClick={ onSubmit }> | ||
{ __( 'Accept dispute', 'woocommerce-payments' ) } | ||
</Button> | ||
</Flex> | ||
</Modal> | ||
) } | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default DisputeActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than modify the existing
acceptDispute
action (used on the Dispute → Details screen), I've created a new one since there are some differences in the approach:Once the feature flag is lifted,
_wcpay_feature_dispute_on_transaction_page
, we can remove and replace the previous action with the new one.I've left a TODO item on #6883 to make this change.