diff --git a/src/features/categories/pages/NewCategory.tsx b/src/features/categories/pages/NewCategory.tsx index 9380d59..2cdd110 100644 --- a/src/features/categories/pages/NewCategory.tsx +++ b/src/features/categories/pages/NewCategory.tsx @@ -113,8 +113,11 @@ export default function NewCategory() { }, [isEdit, id, categories, parentIdParam]); const allowedParentOptions = useMemo(() => { - if (!isEdit) return categories; - return categories.filter((cat) => cat.id !== id && !cat.path?.startsWith(categories.find(c => c.id === id)?.path + "/")); + const validCategories = Array.isArray(categories) ? categories.filter((cat) => cat && cat.id) : []; + if (!isEdit) return validCategories; + const currentCat = validCategories.find((c) => c.id === id); + const currentPath = currentCat?.path || ""; + return validCategories.filter((cat) => cat.id !== id && (!currentPath || !cat.path?.startsWith(currentPath + "/"))); }, [categories, isEdit, id]); return ( @@ -204,16 +207,16 @@ export default function NewCategory() { name="parentId" value={formik.values.parentId} onChange={formik.handleChange} - disabled={!isEdit} // Disabled (Read-only) during creation, enabled during Edit + disabled={Boolean(parentIdParam)} > - {allowedParentOptions.map((cat) => ( + {allowedParentOptions.filter(Boolean).map((cat) => ( ))} - {!isEdit && ( + {!isEdit && Boolean(parentIdParam) && (

Locked to parent context. Click inline tree actions to create subcategories.