DONE: add customer pages, implement auth on teller page

This commit is contained in:
ISMAIL MASSERAN
2026-07-21 10:24:14 +08:00
parent 3189e3a1e3
commit a671f7ad5c
48 changed files with 5627 additions and 273 deletions
+82
View File
@@ -0,0 +1,82 @@
import { SERVER_URL } from "./constants";
export type Tenant = {
id: number;
code: string;
name: string;
welcomeMessage: string;
font: string | null;
logo?: { id: number; base64Logo: string | null } | null;
};
export type Branch = {
id: number;
name: string;
tellerStations: { id: number; name: string }[];
};
export type Service = {
id: number;
name: string;
};
export type Ticket = {
id: number;
number: string;
createdAt: string;
service: Service;
branch: Branch;
station: { id: number; name: string } | null;
};
export type TicketResponse = {
ticket: Ticket;
stations: { id: number; name: string }[];
};
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${SERVER_URL}${path}`, {
...init,
headers: {
"Content-Type": "application/json",
...(init?.headers ?? {}),
},
});
if (!response.ok) {
throw new Error(`Request failed (${response.status}) for ${path}`);
}
return response.json() as Promise<T>;
}
export function getTenant(code: string) {
return request<Tenant>(`/api/v1/tenants/${encodeURIComponent(code)}`);
}
export function getBranches(tenantCode: string) {
return request<Branch[]>(
`/api/v1/branches/${encodeURIComponent(tenantCode)}`
);
}
export function getBranchServices(tenantCode: string, branchId: number) {
return request<Service[]>(
`/api/v1/branches/${encodeURIComponent(tenantCode)}/${branchId}/services`
);
}
export function createTicket(input: {
branchId: number;
serviceId: number;
deviceToken: string;
}) {
return request<TicketResponse>("/api/v1/tickets", {
method: "POST",
body: JSON.stringify(input),
});
}
export function getTicketById(ticketId: number | string) {
return request<Ticket>(`/api/v1/tickets/${ticketId}`);
}
+4
View File
@@ -0,0 +1,4 @@
export const SERVER_URL =
process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8080";
export const DEVICE_TOKEN_KEY = "qms_device_token";
+20
View File
@@ -0,0 +1,20 @@
import { DEVICE_TOKEN_KEY } from "./constants";
export function getDeviceToken(): string {
if (typeof window === "undefined") {
return "";
}
const existing = window.localStorage.getItem(DEVICE_TOKEN_KEY);
if (existing) {
return existing;
}
const token =
typeof crypto !== "undefined" && "randomUUID" in crypto
? crypto.randomUUID()
: `web-${Date.now()}-${Math.random().toString(36).slice(2)}`;
window.localStorage.setItem(DEVICE_TOKEN_KEY, token);
return token;
}