complated
This commit is contained in:
@@ -61,4 +61,20 @@ export const plans_api = {
|
||||
const res = await httpClient.post(API_URLS.Import_Product);
|
||||
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;
|
||||
inventory_kinds: { id: number; name: string }[];
|
||||
sector_codes: { id: number; code: string }[];
|
||||
payment_type: "cash" | "card" | null;
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Button } from "@/shared/ui/button";
|
||||
import { Input } from "@/shared/ui/input";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import type { AxiosError } from "axios";
|
||||
import { Loader } from "lucide-react";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
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 (
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Input
|
||||
@@ -101,6 +118,16 @@ const FilterPlans = ({ searchUser, setSearchUser }: Props) => {
|
||||
/>
|
||||
</DialogContent>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { plans_api } from "@/features/plans/lib/api";
|
||||
import type { Product } from "@/features/plans/lib/data";
|
||||
import { API_URLS } from "@/shared/config/api/URLs";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import { Checkbox } from "@/shared/ui/checkbox";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/shared/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -10,8 +19,10 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/shared/ui/table";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Eye, Loader2, Trash2 } from "lucide-react";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface Props {
|
||||
products: Product[] | [];
|
||||
@@ -46,6 +57,29 @@ const ProductTable = ({
|
||||
handleSelectAllPages,
|
||||
isAllPagesSelected,
|
||||
}: 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) {
|
||||
return (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
@@ -63,7 +97,6 @@ const ProductTable = ({
|
||||
}
|
||||
|
||||
const currentPageIds = products.map((p) => p.id);
|
||||
|
||||
const isAllSelected =
|
||||
isAllPagesSelected ||
|
||||
(products.length > 0 &&
|
||||
@@ -141,6 +174,7 @@ const ProductTable = ({
|
||||
<TableHead>Rasmi</TableHead>
|
||||
<TableHead>Nomi</TableHead>
|
||||
<TableHead>Tavsif</TableHead>
|
||||
<TableHead>Narx turi</TableHead>
|
||||
<TableHead className="text-end">Harakatlar</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -175,6 +209,31 @@ const ProductTable = ({
|
||||
</TableCell>
|
||||
<TableCell>{product.name}</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">
|
||||
<Button
|
||||
size="sm"
|
||||
|
||||
@@ -43,4 +43,7 @@ export const API_URLS = {
|
||||
`${API_V}admin/user/${id}/set_password/`,
|
||||
PriceTypeList: `${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