import { distributed_api } from "@/features/distributed/lib/api"; import { order_api } from "@/features/specification/lib/api"; import formatDate from "@/shared/lib/formatDate"; import { Button } from "@/shared/ui/button"; import { Calendar } from "@/shared/ui/calendar"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/shared/ui/command"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/shared/ui/dialog"; import { Input } from "@/shared/ui/input"; import { Label } from "@/shared/ui/label"; import { Popover, PopoverContent, PopoverTrigger } from "@/shared/ui/popover"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { ChevronDownIcon, ChevronsUpDown } from "lucide-react"; import { useState } from "react"; interface Props { open: boolean; setOpen: (v: boolean) => void; } export default function DistributedAddModal({ open, setOpen }: Props) { const [form, setForm] = useState({ product_id: 0, date: "", employee_name: "", quantity: 0, }); const client = useQueryClient(); const { data: product } = useQuery({ queryKey: ["product_list"], queryFn: () => order_api.product_list(), select(data) { return data.data.data; }, }); const [openProduct, setOpenProduct] = useState(false); const [searchProduct, setSearchProduct] = useState(""); const [openDate, setOpenData] = useState(false); const selectedProduct = product?.find((x) => x.id === form.product_id); const createMutation = useMutation({ mutationFn: () => distributed_api.create(form), onSuccess: () => { client.invalidateQueries({ queryKey: ["distributed_list"] }); setOpen(false); }, }); const handleSubmit = () => { createMutation.mutate(); }; return ( Yangi topshirilgan mahsulot qo‘shish
{product && product.length > 0 ? ( {product .filter((p) => p.name .toLowerCase() .includes(searchProduct.toLowerCase()), ) .map((p) => ( { setForm({ ...form, product_id: p.id }); setOpenProduct(false); }} > {p.name} ))} ) : ( Mahsulot topilmadi )}
{ const val = e.target.value; setForm({ ...form, quantity: val === "" ? 0 : Number(val) }); }} />
setForm({ ...form, employee_name: e.target.value }) } />
{ if (date) { setForm({ ...form, date: formatDate.format(date, "YYYY-MM-DD"), }); setOpenData(false); } }} />
); }