Skip to content

Commit

Permalink
Prevent browser error on dispute evidence submission (#9847)
Browse files Browse the repository at this point in the history
Co-authored-by: Nagesh Pai <[email protected]>
Co-authored-by: Jessy Pappachan <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent f500790 commit 55fa477
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9830-browser-error-on-dispute-submission
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Browser error no longer shows after dispute evidence submission
25 changes: 17 additions & 8 deletions client/disputes/evidence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ export default ( { query } ) => {
const [ dispute, setDispute ] = useState();
const [ loading, setLoading ] = useState( false );
const [ evidence, setEvidence ] = useState( {} ); // Evidence to update.
const [ redirectAfterSave, setRedirectAfterSave ] = useState( false );

const {
createSuccessNotice,
createErrorNotice,
Expand All @@ -475,7 +477,7 @@ export default ( { query } ) => {
);

const confirmationNavigationCallback = useConfirmNavigation( () => {
if ( pristine ) {
if ( pristine || redirectAfterSave ) {
return;
}

Expand All @@ -488,6 +490,7 @@ export default ( { query } ) => {
useEffect( confirmationNavigationCallback, [
pristine,
confirmationNavigationCallback,
redirectAfterSave,
] );

useEffect( () => {
Expand Down Expand Up @@ -603,11 +606,6 @@ export default ( { query } ) => {
const message = submit
? __( 'Evidence submitted!', 'woocommerce-payments' )
: __( 'Evidence saved!', 'woocommerce-payments' );
const href = getAdminUrl( {
page: 'wc-admin',
path: '/payments/disputes',
filter: 'awaiting_response',
} );

recordEvent(
submit
Expand Down Expand Up @@ -639,9 +637,20 @@ export default ( { query } ) => {
],
} );

window.location.replace( href );
setRedirectAfterSave( true );
};

useEffect( () => {
if ( redirectAfterSave && pristine ) {
const href = getAdminUrl( {
page: 'wc-admin',
path: '/payments/disputes',
filter: 'awaiting_response',
} );
window.location.replace( href );
}
}, [ redirectAfterSave, pristine ] );

const handleSaveError = ( err, submit ) => {
recordEvent(
submit
Expand Down Expand Up @@ -690,8 +699,8 @@ export default ( { query } ) => {
},
} );
setDispute( updatedDispute );
handleSaveSuccess( submit );
setEvidence( {} );
handleSaveSuccess( submit );
updateDisputeInStore( updatedDispute );
} catch ( err ) {
handleSaveError( err, submit );
Expand Down

0 comments on commit 55fa477

Please sign in to comment.