This commit is contained in:
Iliyan Angelov
2025-11-18 18:35:46 +02:00
parent a1bd576540
commit ab832f851b
26 changed files with 8878 additions and 355 deletions

View File

@@ -35,6 +35,8 @@ export type * from './promotionService';
export { default as reportService } from './reportService';
export { default as dashboardService } from './dashboardService';
export { default as auditService } from './auditService';
export { default as pageContentService } from './pageContentService';
export type { CustomerDashboardStats, CustomerDashboardResponse } from './dashboardService';
export type * from './reportService';
export type * from './auditService';
export type * from './pageContentService';

View File

@@ -0,0 +1,168 @@
import apiClient from './apiClient';
export type PageType = 'home' | 'contact' | 'about' | 'footer' | 'seo';
export interface PageContent {
id?: number;
page_type: PageType;
title?: string;
subtitle?: string;
description?: string;
content?: string;
meta_title?: string;
meta_description?: string;
meta_keywords?: string;
og_title?: string;
og_description?: string;
og_image?: string;
canonical_url?: string;
contact_info?: {
phone?: string;
email?: string;
address?: string;
};
map_url?: string;
social_links?: {
facebook?: string;
twitter?: string;
instagram?: string;
linkedin?: string;
youtube?: string;
};
footer_links?: {
quick_links?: Array<{ label: string; url: string }>;
support_links?: Array<{ label: string; url: string }>;
};
hero_title?: string;
hero_subtitle?: string;
hero_image?: string;
story_content?: string;
values?: Array<{ icon?: string; title: string; description: string }>;
features?: Array<{ icon?: string; title: string; description: string }>;
is_active?: boolean;
created_at?: string;
updated_at?: string;
}
export interface PageContentResponse {
status: string;
data: {
page_content?: PageContent | null;
page_contents?: PageContent[];
};
message?: string;
}
export interface UpdatePageContentData {
title?: string;
subtitle?: string;
description?: string;
content?: string;
meta_title?: string;
meta_description?: string;
meta_keywords?: string;
og_title?: string;
og_description?: string;
og_image?: string;
canonical_url?: string;
contact_info?: {
phone?: string;
email?: string;
address?: string;
};
map_url?: string;
social_links?: {
facebook?: string;
twitter?: string;
instagram?: string;
linkedin?: string;
youtube?: string;
};
footer_links?: {
quick_links?: Array<{ label: string; url: string }>;
support_links?: Array<{ label: string; url: string }>;
};
hero_title?: string;
hero_subtitle?: string;
hero_image?: string;
story_content?: string;
values?: Array<{ icon?: string; title: string; description: string }>;
features?: Array<{ icon?: string; title: string; description: string }>;
is_active?: boolean;
}
const pageContentService = {
/**
* Get all page contents
*/
getAllPageContents: async (): Promise<PageContentResponse> => {
const response = await apiClient.get<PageContentResponse>('/page-content');
return response.data;
},
/**
* Get content for a specific page
*/
getPageContent: async (pageType: PageType): Promise<PageContentResponse> => {
const response = await apiClient.get<PageContentResponse>(`/page-content/${pageType}`);
return response.data;
},
/**
* Update page content
*/
updatePageContent: async (
pageType: PageType,
data: UpdatePageContentData
): Promise<PageContentResponse> => {
// Convert objects to JSON strings for fields that need it
const updateData: any = { ...data };
// Handle contact_info - ensure it has all required fields
if (data.contact_info) {
const contactInfo = {
phone: data.contact_info.phone || '',
email: data.contact_info.email || '',
address: data.contact_info.address || '',
};
updateData.contact_info = contactInfo; // Send as object, backend will convert to JSON
}
// Handle social_links - ensure it has all required fields
if (data.social_links) {
const socialLinks = {
facebook: data.social_links.facebook || '',
twitter: data.social_links.twitter || '',
instagram: data.social_links.instagram || '',
linkedin: data.social_links.linkedin || '',
youtube: data.social_links.youtube || '',
};
updateData.social_links = socialLinks; // Send as object, backend will convert to JSON
}
// Handle footer_links
if (data.footer_links) {
updateData.footer_links = {
quick_links: data.footer_links.quick_links || [],
support_links: data.footer_links.support_links || [],
};
}
// Handle values and features arrays
if (data.values) {
updateData.values = data.values; // Send as array, backend will convert to JSON
}
if (data.features) {
updateData.features = data.features; // Send as array, backend will convert to JSON
}
const response = await apiClient.put<PageContentResponse>(
`/page-content/${pageType}`,
updateData
);
return response.data;
},
};
export default pageContentService;