Add a static images manager and polish dashboard layout and fonts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
e79211e3cd
commit
b9024ad77a
@@ -0,0 +1,70 @@
|
||||
import { apiRequest } from '../lib/api'
|
||||
import { getActiveBusinessId } from '../lib/businessContext'
|
||||
import type {
|
||||
CreateWebsiteStaticImageSlotPayload,
|
||||
UpdateWebsiteStaticImageSlotPayload,
|
||||
WebsiteStaticImageItem,
|
||||
WebsiteStaticImageSlotsListResponse,
|
||||
WebsiteStaticImageSlot,
|
||||
} from '../types/websiteStaticImage'
|
||||
|
||||
function businessPath(suffix = '') {
|
||||
const businessId = getActiveBusinessId()
|
||||
if (!businessId) {
|
||||
throw new Error('No active business selected. Please sign in again.')
|
||||
}
|
||||
return `/businesses/${businessId}/website/static-images${suffix}`
|
||||
}
|
||||
|
||||
export async function listWebsiteStaticImageSlots(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
signal?: AbortSignal,
|
||||
) {
|
||||
return apiRequest<WebsiteStaticImageSlotsListResponse>(
|
||||
`${businessPath()}?page=${page}&pageSize=${pageSize}`,
|
||||
{ auth: true, signal },
|
||||
)
|
||||
}
|
||||
|
||||
export async function createWebsiteStaticImageSlot(
|
||||
payload: CreateWebsiteStaticImageSlotPayload,
|
||||
) {
|
||||
return apiRequest<{ message: string; slot: WebsiteStaticImageSlot }>(businessPath(), {
|
||||
method: 'POST',
|
||||
auth: true,
|
||||
body: payload,
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateWebsiteStaticImageSlot(
|
||||
slotId: string,
|
||||
payload: UpdateWebsiteStaticImageSlotPayload,
|
||||
) {
|
||||
return apiRequest<{ message: string; slot: WebsiteStaticImageSlot }>(
|
||||
businessPath(`/${slotId}`),
|
||||
{
|
||||
method: 'PATCH',
|
||||
auth: true,
|
||||
body: payload,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export async function deleteWebsiteStaticImageSlot(slotId: string) {
|
||||
return apiRequest<{ message: string }>(businessPath(`/${slotId}`), {
|
||||
method: 'DELETE',
|
||||
auth: true,
|
||||
})
|
||||
}
|
||||
|
||||
export function staticImageItemsToPayload(images: WebsiteStaticImageItem[]) {
|
||||
return images.map((image) => ({
|
||||
imageMediaId: image.imageMediaId,
|
||||
sortOrder: image.sortOrder,
|
||||
...(image.titleFa || image.title ? { titleFa: image.titleFa || image.title || undefined } : {}),
|
||||
...(image.titleEn ? { titleEn: image.titleEn } : {}),
|
||||
...(image.subtext ? { subtext: image.subtext } : {}),
|
||||
...(image.linkUrl ? { linkUrl: image.linkUrl } : {}),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user