Skip to content

Commit fb21c97

Browse files
committed
last frontend scanner update
1 parent 7b491cd commit fb21c97

7 files changed

Lines changed: 326 additions & 181 deletions

File tree

frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ShowQR from "./pages/ShowQR";
66
import ScanQR from "./pages/ScanQR";
77
import Services from "./pages/Services";
88
import Domains from "./pages/Domains";
9+
// import ScanDone from "./pages/ScanDone";
910

1011
function App() {
1112
return (
@@ -19,6 +20,7 @@ function App() {
1920
<Route path="/scan-qr" element={<ScanQR />} />
2021
<Route path="/services" element={<Services />} />
2122
<Route path="/domains" element={<Domains />} />
23+
{/* <Route path="/scan-done" element={<ScanDone />} /> */}
2224
</Routes>
2325
</Router>
2426
</div>

frontend/src/api/api.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const API_URL = import.meta.env.VITE_API_URL || "http://localhost:8080";
22

33
export const validateQrCode = async (
44
validationId: string
5-
): Promise<boolean> => {
5+
): Promise<"valid" | "invalid" | "error"> => {
66
try {
77
const response = await fetch(
88
`${API_URL}/api/v1/validation/${validationId}`,
@@ -14,21 +14,32 @@ export const validateQrCode = async (
1414
}
1515
);
1616

17-
if (response.status === 200) {
18-
return true;
17+
if (!response.ok) {
18+
return "error";
1919
}
20-
return false;
20+
21+
let data: unknown;
22+
try {
23+
data = await response.json();
24+
} catch {
25+
return "error";
26+
}
27+
28+
const result = (data as { result?: string })?.result?.toUpperCase();
29+
if (result === "VALID") return "valid";
30+
if (result === "INVALID") return "invalid";
31+
return "error";
2132
} catch (error) {
2233
console.error("Validation error:", error);
23-
return false;
34+
return "error";
2435
}
2536
};
2637

2738
export type DomainItem = { id: number; domain: string };
2839

2940
export const getDomainList = async (): Promise<DomainItem[]> => {
3041
try {
31-
const response = await fetch(`${API_URL}/domains`, {
42+
const response = await fetch(`${API_URL}/api/v1/domains`, {
3243
method: "GET",
3344
headers: {
3445
"Content-Type": "application/json",

0 commit comments

Comments
 (0)