fixing platform admin

This commit is contained in:
root
2026-05-06 22:58:23 -04:00
parent 695a7f7cc7
commit 750ae56a29
175 changed files with 31249 additions and 328 deletions
+115
View File
@@ -0,0 +1,115 @@
'use client'
const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:4000/api/v1'
export interface SavedCompany {
id: string
brand?: {
displayName: string
subdomain: string
logoUrl?: string | null
} | null
}
export interface RenterProfile {
id: string
firstName: string
lastName: string
email: string
phone?: string | null
preferredLocale?: string
preferredCurrency?: string
emailVerified?: boolean
savedCompanies?: SavedCompany[]
}
export interface RenterPreference {
notificationType: string
channel: string
enabled: boolean
}
export interface RenterNotification {
id: string
title: string
body: string
type: string
status: string
readAt: string | null
createdAt: string
}
export class RenterAuthError extends Error {
constructor(message = 'Authentication required') {
super(message)
this.name = 'RenterAuthError'
}
}
function getRenterToken() {
return window.localStorage.getItem('renter_token')
}
async function renterFetch<T>(path: string, init?: RequestInit): Promise<T> {
const token = getRenterToken()
if (!token) throw new RenterAuthError()
const res = await fetch(`${API_BASE}${path}`, {
...init,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
...(init?.headers ?? {}),
},
})
const json = await res.json().catch(() => null)
if (res.status === 401) {
window.localStorage.removeItem('renter_token')
throw new RenterAuthError()
}
if (!res.ok) throw new Error(json?.message ?? 'Request failed')
return (json?.data ?? json) as T
}
export function clearRenterSession() {
window.localStorage.removeItem('renter_token')
}
export function loadRenterProfile() {
return renterFetch<RenterProfile>('/auth/renter/me')
}
export function updateRenterProfile(body: Partial<RenterProfile>) {
return renterFetch<RenterProfile>('/auth/renter/me', {
method: 'PATCH',
body: JSON.stringify(body),
})
}
export function loadRenterNotifications() {
return renterFetch<RenterNotification[]>('/notifications/renter')
}
export function markRenterNotificationRead(id: string) {
return renterFetch<{ success: boolean }>(`/notifications/renter/${id}/read`, {
method: 'POST',
})
}
export function markAllRenterNotificationsRead() {
return renterFetch<{ success: boolean }>('/notifications/renter/read-all', {
method: 'POST',
})
}
export function loadRenterPreferences() {
return renterFetch<RenterPreference[]>('/notifications/renter/preferences')
}
export function updateRenterPreferences(body: RenterPreference[]) {
return renterFetch<{ success: boolean }>('/notifications/renter/preferences', {
method: 'PATCH',
body: JSON.stringify(body),
})
}