download pdf
This commit is contained in:
@@ -33,4 +33,9 @@ export const order_api = {
|
|||||||
const res = await httpClient.patch(`${ORDER}${id}/update/`, body);
|
const res = await httpClient.patch(`${ORDER}${id}/update/`, body);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async download_pdf(id: number) {
|
||||||
|
const res = await httpClient.get(`${ORDER}${id}/send_pdf/`);
|
||||||
|
return res;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import { formatPrice } from "@/shared/lib/formatPrice";
|
|||||||
import { Button } from "@/shared/ui/button";
|
import { Button } from "@/shared/ui/button";
|
||||||
import { DashboardLayout } from "@/widgets/dashboard-layout/ui";
|
import { DashboardLayout } from "@/widgets/dashboard-layout/ui";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Building2, User } from "lucide-react";
|
import { Building2, Loader2, User } from "lucide-react";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export function DetailViewPage() {
|
export function DetailViewPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
const [pdfId, setPdfId] = useState<number | null>(null);
|
||||||
|
|
||||||
const { data } = useQuery({
|
const { data } = useQuery({
|
||||||
queryKey: ["order_list"],
|
queryKey: ["order_list"],
|
||||||
@@ -27,9 +30,32 @@ export function DetailViewPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: pdf,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["download_pdf", pdfId],
|
||||||
|
queryFn: () => order_api.download_pdf(Number(pdfId!)),
|
||||||
|
enabled: !!pdfId,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isError) {
|
||||||
|
toast.error(error.message || "Faylni yuklab olishda xatolik yuz berdi", {
|
||||||
|
richColors: true,
|
||||||
|
position: "top-center",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isError]);
|
||||||
|
|
||||||
const item = data && data.find((h) => h.id === Number(id));
|
const item = data && data.find((h) => h.id === Number(id));
|
||||||
|
|
||||||
const handleDownloadPDF = async () => {};
|
const handleDownloadPDF = (id: number) => {
|
||||||
|
setPdfId(id);
|
||||||
|
console.log(pdf);
|
||||||
|
};
|
||||||
|
|
||||||
if (!item) return <div>{"Ma'lumot topilmadi"}</div>;
|
if (!item) return <div>{"Ma'lumot topilmadi"}</div>;
|
||||||
|
|
||||||
@@ -160,11 +186,11 @@ export function DetailViewPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleDownloadPDF}
|
onClick={() => handleDownloadPDF(item.id)}
|
||||||
className="w-full h-14 mt-5 text-md bg-green-600 hover:bg-green-700 text-white"
|
className="w-full h-14 mt-5 text-md bg-green-600 hover:bg-green-700 text-white"
|
||||||
size="lg"
|
size="lg"
|
||||||
>
|
>
|
||||||
Yuklab olish
|
{isLoading ? <Loader2 className="animate-spin" /> : "Yuklab olish"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</DashboardLayout>
|
</DashboardLayout>
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export function SpecificationPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [selectedPharmacy, setSelectedPharmacy] = useState(
|
const [selectedPharmacy, setSelectedPharmacy] = useState(
|
||||||
data ? data[0].id : "",
|
data && data.length > 0 ? data[0].id : "",
|
||||||
);
|
);
|
||||||
|
|
||||||
// const [selectedPharm, setSelectedPharm] = useState(
|
// const [selectedPharm, setSelectedPharm] = useState(
|
||||||
@@ -104,7 +104,7 @@ export function SpecificationPage() {
|
|||||||
if (product) {
|
if (product) {
|
||||||
setMedicines(product?.map((m) => ({ ...m, quantity: 0 })));
|
setMedicines(product?.map((m) => ({ ...m, quantity: 0 })));
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data && data.length > 0) {
|
||||||
setSelectedPharmacy(data[0].id);
|
setSelectedPharmacy(data[0].id);
|
||||||
}
|
}
|
||||||
// if (pharmacy) {
|
// if (pharmacy) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default defineConfig({
|
|||||||
port: 5174,
|
port: 5174,
|
||||||
host: true, // barcha hostlarga ruxsat
|
host: true, // barcha hostlarga ruxsat
|
||||||
allowedHosts: [
|
allowedHosts: [
|
||||||
"hampshire-blake-womens-ref.trycloudflare.com", // ngrok host qo'shildi
|
"hugo-quotes-loved-wiki.trycloudflare.com", // ngrok host qo'shildi
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user