complated
This commit is contained in:
@@ -61,4 +61,20 @@ export const plans_api = {
|
|||||||
const res = await httpClient.post(API_URLS.Import_Product);
|
const res = await httpClient.post(API_URLS.Import_Product);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async update_payment_type({
|
||||||
|
id,
|
||||||
|
body,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
body: { payment_type: "cash" | "card" };
|
||||||
|
}) {
|
||||||
|
const res = await httpClient.put(API_URLS.Update_Pyment_Type(id), body);
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
|
async import_balance() {
|
||||||
|
const res = await httpClient.post(API_URLS.Import_Balance);
|
||||||
|
return res;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export interface Product {
|
|||||||
marketing_group_code: null | string;
|
marketing_group_code: null | string;
|
||||||
inventory_kinds: { id: number; name: string }[];
|
inventory_kinds: { id: number; name: string }[];
|
||||||
sector_codes: { id: number; code: string }[];
|
sector_codes: { id: number; code: string }[];
|
||||||
|
payment_type: "cash" | "card" | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Category {
|
export interface Category {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Button } from "@/shared/ui/button";
|
|||||||
import { Input } from "@/shared/ui/input";
|
import { Input } from "@/shared/ui/input";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import type { AxiosError } from "axios";
|
import type { AxiosError } from "axios";
|
||||||
|
import { Loader } from "lucide-react";
|
||||||
import type { Dispatch, SetStateAction } from "react";
|
import type { Dispatch, SetStateAction } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
@@ -46,6 +47,22 @@ const FilterPlans = ({ searchUser, setSearchUser }: Props) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { mutate: balanceMutate, isPending } = useMutation({
|
||||||
|
mutationFn: () => plans_api.import_balance(),
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Mahsulotlar soni import qilindi", {
|
||||||
|
richColors: true,
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Xatolik yuz berdi", {
|
||||||
|
richColors: true,
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-2 mb-4">
|
<div className="flex gap-2 mb-4">
|
||||||
<Input
|
<Input
|
||||||
@@ -101,6 +118,16 @@ const FilterPlans = ({ searchUser, setSearchUser }: Props) => {
|
|||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>*/}
|
</Dialog>*/}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className="h-12 bg-blue-500 text-white hover:bg-blue-600 cursor-pointer"
|
||||||
|
variant={"secondary"}
|
||||||
|
onClick={() => balanceMutate()}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
Mahsulotlar sonini olish
|
||||||
|
{isPending && <Loader className="animate-spin" />}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
|
import { plans_api } from "@/features/plans/lib/api";
|
||||||
import type { Product } from "@/features/plans/lib/data";
|
import type { Product } from "@/features/plans/lib/data";
|
||||||
import { API_URLS } from "@/shared/config/api/URLs";
|
import { API_URLS } from "@/shared/config/api/URLs";
|
||||||
import { Button } from "@/shared/ui/button";
|
import { Button } from "@/shared/ui/button";
|
||||||
import { Checkbox } from "@/shared/ui/checkbox";
|
import { Checkbox } from "@/shared/ui/checkbox";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/shared/ui/select";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -10,8 +19,10 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/shared/ui/table";
|
} from "@/shared/ui/table";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { Eye, Loader2, Trash2 } from "lucide-react";
|
import { Eye, Loader2, Trash2 } from "lucide-react";
|
||||||
import type { Dispatch, SetStateAction } from "react";
|
import type { Dispatch, SetStateAction } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
products: Product[] | [];
|
products: Product[] | [];
|
||||||
@@ -46,6 +57,29 @@ const ProductTable = ({
|
|||||||
handleSelectAllPages,
|
handleSelectAllPages,
|
||||||
isAllPagesSelected,
|
isAllPagesSelected,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const { mutate, isPending } = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
id,
|
||||||
|
body,
|
||||||
|
}: {
|
||||||
|
id: number;
|
||||||
|
body: { payment_type: "cash" | "card" };
|
||||||
|
}) => plans_api.update_payment_type({ id, body }),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.refetchQueries({ queryKey: ["product_list"] });
|
||||||
|
toast.success("To‘lov turi yangilandi", {
|
||||||
|
richColors: true,
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Xatolik yuz berdi", {
|
||||||
|
richColors: true,
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
if (isLoading || isFetching) {
|
if (isLoading || isFetching) {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full items-center justify-center">
|
<div className="flex h-full items-center justify-center">
|
||||||
@@ -63,7 +97,6 @@ const ProductTable = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentPageIds = products.map((p) => p.id);
|
const currentPageIds = products.map((p) => p.id);
|
||||||
|
|
||||||
const isAllSelected =
|
const isAllSelected =
|
||||||
isAllPagesSelected ||
|
isAllPagesSelected ||
|
||||||
(products.length > 0 &&
|
(products.length > 0 &&
|
||||||
@@ -141,6 +174,7 @@ const ProductTable = ({
|
|||||||
<TableHead>Rasmi</TableHead>
|
<TableHead>Rasmi</TableHead>
|
||||||
<TableHead>Nomi</TableHead>
|
<TableHead>Nomi</TableHead>
|
||||||
<TableHead>Tavsif</TableHead>
|
<TableHead>Tavsif</TableHead>
|
||||||
|
<TableHead>Narx turi</TableHead>
|
||||||
<TableHead className="text-end">Harakatlar</TableHead>
|
<TableHead className="text-end">Harakatlar</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
@@ -175,6 +209,31 @@ const ProductTable = ({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{product.name}</TableCell>
|
<TableCell>{product.name}</TableCell>
|
||||||
<TableCell>{product.short_name?.slice(0, 15)}...</TableCell>
|
<TableCell>{product.short_name?.slice(0, 15)}...</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Select
|
||||||
|
value={product.payment_type ?? ""}
|
||||||
|
disabled={isPending}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
mutate({
|
||||||
|
id: product.id,
|
||||||
|
body: {
|
||||||
|
payment_type: value as "cash" | "card",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full max-w-48">
|
||||||
|
<SelectValue placeholder="To'lov turi" />
|
||||||
|
</SelectTrigger>
|
||||||
|
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectItem value="cash">Naqd</SelectItem>
|
||||||
|
<SelectItem value="card">Karta</SelectItem>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</TableCell>
|
||||||
<TableCell className="space-x-2 text-right">
|
<TableCell className="space-x-2 text-right">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -43,4 +43,7 @@ export const API_URLS = {
|
|||||||
`${API_V}admin/user/${id}/set_password/`,
|
`${API_V}admin/user/${id}/set_password/`,
|
||||||
PriceTypeList: `${API_V}shared/price_type/`,
|
PriceTypeList: `${API_V}shared/price_type/`,
|
||||||
PriceTypeImport: `${API_V}shared/price_type/`,
|
PriceTypeImport: `${API_V}shared/price_type/`,
|
||||||
|
Update_Pyment_Type: (id: number) =>
|
||||||
|
`${API_V}admin/product/${id}/update_payment_type/`,
|
||||||
|
Import_Balance: `${API_V}admin/product/import/balance/`,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user