-
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
Show a loading UI when accepting a dispute is in progress #7476
Changes from 10 commits
aab1471
1d68e48
a141018
28ac2e9
20173b5
ab3be4f
32c1f0e
528c7ca
af9ec15
e7dc291
24223b3
b60c8dc
27e7621
3e8f9ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
Show loading state when accepting a dispute from the transaction details screen. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,10 +82,14 @@ interface AcceptDisputeProps { | |
/** | ||
* Disputes and Inquiries have different text for buttons and the modal. | ||
* They also have different icons and tracks events. This function returns the correct props. | ||
* | ||
* @param dispute | ||
*/ | ||
function getAcceptDisputeProps( dispute: Dispute ): AcceptDisputeProps { | ||
function getAcceptDisputeProps( { | ||
dispute, | ||
isLoading, | ||
}: { | ||
dispute: Dispute; | ||
isLoading: boolean; | ||
} ): AcceptDisputeProps { | ||
if ( isInquiry( dispute ) ) { | ||
return { | ||
acceptButtonLabel: __( 'Issue refund', 'woocommerce-payments' ), | ||
|
@@ -146,7 +150,9 @@ function getAcceptDisputeProps( dispute: Dispute ): AcceptDisputeProps { | |
), | ||
}, | ||
], | ||
modalButtonLabel: __( 'Accept dispute', 'woocommerce-payments' ), | ||
modalButtonLabel: isLoading | ||
Jinksi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? __( 'Accepting…', 'woocommerce-payments' ) | ||
: __( 'Accept dispute', 'woocommerce-payments' ), | ||
modalButtonTracksEvent: wcpayTracks.events.DISPUTE_ACCEPT_CLICK, | ||
}; | ||
} | ||
|
@@ -171,6 +177,9 @@ const DisputeAwaitingResponseDetails: React.FC< Props > = ( { | |
} = useContext( WCPaySettingsContext ); | ||
|
||
const onModalClose = () => { | ||
if ( isLoading ) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More renaming suggestions 😁
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've renamed it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A tiny bit! |
||
setModalOpen( false ); | ||
}; | ||
|
||
|
@@ -188,7 +197,7 @@ const DisputeAwaitingResponseDetails: React.FC< Props > = ( { | |
); | ||
}; | ||
|
||
const disputeAcceptAction = getAcceptDisputeProps( dispute ); | ||
const disputeAcceptAction = getAcceptDisputeProps( { dispute, isLoading } ); | ||
|
||
const challengeButtonDefaultText = isInquiry( dispute ) | ||
? __( 'Submit evidence', 'woocommerce-payments' ) | ||
|
@@ -326,6 +335,7 @@ const DisputeAwaitingResponseDetails: React.FC< Props > = ( { | |
> | ||
<Button | ||
variant="tertiary" | ||
disabled={ isLoading } | ||
onClick={ onModalClose } | ||
> | ||
{ __( | ||
|
@@ -335,6 +345,8 @@ const DisputeAwaitingResponseDetails: React.FC< Props > = ( { | |
</Button> | ||
<Button | ||
variant="primary" | ||
isBusy={ isLoading } | ||
disabled={ isLoading } | ||
Jinksi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data-testid="accept-dispute-button" | ||
onClick={ () => { | ||
wcpayTracks.recordEvent( | ||
|
@@ -346,7 +358,7 @@ const DisputeAwaitingResponseDetails: React.FC< Props > = ( { | |
'transaction_details', | ||
} | ||
); | ||
setModalOpen( false ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why we didn't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same! I don't have an answer. |
||
|
||
/** | ||
* Handle the primary modal action. | ||
* If it's an inquiry, redirect to the order page; otherwise, continue with the default dispute acceptance. | ||
|
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.
getAcceptDisputeProps
is pretty strange to read and reason about. I think this code would be a lot clearer if it just had a dedicated modal for each case (inquiry vs dispute).AcceptDisputeProps
is a domain-specific interface for a semi-generic modal (e.g.modalLines
); I don't see a benefit to that over using the React components we have (i.e. a powerful, readable, flexible modal API).That said, I don't know if it's safe/worthwhile to refactor this for this change. I would be tempted 😁
Mentioning because this PR reads as very decoupled – can't really see what changed. Specifically, the button
Submitting…
label should be an implementation detail inside a modal component. I find it strange (and complex) that this is delegated to a function (that now needs a new param).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.
Yes, I agree and I began a refactor of this code in #7339, but it became low-priority and out-of-scope due to time constraints.
I think a refactor should be handled in a separate PR, as it is a more significant quantity of work and is separate from this PR's goal.