Merge branch 'main' of https://git.igny8.com/salman/igny8
This commit is contained in:
@@ -24,9 +24,7 @@ import {
|
||||
fetchTasks,
|
||||
fetchContent,
|
||||
fetchContentImages,
|
||||
// TODO: Stage 3/4 - Add when taxonomy and attribute endpoints are implemented
|
||||
// fetchTaxonomies,
|
||||
// fetchAttributes
|
||||
fetchTaxonomies,
|
||||
} from "../../services/api";
|
||||
import { useSiteStore } from "../../store/siteStore";
|
||||
import { useSectorStore } from "../../store/sectorStore";
|
||||
@@ -85,11 +83,11 @@ export default function WriterDashboard() {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// TODO: Stage 3/4 - Re-enable when taxonomy and attribute endpoints are implemented
|
||||
const [tasksRes, contentRes, imagesRes] = await Promise.all([
|
||||
const [tasksRes, contentRes, imagesRes, taxonomiesRes] = await Promise.all([
|
||||
fetchTasks({ page_size: 1000, sector_id: activeSector?.id }),
|
||||
fetchContent({ page_size: 1000, sector_id: activeSector?.id }),
|
||||
fetchContentImages({ sector_id: activeSector?.id }),
|
||||
fetchTaxonomies({ page_size: 1000, sector_id: activeSector?.id }),
|
||||
]);
|
||||
|
||||
const tasks = tasksRes.results || [];
|
||||
@@ -145,9 +143,10 @@ export default function WriterDashboard() {
|
||||
const contentThisMonth = Math.floor(content.length * 0.7);
|
||||
const publishRate = content.length > 0 ? Math.round((published / content.length) * 100) : 0;
|
||||
|
||||
// TODO: Stage 3/4 - Re-enable when taxonomy and attribute endpoints are implemented
|
||||
const taxonomyCount = 0; // taxonomiesRes.results?.length || 0
|
||||
const attributeCount = 0; // attributesRes.results?.length || 0
|
||||
const taxonomies = taxonomiesRes.results || [];
|
||||
const taxonomyCount = taxonomies.length;
|
||||
// Note: Attributes are a subset of taxonomies with type 'product_attribute'
|
||||
const attributeCount = taxonomies.filter(t => t.taxonomy_type === 'product_attribute').length;
|
||||
|
||||
setStats({
|
||||
tasks: {
|
||||
|
||||
@@ -2147,6 +2147,97 @@ export async function validateContent(id: number): Promise<{
|
||||
});
|
||||
}
|
||||
|
||||
// Content Taxonomy API
|
||||
export interface ContentTaxonomy {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
taxonomy_type: 'category' | 'tag' | 'product_category' | 'product_tag' | 'product_attribute' | 'cluster';
|
||||
external_taxonomy?: string | null;
|
||||
external_id?: string | null;
|
||||
parent_id?: number | null;
|
||||
description?: string | null;
|
||||
count?: number;
|
||||
site_id: number;
|
||||
sector_id?: number | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface ContentTaxonomyFilters {
|
||||
taxonomy_type?: string;
|
||||
search?: string;
|
||||
site_id?: number;
|
||||
sector_id?: number;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
ordering?: string;
|
||||
}
|
||||
|
||||
export interface ContentTaxonomyResponse {
|
||||
count: number;
|
||||
next: string | null;
|
||||
previous: string | null;
|
||||
results: ContentTaxonomy[];
|
||||
}
|
||||
|
||||
export async function fetchTaxonomies(filters: ContentTaxonomyFilters = {}): Promise<ContentTaxonomyResponse> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
// Automatically add active site filter if not explicitly provided
|
||||
if (!filters.site_id) {
|
||||
const activeSiteId = getActiveSiteId();
|
||||
if (activeSiteId) {
|
||||
filters.site_id = activeSiteId;
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically add active sector filter if not explicitly provided
|
||||
if (filters.sector_id === undefined) {
|
||||
const activeSectorId = getActiveSectorId();
|
||||
if (activeSectorId !== null && activeSectorId !== undefined) {
|
||||
filters.sector_id = activeSectorId;
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.search) params.append('search', filters.search);
|
||||
if (filters.taxonomy_type) params.append('taxonomy_type', filters.taxonomy_type);
|
||||
if (filters.site_id) params.append('site_id', filters.site_id.toString());
|
||||
if (filters.sector_id) params.append('sector_id', filters.sector_id.toString());
|
||||
if (filters.page) params.append('page', filters.page.toString());
|
||||
if (filters.page_size !== undefined && filters.page_size !== null) {
|
||||
params.append('page_size', filters.page_size.toString());
|
||||
}
|
||||
if (filters.ordering) params.append('ordering', filters.ordering);
|
||||
|
||||
const queryString = params.toString();
|
||||
return fetchAPI(`/v1/writer/taxonomies/${queryString ? `?${queryString}` : ''}`);
|
||||
}
|
||||
|
||||
export async function fetchTaxonomyById(id: number): Promise<ContentTaxonomy> {
|
||||
return fetchAPI(`/v1/writer/taxonomies/${id}/`);
|
||||
}
|
||||
|
||||
export async function createTaxonomy(data: Partial<ContentTaxonomy>): Promise<ContentTaxonomy> {
|
||||
return fetchAPI('/v1/writer/taxonomies/', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateTaxonomy(id: number, data: Partial<ContentTaxonomy>): Promise<ContentTaxonomy> {
|
||||
return fetchAPI(`/v1/writer/taxonomies/${id}/`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTaxonomy(id: number): Promise<void> {
|
||||
return fetchAPI(`/v1/writer/taxonomies/${id}/`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// Site Builder API
|
||||
export interface SiteBlueprint {
|
||||
id: number;
|
||||
|
||||
Reference in New Issue
Block a user