wip
This commit is contained in:
@@ -21,7 +21,7 @@ export default function CartItems({ cart, items, productColumnLabelKey }: {
|
||||
return (
|
||||
<Table className="rounded-lg border border-separate">
|
||||
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
|
||||
<TableRow className="">
|
||||
<TableRow>
|
||||
<TableHead className="px-6">
|
||||
<Trans i18nKey={productColumnLabelKey} />
|
||||
</TableHead>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Button } from '@kit/ui/button';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { placeOrder } from "@lib/data/cart"
|
||||
import Link from 'next/link';
|
||||
import Loading from '@/app/home/loading';
|
||||
import GlobalLoader from '../../loading';
|
||||
|
||||
enum Status {
|
||||
LOADING = 'LOADING',
|
||||
@@ -18,12 +18,17 @@ enum Status {
|
||||
export function MontonioCheckoutCallback() {
|
||||
const router = useRouter();
|
||||
const [status, setStatus] = useState<Status>(Status.LOADING);
|
||||
const [isFinalized, setIsFinalized] = useState(false);
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
if (isFinalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
const token = searchParams.get('order-token');
|
||||
if (!token) {
|
||||
router.push('/home/cart');
|
||||
//router.push('/home/cart');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,6 +43,7 @@ export function MontonioCheckoutCallback() {
|
||||
},
|
||||
body: JSON.stringify({ token }),
|
||||
});
|
||||
setIsFinalized(true);
|
||||
|
||||
if (!response.ok) {
|
||||
const body = await response.json();
|
||||
@@ -54,7 +60,7 @@ export function MontonioCheckoutCallback() {
|
||||
router.push('/home/cart');
|
||||
}
|
||||
} else {
|
||||
setStatus(Status.ERROR);
|
||||
throw new Error('Payment failed or pending');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error verifying token", e);
|
||||
@@ -63,7 +69,7 @@ export function MontonioCheckoutCallback() {
|
||||
}
|
||||
|
||||
void verifyToken();
|
||||
}, [searchParams]);
|
||||
}, [searchParams, isFinalized]);
|
||||
|
||||
if (status === Status.ERROR) {
|
||||
return (
|
||||
@@ -91,5 +97,5 @@ export function MontonioCheckoutCallback() {
|
||||
);
|
||||
}
|
||||
|
||||
return (<Loading />);
|
||||
return <GlobalLoader />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user