update
This commit is contained in:
18
src/features/price-type/lib/api.ts
Normal file
18
src/features/price-type/lib/api.ts
Normal file
@@ -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<AxiosResponse<PriceTypeResponse[]>> {
|
||||||
|
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;
|
||||||
10
src/features/price-type/lib/type.ts
Normal file
10
src/features/price-type/lib/type.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
72
src/features/price-type/ui/TablePriceType.tsx
Normal file
72
src/features/price-type/ui/TablePriceType.tsx
Normal file
@@ -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 (
|
||||||
|
<div className="flex-1 overflow-auto">
|
||||||
|
{isLoading && (
|
||||||
|
<div className="h-full flex items-center justify-center bg-white/70 z-10">
|
||||||
|
<span className="text-lg font-medium">
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isError && (
|
||||||
|
<div className="h-full flex items-center justify-center z-10">
|
||||||
|
<span className="text-lg font-medium text-red-600">
|
||||||
|
Ma'lumotlarni olishda xatolik yuz berdi.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isError && !isLoading && (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>ID</TableHead>
|
||||||
|
<TableHead>Nomi</TableHead>
|
||||||
|
<TableHead>Kodi</TableHead>
|
||||||
|
<TableHead>Valyuta kodi</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
|
||||||
|
<TableBody>
|
||||||
|
{data.map((d, index) => (
|
||||||
|
<TableRow key={d.id}>
|
||||||
|
<TableCell>{index + 1}</TableCell>
|
||||||
|
<TableCell>{d.name}</TableCell>
|
||||||
|
<TableCell>{d.code}</TableCell>
|
||||||
|
<TableCell>{d.currency_code}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{data.length === 0 && (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={4} className="text-center py-6">
|
||||||
|
Hech qanday tuman topilmadi
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TablePriceType;
|
||||||
61
src/features/price-type/ui/priceTypeList.tsx
Normal file
61
src/features/price-type/ui/priceTypeList.tsx
Normal file
@@ -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 (
|
||||||
|
<div className="flex flex-col h-full p-10 w-full">
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-start md:items-center mb-4 gap-4">
|
||||||
|
<h1 className="text-2xl font-bold">Narx turlari</h1>
|
||||||
|
|
||||||
|
<div className="flex gap-4 justify-end">
|
||||||
|
<Button
|
||||||
|
className="bg-blue-500 h-12 cursor-pointer hover:bg-blue-500"
|
||||||
|
onClick={() => mutate()}
|
||||||
|
>
|
||||||
|
Narx turlarini import qilish
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<TablePriceType
|
||||||
|
data={data ? data : []}
|
||||||
|
isError={isError}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PriceTypeList;
|
||||||
12
src/pages/PriceType.tsx
Normal file
12
src/pages/PriceType.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import PriceTypeList from "@/features/price-type/ui/priceTypeList";
|
||||||
|
import SidebarLayout from "@/SidebarLayout";
|
||||||
|
|
||||||
|
const PriceType = () => {
|
||||||
|
return (
|
||||||
|
<SidebarLayout>
|
||||||
|
<PriceTypeList />
|
||||||
|
</SidebarLayout>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PriceType;
|
||||||
@@ -4,6 +4,7 @@ import Categories from "@/pages/Categories";
|
|||||||
import Faq from "@/pages/Faq";
|
import Faq from "@/pages/Faq";
|
||||||
import HomePage from "@/pages/Home";
|
import HomePage from "@/pages/Home";
|
||||||
import Orders from "@/pages/Orders";
|
import Orders from "@/pages/Orders";
|
||||||
|
import PriceType from "@/pages/PriceType";
|
||||||
import Product from "@/pages/Product";
|
import Product from "@/pages/Product";
|
||||||
import Questionnaire from "@/pages/Questionnaire";
|
import Questionnaire from "@/pages/Questionnaire";
|
||||||
import Units from "@/pages/Units";
|
import Units from "@/pages/Units";
|
||||||
@@ -58,6 +59,10 @@ const AppRouter = () => {
|
|||||||
path: "/dashboard/questionnaire",
|
path: "/dashboard/questionnaire",
|
||||||
element: <Questionnaire />,
|
element: <Questionnaire />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/dashboard/price-type",
|
||||||
|
element: <PriceType />,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return routes;
|
return routes;
|
||||||
|
|||||||
@@ -41,4 +41,6 @@ export const API_URLS = {
|
|||||||
`${API_V}admin/category/${id}/upload_image/`,
|
`${API_V}admin/category/${id}/upload_image/`,
|
||||||
PasswordSet: (id: number | string) =>
|
PasswordSet: (id: number | string) =>
|
||||||
`${API_V}admin/user/${id}/set_password/`,
|
`${API_V}admin/user/${id}/set_password/`,
|
||||||
|
PriceTypeList: `${API_V}shared/price_type/`,
|
||||||
|
PriceTypeImport: `${API_V}shared/price_type/`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
BanknoteIcon,
|
||||||
CircleQuestionMark,
|
CircleQuestionMark,
|
||||||
FileText,
|
FileText,
|
||||||
FolderOpen,
|
FolderOpen,
|
||||||
@@ -42,6 +43,11 @@ const items = [
|
|||||||
url: "/dashboard/categories",
|
url: "/dashboard/categories",
|
||||||
icon: FolderOpen,
|
icon: FolderOpen,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Narx turlari",
|
||||||
|
url: "/dashboard/price-type",
|
||||||
|
icon: BanknoteIcon,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Birliklar",
|
title: "Birliklar",
|
||||||
url: "/dashboard/units",
|
url: "/dashboard/units",
|
||||||
|
|||||||
Reference in New Issue
Block a user