diff --git a/src/app/admin/categories/page.tsx b/src/app/admin/categories/page.tsx index 7850144..1ca4ff4 100644 --- a/src/app/admin/categories/page.tsx +++ b/src/app/admin/categories/page.tsx @@ -8,103 +8,16 @@ 'use client' import { useState, useEffect, useCallback } from 'react' -import { PencilSimple, Plus, TrashSimple } from '@phosphor-icons/react' +import { Plus } from '@phosphor-icons/react' import { AdminLayout } from '@/components/admin/admin-layout' import { ErrorAlert } from '@/components/error-alert' +import { CategoryRow } from '@/components/admin/categories/category-row' +import { CategoryForm } from '@/components/admin/categories/category-form' +import type { EditingCategory } from '@/components/admin/categories/category-form' import { getCategories, createCategory, updateCategory, deleteCategory } from '@/lib/api/client' -import { cn } from '@/lib/utils' -import type { CategoryTreeNode, MaturityRating } from '@/lib/api/types' +import type { CategoryTreeNode } from '@/lib/api/types' import { useAuth } from '@/hooks/use-auth' -const MATURITY_LABELS: Record = { - safe: 'Safe', - mature: 'Mature', - adult: 'Adult', -} - -const MATURITY_COLORS: Record = { - safe: 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400', - mature: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400', - adult: 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400', -} - -interface EditingCategory { - id: string | null - name: string - slug: string - description: string - parentId: string | null - maturityRating: MaturityRating -} - -function CategoryRow({ - category, - depth, - onEdit, - onDelete, -}: { - category: CategoryTreeNode - depth: number - onEdit: (cat: CategoryTreeNode) => void - onDelete: (id: string) => void -}) { - return ( - <> -
0 && 'ml-6' - )} - > -
-
-

{category.name}

- {category.description && ( -

{category.description}

- )} -
-
-
- - {MATURITY_LABELS[category.maturityRating]} - - - -
-
- {category.children.map((child) => ( - - ))} - - ) -} - export default function AdminCategoriesPage() { const { getAccessToken } = useAuth() const [categories, setCategories] = useState([]) @@ -214,87 +127,15 @@ export default function AdminCategoriesPage() { {actionError && setActionError(null)} />} - {/* Edit form */} {editing && ( -
-

- {editing.id ? 'Edit Category' : 'New Category'} -

-
-
- - setEditing({ ...editing, name: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground" - /> -
-
- - setEditing({ ...editing, slug: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground" - /> -
-
- -