structure category product

This commit is contained in:
hamid zarghami
2026-01-24 09:24:18 +03:30
parent 2eba93984c
commit 2995bb86b4
12 changed files with 109 additions and 2 deletions
+5 -1
View File
@@ -4,7 +4,11 @@ export const Paths = {
},
product: {
list: '/product/list',
create: '/product/create'
create: '/product/create',
category: {
create: '/product/category/create',
list: '/product/category/list',
}
},
order: {
list: '/order/list'
+1 -1
View File
@@ -2,7 +2,7 @@ import axios from "axios";
import { getToken } from "./func";
const instance = axios.create({
baseURL: import.meta.env.VITE_API_URL || "http://localhost:3000/api",
baseURL: import.meta.env.VITE_API_BASE_URL || "http://localhost:3000/api",
timeout: 10000,
});
+11
View File
@@ -0,0 +1,11 @@
import { type FC } from 'react'
const ProductCategory: FC = () => {
return (
<div className='mt-5'>
<h1 className='text-lg font-light'>دسته بندی محصولات</h1>
</div>
)
}
export default ProductCategory
+29
View File
@@ -0,0 +1,29 @@
import { type FC } from 'react'
import { useGetCategory } from '../hooks/useProductData'
import Table from '@/components/Table'
import type { RowDataType } from '@/components/types/TableTypes'
import type { CategoryType } from '../types/Types'
const CategoryList: FC = () => {
const { data } = useGetCategory()
const column = [{
title: 'عنوان',
key: 'title',
}]
return (
<div className='mt-5'>
<h1 className='text-lg font-light'>دسته بندی محصولات</h1>
<Table
columns={column}
data={data?.data || [] as (CategoryType & RowDataType)[]}
/>
</div>
)
}
export default CategoryList
@@ -0,0 +1,9 @@
import { useQuery } from "@tanstack/react-query";
import * as api from "../service/ProductService";
export const useGetCategory = () => {
return useQuery({
queryKey: ["category"],
queryFn: api.getCategory,
});
};
@@ -0,0 +1,7 @@
import axios from "@/config/axios";
import { type CategoriesResponse } from "../types/Types";
export const getCategory = async () => {
const { data } = await axios.get<CategoriesResponse>("/admin/category");
return data;
};
+16
View File
@@ -0,0 +1,16 @@
import type { RowDataType } from "@/components/types/TableTypes";
import { type BaseResponse } from "@/shared/types/Types";
export interface CategoryType extends RowDataType {
avatarUrl: string | null;
children: CategoryType[];
createdAt: string;
deletedAt: string | null;
id: string;
isActive: boolean;
order: number | null;
parent: CategoryType | null;
title: string;
}
export type CategoriesResponse = BaseResponse<CategoryType[]>;
+6
View File
@@ -25,6 +25,8 @@ import CriticismsDetail from '@/pages/criticisms/Detail'
import LearningList from '@/pages/learning/List'
import LearningCreate from '@/pages/learning/Create'
import LearningCategory from '@/pages/learning/Category'
import CategoryList from '@/pages/product/category/List'
import CreateCategory from '@/pages/learning/components/CreateCategory'
const MainRouter: FC = () => {
return (
<div className='p-4 overflow-hidden'>
@@ -40,8 +42,12 @@ const MainRouter: FC = () => {
<Route path={Paths.perfomaInvoice.list} element={<ProformaInvoice />} />
<Route path={Paths.perfomaInvoice.detail + ':id'} element={<DetailPerfomaInvoice />} />
<Route path={Paths.requests.list} element={<RequestList />} />
<Route path={Paths.product.list} element={<ProductList />} />
<Route path={Paths.product.create} element={<CreateProduct />} />
<Route path={Paths.product.category.list} element={<CategoryList />} />
<Route path={Paths.product.category.create} element={<CreateCategory />} />
<Route path={Paths.order.list} element={<OrdersList />} />
<Route path={Paths.features.list} element={<FeaturesList />} />
<Route path={Paths.features.create} element={<CreateFeature />} />
+12
View File
@@ -2,3 +2,15 @@ export type SharedStoreType = {
openSidebar: boolean;
setOpenSidebar: (open: boolean) => void;
};
export interface BaseResponse<T> {
success: boolean;
statusCode: number;
data: T;
meta?: {
limit: number;
page: number;
total: number;
totalPages: number;
};
}