File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,28 @@ const handleSubmit = ({
92
92
transactionId: " hjkhjkhsdsdiui" ,
93
93
};
94
94
95
- const variables = { input : checkoutData } ;
95
+ const { mutate , onDone , onError } = useMutation ( CHECKOUT_MUTATION ) ;
96
96
97
- const { mutate , onDone , onError } = useMutation (CHECKOUT_MUTATION , {
98
- variables,
99
- });
100
-
101
- mutate (checkoutData);
97
+ mutate ({ input: checkoutData });
102
98
103
- onDone (async () => await navigateTo (" /success" ));
99
+ onDone (async (result ) => {
100
+ const { data } = result;
101
+ if (data? .checkout ? .result === " success" ) {
102
+ await navigateTo (" /success" );
103
+ } else {
104
+ alert (" Error, order not placed. Please try again." );
105
+ }
106
+ });
104
107
105
- onError (() => alert (" Error, order not placed" ));
108
+ onError ((error ) => {
109
+ console .error (" Checkout error:" , error);
110
+ if (error .message .includes (" session" )) {
111
+ alert (
112
+ " Your session has expired. Please refresh the page and try again." ,
113
+ );
114
+ } else {
115
+ alert (" An unexpected error occurred. Please try again." );
116
+ }
117
+ });
106
118
};
107
119
< / script>
You can’t perform that action at this time.
0 commit comments