feat: manage homepage banner carousel
This commit is contained in:
@@ -59,6 +59,20 @@ export interface LearningPathInput {
|
||||
kind: 'trail' | 'formation';
|
||||
courseIds: string[];
|
||||
}
|
||||
export interface HomeBannerInput {
|
||||
kind: 'course' | 'custom';
|
||||
courseId: string | null;
|
||||
imageUrl: string | null;
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
export interface HomeBanner extends HomeBannerInput {
|
||||
id: string;
|
||||
position: number;
|
||||
courseTitle: string | null;
|
||||
courseDescription: string | null;
|
||||
courseImageUrl: string | null;
|
||||
}
|
||||
|
||||
interface Session {
|
||||
token: string;
|
||||
@@ -170,6 +184,8 @@ export const adminApi = {
|
||||
async createPath(input: LearningPathInput) { return apiRequest<{ data: LearningPath }>('/admin/paths', { method: 'POST', body: JSON.stringify(input) }); },
|
||||
async updatePath(pathId: string, input: LearningPathInput) { return apiRequest<{ data: LearningPath }>(`/admin/paths/${pathId}`, { method: 'PATCH', body: JSON.stringify(input) }); },
|
||||
async deletePath(pathId: string) { return apiRequest<void>(`/admin/paths/${pathId}`, { method: 'DELETE' }); },
|
||||
async homeBanners() { return apiRequest<{ data: HomeBanner[] }>('/admin/home-banners'); },
|
||||
async updateHomeBanners(banners: HomeBannerInput[]) { return apiRequest<{ data: HomeBanner[] }>('/admin/home-banners', { method: 'PUT', body: JSON.stringify({ banners }) }); },
|
||||
async homeConfiguration() { return apiRequest<{ data: { featuredCourseId: string | null; courseOrder: string[]; defaultCoverImageUrl: string | null; courses: Array<{ id: string; title: string; status: string }> } }>('/admin/home-configuration'); },
|
||||
async updateHomeConfiguration(input: { featuredCourseId: string | null; courseOrder: string[]; defaultCoverImageUrl: string | null }) { return apiRequest<{ data: typeof input }>('/admin/home-configuration', { method: 'PUT', body: JSON.stringify(input) }); },
|
||||
};
|
||||
|
||||
@@ -62,6 +62,22 @@ export type PublicLearningPath = {
|
||||
}>;
|
||||
};
|
||||
|
||||
export type PublicHomeBanner = {
|
||||
id: string;
|
||||
kind: 'course' | 'custom';
|
||||
courseId: string | null;
|
||||
imageUrl: string | null;
|
||||
title: string;
|
||||
description: string;
|
||||
position: number;
|
||||
courseTitle: string | null;
|
||||
courseDescription: string | null;
|
||||
courseImageUrl: string | null;
|
||||
coverImageZoom: number | null;
|
||||
coverImagePositionX: number | null;
|
||||
coverImagePositionY: number | null;
|
||||
};
|
||||
|
||||
const toAttachmentType = (kind: ApiAsset['kind']): AttachmentType => {
|
||||
if (kind === 'document') return 'doc';
|
||||
if (kind === 'archive') return 'zip';
|
||||
@@ -196,6 +212,11 @@ export const getLearningPaths = async (): Promise<PublicLearningPath[]> => {
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getHomeBanners = async (): Promise<PublicHomeBanner[]> => {
|
||||
const response = await apiRequest<{ data: PublicHomeBanner[] }>('/courses/home-banners');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getManagedCourses = async (): Promise<Course[]> => {
|
||||
const response = await apiRequest<{ data: ApiCourse[] }>('/manage/courses');
|
||||
return response.data.map(toCourse);
|
||||
|
||||
Reference in New Issue
Block a user