diff --git a/src/features/price-type/lib/api.ts b/src/features/price-type/lib/api.ts new file mode 100644 index 0000000..c288a3c --- /dev/null +++ b/src/features/price-type/lib/api.ts @@ -0,0 +1,18 @@ +import httpClient from "@/shared/config/api/httpClient"; +import { API_URLS } from "@/shared/config/api/URLs"; +import type { AxiosResponse } from "axios"; +import type { PriceTypeResponse } from "./type"; + +const price_type_api = { + async list(): Promise> { + const res = await httpClient.get(API_URLS.PriceTypeList); + return res; + }, + + async import() { + const res = await httpClient.post(API_URLS.PriceTypeImport); + return res; + }, +}; + +export default price_type_api; diff --git a/src/features/price-type/lib/type.ts b/src/features/price-type/lib/type.ts new file mode 100644 index 0000000..8573905 --- /dev/null +++ b/src/features/price-type/lib/type.ts @@ -0,0 +1,10 @@ +export interface PriceTypeResponse { + id: number; + created_at: string; + name: string; + code: string; + with_card: string; + state: string; + price_type_kind: string; + currency_code: string; +} diff --git a/src/features/price-type/ui/TablePriceType.tsx b/src/features/price-type/ui/TablePriceType.tsx new file mode 100644 index 0000000..2881387 --- /dev/null +++ b/src/features/price-type/ui/TablePriceType.tsx @@ -0,0 +1,72 @@ +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/shared/ui/table"; +import { Loader2 } from "lucide-react"; +import type { PriceTypeResponse } from "../lib/type"; + +interface Props { + data: PriceTypeResponse[] | []; + isLoading: boolean; + isError: boolean; +} + +const TablePriceType = ({ data, isError, isLoading }: Props) => { + return ( +
+ {isLoading && ( +
+ + + +
+ )} + + {isError && ( +
+ + Ma'lumotlarni olishda xatolik yuz berdi. + +
+ )} + + {!isError && !isLoading && ( + + + + ID + Nomi + Kodi + Valyuta kodi + + + + + {data.map((d, index) => ( + + {index + 1} + {d.name} + {d.code} + {d.currency_code} + + ))} + + {data.length === 0 && ( + + + Hech qanday tuman topilmadi + + + )} + +
+ )} +
+ ); +}; + +export default TablePriceType; diff --git a/src/features/price-type/ui/priceTypeList.tsx b/src/features/price-type/ui/priceTypeList.tsx new file mode 100644 index 0000000..b398bca --- /dev/null +++ b/src/features/price-type/ui/priceTypeList.tsx @@ -0,0 +1,61 @@ +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import price_type_api from "../lib/api"; +import TablePriceType from "./TablePriceType"; +import { Button } from "@/shared/ui/button"; +import { toast } from "sonner"; +import type { AxiosError } from "axios"; + +const PriceTypeList = () => { + const queryClient = useQueryClient(); + const { mutate } = useMutation({ + mutationFn: () => price_type_api.import(), + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ["price_type"] }); + toast.success("Narx turlari import qilindi", { + richColors: true, + position: "top-center", + }); + }, + onError: (err: AxiosError) => { + const errData = (err.response?.data as { data: string }).data; + const errMessage = (err.response?.data as { message: string }).message; + toast.error(errData || errMessage || "Xatolik yuz berdi", { + richColors: true, + position: "top-center", + }); + }, + }); + + const { data, isLoading, isError } = useQuery({ + queryKey: ["price_type"], + queryFn: () => price_type_api.list(), + select(data) { + return data.data; + }, + }); + + return ( +
+
+

Narx turlari

+ +
+ +
+
+ + +
+ ); +}; + +export default PriceTypeList; diff --git a/src/pages/PriceType.tsx b/src/pages/PriceType.tsx new file mode 100644 index 0000000..ca7875a --- /dev/null +++ b/src/pages/PriceType.tsx @@ -0,0 +1,12 @@ +import PriceTypeList from "@/features/price-type/ui/priceTypeList"; +import SidebarLayout from "@/SidebarLayout"; + +const PriceType = () => { + return ( + + + + ); +}; + +export default PriceType; diff --git a/src/providers/routing/AppRoutes.tsx b/src/providers/routing/AppRoutes.tsx index 71128c0..bf851f6 100644 --- a/src/providers/routing/AppRoutes.tsx +++ b/src/providers/routing/AppRoutes.tsx @@ -4,6 +4,7 @@ import Categories from "@/pages/Categories"; import Faq from "@/pages/Faq"; import HomePage from "@/pages/Home"; import Orders from "@/pages/Orders"; +import PriceType from "@/pages/PriceType"; import Product from "@/pages/Product"; import Questionnaire from "@/pages/Questionnaire"; import Units from "@/pages/Units"; @@ -58,6 +59,10 @@ const AppRouter = () => { path: "/dashboard/questionnaire", element: , }, + { + path: "/dashboard/price-type", + element: , + }, ]); return routes; diff --git a/src/shared/config/api/URLs.ts b/src/shared/config/api/URLs.ts index e98fede..bb0b785 100644 --- a/src/shared/config/api/URLs.ts +++ b/src/shared/config/api/URLs.ts @@ -41,4 +41,6 @@ export const API_URLS = { `${API_V}admin/category/${id}/upload_image/`, PasswordSet: (id: number | string) => `${API_V}admin/user/${id}/set_password/`, + PriceTypeList: `${API_V}shared/price_type/`, + PriceTypeImport: `${API_V}shared/price_type/`, }; diff --git a/src/widgets/sidebar-layout/index.tsx b/src/widgets/sidebar-layout/index.tsx index 8d673c5..862835a 100644 --- a/src/widgets/sidebar-layout/index.tsx +++ b/src/widgets/sidebar-layout/index.tsx @@ -1,4 +1,5 @@ import { + BanknoteIcon, CircleQuestionMark, FileText, FolderOpen, @@ -42,6 +43,11 @@ const items = [ url: "/dashboard/categories", icon: FolderOpen, }, + { + title: "Narx turlari", + url: "/dashboard/price-type", + icon: BanknoteIcon, + }, { title: "Birliklar", url: "/dashboard/units",