Skip to content

Commit

Permalink
fix: use dymanic url for portal page
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-yato committed Sep 20, 2024
1 parent 844af1b commit fe4ceb8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
1 change: 0 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@fontsource-variable/manrope": "^5.1.0",
"@formkit/auto-animate": "^0.8.2",
"@hookform/resolvers": "^3.9.0",
"@justmiracle/checkitout": "workspace:*",
"@justmiracle/result": "^1.2.0",
"@nanostores/react": "^0.7.3",
"@phosphor-icons/react": "^2.1.7",
Expand Down
27 changes: 5 additions & 22 deletions apps/web/src/route/portal/$checkoutId.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,33 @@
import { Em, Flex, Grid, Text } from "@radix-ui/themes";
import { Flex, Grid } from "@radix-ui/themes";
import { createFileRoute } from "@tanstack/react-router";
import { Invoice } from "./-component/invoice";
import { QRPay } from "./-component/qr";
import { useQuery } from "@tanstack/react-query";
import ky from "ky";
import { useEffect, useState } from "react";
import { Check, PiggyBank, Scan } from "@phosphor-icons/react";
import { env } from "@/lib/env";

export const Route = createFileRoute("/portal/$checkoutId")({
component: CheckoutPage,
});

function CheckoutPage() {
const { checkoutId } = Route.useParams();
const [success, setSuccess] = useState(false);

const { data, isPending, error } = useQuery({
queryKey: ["checkout", checkoutId],
queryFn: () => {
return ky
.get(`http://localhost:3050/v1/checkout/portal/${checkoutId}`, { retry: 0 })
.get(`v1/checkout/portal/${checkoutId}`, { retry: 0, prefixUrl: env.VITE_API_URL })
.json<any>();
},
retry: false,
refetchInterval: (query) =>
query.state.status === "error" || query.state?.data?.checkout?.status === "SUCCESS"
? false
: 3000,
: 2869,
});

useEffect(() => {
if (!data?.activeTransaction) return;

const event = new EventSource(
`http://localhost:3050/v1/transaction/track/${data?.activeTransaction.md5}`,
);

event.onmessage = (e) => {
const status = e.data;
if (status === "COMPLETED") {
setSuccess(true);
event.close();
}
};
}, [data]);

if (isPending) {
return <div className="h-dvh w-full bg-gray-2" />;
}
Expand All @@ -65,7 +48,7 @@ function CheckoutPage() {
>
<div className="flex w-fit flex-col">
<QRPay
paid={success || data.checkout.status === "SUCCESS"}
paid={data.checkout.status === "SUCCESS"}
currency={data.checkout.currency}
amount={data.checkout.total}
merchantName={"Mi Home BKK"}
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/.changeset/empty-timers-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@justmiracle/checkitout": patch
---

Remove .turbo cache and wild index.ts file
13 changes: 13 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @justmiracle/checkitout

## 0.1.3

### Patch Changes

- Remove .turbo cache and wild index.ts file
- Ignore uneeded files

## 0.1.2

### Patch Changes

- Ignore uneeded files

## 0.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"typings": "dist/index.d.ts",
"main": "dist/index.js",
"type": "module",
"version": "0.1.1",
"version": "0.1.3",
"author": "RinYato <[email protected]> (https://rinyato.com)",
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --minify",
Expand Down

0 comments on commit fe4ceb8

Please sign in to comment.