fixed all admin email pages. added admin user info and button on builder page to route to admin page.
CI / test (push) Successful in 5s

This commit is contained in:
2026-01-26 14:58:56 -05:00
parent fb2effca47
commit 77c31ae4f9
15 changed files with 393 additions and 214 deletions
+31 -31
View File
@@ -17,64 +17,64 @@ export interface UpdateEmailRequestDto {
status?: string;
}
const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL || '';
export async function fetchEmailRequests(): Promise<EmailRequest[]> {
const response = await fetch("/api/admin/email", { cache: "no-store" });
export async function fetchEmailRequests(token: string): Promise<EmailRequest[]> {
const response = await fetch(`${API_BASE}/api/email`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
throw new Error(`Failed to fetch email requests: ${response.statusText}`);
}
return response.json();
const data = (await response.json()) as unknown;
if (Array.isArray(data)) return data as EmailRequest[];
const wrapped = data as { data?: unknown; content?: unknown };
if (Array.isArray(wrapped.data)) return wrapped.data as EmailRequest[];
if (Array.isArray(wrapped.content)) return wrapped.content as EmailRequest[];
return [];
}
export async function createEmailRequest(token: string, data: CreateEmailRequestDto): Promise<EmailRequest> {
const response = await fetch(`${API_BASE}/api/email`, {
method: 'POST',
export async function createEmailRequest(
data: CreateEmailRequestDto
): Promise<EmailRequest> {
const response = await fetch("/api/admin/email", {
method: "POST",
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Failed to create email request: ${response.statusText}`);
}
return response.json();
}
export async function updateEmailRequest(token: string, id: number, data: UpdateEmailRequestDto): Promise<EmailRequest> {
const response = await fetch(`${API_BASE}/api/email/${id}`, {
method: 'PUT',
export async function updateEmailRequest(
id: number,
data: UpdateEmailRequestDto
): Promise<EmailRequest> {
const response = await fetch(`/api/admin/email/${id}`, {
method: "PUT",
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Failed to update email request: ${response.statusText}`);
}
return response.json();
}
export async function deleteEmailRequest(token: string, id: number): Promise<void> {
const response = await fetch(`${API_BASE}/api/email/${id}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`,
},
export async function deleteEmailRequest(id: number): Promise<void> {
const response = await fetch(`/api/admin/email/${id}`, {
method: "DELETE",
});
if (!response.ok) {
throw new Error(`Failed to delete email request: ${response.statusText}`);
}