fix(build): restore missing admin imports and api client

This commit is contained in:
Ashwin Kumar 2026-04-10 19:57:23 +02:00
parent e416f2fe8f
commit ad9be1ab15
2 changed files with 53 additions and 3 deletions

50
src/lib/api.ts Normal file
View file

@ -0,0 +1,50 @@
type ApiRequestOptions = {
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
body?: unknown;
headers?: HeadersInit;
};
type ApiResponse<T = any> = {
data: T;
status: number;
headers: Headers;
};
const API_BASE = "";
async function request<T = any>(path: string, options: ApiRequestOptions = {}): Promise<ApiResponse<T>> {
const headers: HeadersInit = {
Accept: "application/json",
...options.headers,
};
const init: RequestInit = {
method: options.method ?? "GET",
credentials: "include",
headers,
};
if (options.body !== undefined) {
init.body = JSON.stringify(options.body);
(init.headers as Record<string, string>)["Content-Type"] = "application/json";
}
const res = await fetch(`${API_BASE}${path}`, init);
const raw = await res.text();
const data = raw ? JSON.parse(raw) : null;
if (!res.ok) {
const message = (data && (data.message || data.error)) || `Request failed (${res.status})`;
throw new Error(message);
}
return { data: data as T, status: res.status, headers: res.headers };
}
export const api = {
get: <T = any>(path: string, headers?: HeadersInit) => request<T>(path, { method: "GET", headers }),
post: <T = any>(path: string, body?: unknown, headers?: HeadersInit) => request<T>(path, { method: "POST", body, headers }),
put: <T = any>(path: string, body?: unknown, headers?: HeadersInit) => request<T>(path, { method: "PUT", body, headers }),
patch: <T = any>(path: string, body?: unknown, headers?: HeadersInit) => request<T>(path, { method: "PATCH", body, headers }),
delete: <T = any>(path: string, headers?: HeadersInit) => request<T>(path, { method: "DELETE", headers }),
};

View file

@ -1,6 +1,6 @@
import { createResource, createSignal, Show, For } from "solid-js";
import { useNavigate } from "@solidjs/router";
import AdminLayout from "~/components/AdminLayout";
import AdminShell from "~/components/AdminShell";
import { api } from "~/lib/api";
interface EmailTemplate {
@ -70,7 +70,7 @@ export default function EmailManagementPage() {
};
return (
<AdminLayout>
<AdminShell>
<div class="p-6">
<h1 class="text-2xl font-bold mb-6">📧 Email Management</h1>
@ -231,6 +231,6 @@ export default function EmailManagementPage() {
</div>
</div>
</div>
</AdminLayout>
</AdminShell>
);
}