diff --git a/app/(admin)/categories/page.tsx b/app/(admin)/categories/page.tsx
index add903b..caba483 100644
--- a/app/(admin)/categories/page.tsx
+++ b/app/(admin)/categories/page.tsx
@@ -1440,16 +1440,34 @@ export default function CategoriesPage() {
pager.items.map((c) => {
const parent = categories.find((parentCat) => idsEqual(parentCat.category_id, c.parent_category_id));
const parentLabel = parent && !isRootParentId(c.parent_category_id) ? parent.name : '- Root -';
+ const isChild = Boolean(c.parent_category_id && !isRootParentId(c.parent_category_id));
+
return (
-
{visibleColumns.categoryName && (
-
-
-
+
+ {isChild && (
+ ↳
+ )}
+
+
- {c.name}
+
+
+ {c.name}
+
+ {!isChild ? (
+
+ Parent
+
+ ) : (
+
+ Sub
+
+ )}
+
{c.slug}
diff --git a/app/(admin)/coupons/page.tsx b/app/(admin)/coupons/page.tsx
index 98b22f5..1c19db6 100644
--- a/app/(admin)/coupons/page.tsx
+++ b/app/(admin)/coupons/page.tsx
@@ -728,3 +728,4 @@ export default function AdminCouponsPage() {
);
}
+
diff --git a/app/(admin)/orders/page.tsx b/app/(admin)/orders/page.tsx
index e6d0aa7..4f85117 100644
--- a/app/(admin)/orders/page.tsx
+++ b/app/(admin)/orders/page.tsx
@@ -186,6 +186,7 @@ export default function OrderIntelligencePage() {
const [categoriesList, setCategoriesList] = useState ([]);
const [brandsList, setBrandsList] = useState([]);
const [selectedCategoryId, setSelectedCategoryId] = useState('');
+ const [selectedSubCategoryId, setSelectedSubCategoryId] = useState('');
const [selectedBrandId, setSelectedBrandId] = useState('');
const [selectedProductId, setSelectedProductId] = useState('');
const [skuOptions, setSkuOptions] = useState([]);
@@ -354,31 +355,44 @@ export default function OrderIntelligencePage() {
};
const availableCategoriesOptions = useMemo(() => {
- if (categoriesList.length > 0) {
- return categoriesList.map((c) => ({
- value: c.category_id,
- label: c.name,
- }));
- }
- const map = new Map();
- productsList.forEach((p) => {
- if (p.category_id) {
- map.set(p.category_id, p.category_name || p.category?.name || 'Category');
- }
- });
- return Array.from(map.entries()).map(([id, name]) => ({ value: id, label: name }));
- }, [categoriesList, productsList]);
+ // Only return Root Parent Categories (parent_category_id is null/empty)
+ const roots = categoriesList.filter((c) => !c.parent_category_id);
+ const sourceList = roots.length > 0 ? roots : categoriesList;
+ return sourceList.map((c) => ({
+ value: c.category_id,
+ label: c.name,
+ }));
+ }, [categoriesList]);
+
+ const availableSubCategoriesOptions = useMemo(() => {
+ if (!selectedCategoryId) return [];
+ const subs = categoriesList.filter((c) => c.parent_category_id === selectedCategoryId);
+ if (subs.length === 0) return [];
+ return [
+ { value: '', label: 'All Sub-Categories' },
+ ...subs.map((s) => ({ value: s.category_id, label: s.name })),
+ ];
+ }, [categoriesList, selectedCategoryId]);
+
+ const activeCategoryIds = useMemo(() => {
+ if (!selectedCategoryId) return [];
+ if (selectedSubCategoryId) return [selectedSubCategoryId];
+ const childIds = categoriesList
+ .filter((c) => c.parent_category_id === selectedCategoryId)
+ .map((c) => c.category_id);
+ return [selectedCategoryId, ...childIds];
+ }, [categoriesList, selectedCategoryId, selectedSubCategoryId]);
const availableBrandsOptions = useMemo(() => {
- const filteredProducts = selectedCategoryId
- ? productsList.filter((p) => p.category_id === selectedCategoryId)
+ const filteredProducts = activeCategoryIds.length > 0
+ ? productsList.filter((p) => activeCategoryIds.includes(p.category_id))
: productsList;
const brandIdsInFilteredProducts = new Set(filteredProducts.map((p) => p.brand_id).filter(Boolean));
if (brandsList.length > 0) {
return brandsList
- .filter((b) => !selectedCategoryId || brandIdsInFilteredProducts.has(b.brand_id))
+ .filter((b) => activeCategoryIds.length === 0 || brandIdsInFilteredProducts.has(b.brand_id))
.map((b) => ({
value: b.brand_id,
label: b.name,
@@ -392,12 +406,12 @@ export default function OrderIntelligencePage() {
}
});
return Array.from(map.entries()).map(([id, name]) => ({ value: id, label: name }));
- }, [brandsList, productsList, selectedCategoryId]);
+ }, [brandsList, productsList, activeCategoryIds]);
const availableProductsOptions = useMemo(() => {
let filtered = productsList;
- if (selectedCategoryId) {
- filtered = filtered.filter((p) => p.category_id === selectedCategoryId);
+ if (activeCategoryIds.length > 0) {
+ filtered = filtered.filter((p) => activeCategoryIds.includes(p.category_id));
}
if (selectedBrandId) {
filtered = filtered.filter((p) => p.brand_id === selectedBrandId);
@@ -406,7 +420,7 @@ export default function OrderIntelligencePage() {
value: p.product_id,
label: p.name,
}));
- }, [productsList, selectedCategoryId, selectedBrandId]);
+ }, [productsList, activeCategoryIds, selectedBrandId]);
const availableVariantsForProduct = useMemo(() => {
if (!selectedProductId) return [];
@@ -656,6 +670,7 @@ export default function OrderIntelligencePage() {
setBuyerPhone('');
setShippingAddress('');
setSelectedCategoryId('');
+ setSelectedSubCategoryId('');
setSelectedBrandId('');
setSelectedProductId('');
setTempSkuId('');
@@ -1383,6 +1398,7 @@ export default function OrderIntelligencePage() {
value={selectedCategoryId}
onChange={(value) => {
setSelectedCategoryId(value);
+ setSelectedSubCategoryId('');
setSelectedBrandId('');
setSelectedProductId('');
setTempSkuId('');
@@ -1395,6 +1411,45 @@ export default function OrderIntelligencePage() {
placeholder="Select Category"
/>
+ {availableSubCategoriesOptions.length > 0 ? (
+
+
+ {
+ setSelectedSubCategoryId(value);
+ setSelectedBrandId('');
+ setSelectedProductId('');
+ setTempSkuId('');
+ setTempPrice(0);
+ }}
+ options={availableSubCategoriesOptions}
+ placeholder="All Sub-Categories"
+ />
+
+ ) : (
+
+
+ {
+ setSelectedBrandId(value);
+ setSelectedProductId('');
+ setTempSkuId('');
+ setTempPrice(0);
+ }}
+ options={[
+ { value: '', label: !selectedCategoryId ? 'Select Category first' : 'Select Brand' },
+ ...availableBrandsOptions,
+ ]}
+ placeholder={!selectedCategoryId ? 'Select Category first' : 'Select Brand'}
+ />
+
+ )}
+
+
+ {availableSubCategoriesOptions.length > 0 && (
-
+ )}
|