From 26c0c169a35fffe567f0256a17084012288c32a9 Mon Sep 17 00:00:00 2001 From: Xor290 Date: Sat, 20 Jun 2026 15:56:27 +0200 Subject: [PATCH] chore: build admin --- frontend-admin/src/api/api_admin.ts | 15 +++++++ frontend-admin/src/context/ThemeContext.tsx | 2 + .../src/screens/admin/CategoriesScreen.tsx | 41 ++++++++++++++++++- .../src/screens/admin/SettingsScreen.tsx | 3 +- 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/frontend-admin/src/api/api_admin.ts b/frontend-admin/src/api/api_admin.ts index bafe97d9..0f4d17e5 100644 --- a/frontend-admin/src/api/api_admin.ts +++ b/frontend-admin/src/api/api_admin.ts @@ -857,6 +857,7 @@ export interface Category { name: string; color: string; is_coming_soon: boolean; + position: number; created_at: string; } @@ -922,6 +923,20 @@ export const deleteCategoryAdmin = async ( } }; +export const reorderCategoriesAdmin = async ( + ids: number[], +): Promise<{ success: boolean; error?: string }> => { + try { + await apiClient.put(`${V2}/admin/protected/categories/reorder`, { ids }); + return { success: true }; + } catch (error: any) { + return { + success: false, + error: error.response?.data?.error || "Erreur", + }; + } +}; + // ============================================ // PARAMÈTRES GLOBAUX // ============================================ diff --git a/frontend-admin/src/context/ThemeContext.tsx b/frontend-admin/src/context/ThemeContext.tsx index fbc07d98..fc3b40b2 100644 --- a/frontend-admin/src/context/ThemeContext.tsx +++ b/frontend-admin/src/context/ThemeContext.tsx @@ -11,6 +11,7 @@ interface ThemeContextType { mode: ThemeMode; toggleTheme: () => void; isDark: boolean; + refreshColors: () => Promise; } const STORAGE_KEY = "@theme_mode"; @@ -71,6 +72,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) { mode, toggleTheme, isDark: mode === "dark", + refreshColors: fetchAdminColors, }; return ( diff --git a/frontend-admin/src/screens/admin/CategoriesScreen.tsx b/frontend-admin/src/screens/admin/CategoriesScreen.tsx index 5104a39a..1f930730 100644 --- a/frontend-admin/src/screens/admin/CategoriesScreen.tsx +++ b/frontend-admin/src/screens/admin/CategoriesScreen.tsx @@ -20,6 +20,7 @@ import { createCategoryAdmin, updateCategoryAdmin, deleteCategoryAdmin, + reorderCategoriesAdmin, } from "../../api/api_admin"; import type { Category } from "../../api/api_admin"; import LoadingSpinner from "../../components/ui/LoadingSpinner"; @@ -47,6 +48,7 @@ export default function CategoriesScreen() { const [hexInput, setHexInput] = useState("#7c3aed"); const [isComingSoon, setIsComingSoon] = useState(false); const [saving, setSaving] = useState(false); + const [reordering, setReordering] = useState(false); const { alert, showError, showSuccess, showConfirm, hideAlert } = useAlert(); const load = useCallback(async () => { @@ -144,6 +146,17 @@ export default function CategoriesScreen() { ); }; + const handleMove = async (index: number, direction: "up" | "down") => { + const newList = [...categories]; + const swapIndex = direction === "up" ? index - 1 : index + 1; + if (swapIndex < 0 || swapIndex >= newList.length) return; + [newList[index], newList[swapIndex]] = [newList[swapIndex], newList[index]]; + setCategories(newList); + setReordering(true); + await reorderCategoriesAdmin(newList.map((c) => c.id)); + setReordering(false); + }; + const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: colors.bgPrimary }, header: { @@ -189,6 +202,8 @@ export default function CategoriesScreen() { paddingVertical: 2, }, comingSoonBadgeText: { fontSize: fontSize.xs, color: colors.warning, fontWeight: "600" }, + orderBtns: { flexDirection: "column", alignItems: "center", marginRight: spacing.s }, + orderBtn: { padding: 2 }, actions: { flexDirection: "row", gap: spacing.s }, actionBtn: { padding: 8 }, overlay: { @@ -297,9 +312,33 @@ export default function CategoriesScreen() { ListEmptyComponent={ Aucune catégorie. Créez-en une ! } - renderItem={({ item }) => ( + renderItem={({ item, index }) => ( + + handleMove(index, "up")} + disabled={index === 0 || reordering} + style={styles.orderBtn} + > + + + handleMove(index, "down")} + disabled={index === categories.length - 1 || reordering} + style={styles.orderBtn} + > + + +