diff options
author | 2024-08-25 04:03:35 +0100 | |
---|---|---|
committer | 2024-08-25 04:03:35 +0100 | |
commit | 79441282fb751553ffbd7af6145bb4a427f1723c (patch) | |
tree | 21db9b9fdf6f4a104793c5f74ca1798ada4c248d | |
parent | Update themes (diff) |
Add API module for templates
-rw-r--r-- | thallium-frontend/src/api/templates.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/thallium-frontend/src/api/templates.ts b/thallium-frontend/src/api/templates.ts new file mode 100644 index 0000000..d60260d --- /dev/null +++ b/thallium-frontend/src/api/templates.ts @@ -0,0 +1,38 @@ +import { get } from "./client"; +import store from "../store"; + +export interface Variant { + variant_id: number; + name: string; + size: string; + colour?: string; + colour_code?: string; + colour_code2?: string; + price: string; + last_synced: string; +} + +export interface Template { + template_id: number; + title: string; + product_id: number; + mockup_file_url: string; + last_synced: string; + variants?: Variant[]; +} + +export const getTemplates = async (withVariants: boolean): Promise<Template[]> => { + /* TODO: Handle lacking authorization */ + + const token = store.getState().authorization.voucherToken; + + if (!token) { + throw new Error("No token available"); + }; + + return await get(`/templates/?with_variants=${withVariants.toString()}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) as unknown as Template[]; +}; |