From ead2748971d5422be928d959220349dd79242e66 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 28 Jan 2025 14:38:34 +0530 Subject: [PATCH 1/9] fix resource letter print crash --- src/components/Resource/ResourceDetails.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/Resource/ResourceDetails.tsx b/src/components/Resource/ResourceDetails.tsx index ec4c617d532..45af9c4b9df 100644 --- a/src/components/Resource/ResourceDetails.tsx +++ b/src/components/Resource/ResourceDetails.tsx @@ -103,8 +103,7 @@ function FacilityCard({ ); } -const RequestLetter = (data: ResourceRequest) => { - const { t } = useTranslation(); +const RequestLetter = (data: ResourceRequest, t: (arg0: string) => string) => { return (
@@ -382,7 +381,7 @@ export default function ResourceDetails(props: { id: string }) { {t("close")}
- {RequestLetter(data)} + {RequestLetter(data, t)}
)} From 4b8a91bcdc6f3aa56aa7bf40b00800b3e46beffd Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 28 Jan 2025 15:22:33 +0530 Subject: [PATCH 2/9] add TFunction --- src/components/Resource/ResourceDetails.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Resource/ResourceDetails.tsx b/src/components/Resource/ResourceDetails.tsx index 45af9c4b9df..d93a1ff9530 100644 --- a/src/components/Resource/ResourceDetails.tsx +++ b/src/components/Resource/ResourceDetails.tsx @@ -1,3 +1,4 @@ +import { TFunction } from "i18next"; import { navigate } from "raviger"; import { useState } from "react"; import { useTranslation } from "react-i18next"; @@ -103,7 +104,7 @@ function FacilityCard({ ); } -const RequestLetter = (data: ResourceRequest, t: (arg0: string) => string) => { +const RequestLetter = (data: ResourceRequest, t: TFunction) => { return (
From 55678e7974e6341738a6128c921e73c1e813b5ab Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 28 Jan 2025 23:07:59 +0530 Subject: [PATCH 3/9] Empty-Commit From d011d26d2bb13143950410e53fddfe4f593d1b42 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 29 Jan 2025 23:31:14 +0530 Subject: [PATCH 4/9] created new print comp for resource letter --- src/Routers/routes/ResourceRoutes.tsx | 2 + .../Resource/PrintResourceLetter.tsx | 129 ++++++++++++++++ src/components/Resource/ResourceDetails.tsx | 142 ++---------------- 3 files changed, 141 insertions(+), 132 deletions(-) create mode 100644 src/components/Resource/PrintResourceLetter.tsx diff --git a/src/Routers/routes/ResourceRoutes.tsx b/src/Routers/routes/ResourceRoutes.tsx index 357b7812513..cdd39b91213 100644 --- a/src/Routers/routes/ResourceRoutes.tsx +++ b/src/Routers/routes/ResourceRoutes.tsx @@ -1,4 +1,5 @@ import View from "@/components/Common/View"; +import PrintResourceLetter from "@/components/Resource/PrintResourceLetter"; import BoardView from "@/components/Resource/ResourceBoard"; import ResourceDetails from "@/components/Resource/ResourceDetails"; import { ResourceDetailsUpdate } from "@/components/Resource/ResourceDetailsUpdate"; @@ -10,6 +11,7 @@ const ResourceRoutes: AppRoutes = { "/resource": () => , "/resource/:id": ({ id }) => , "/resource/:id/update": ({ id }) => , + "/resource/:id/print": ({ id }) => , }; export default ResourceRoutes; diff --git a/src/components/Resource/PrintResourceLetter.tsx b/src/components/Resource/PrintResourceLetter.tsx new file mode 100644 index 00000000000..4d8fef0ebdd --- /dev/null +++ b/src/components/Resource/PrintResourceLetter.tsx @@ -0,0 +1,129 @@ +import { useQuery } from "@tanstack/react-query"; +import { useTranslation } from "react-i18next"; + +import PrintPreview from "@/CAREUI/misc/PrintPreview"; + +import Loading from "@/components/Common/Loading"; + +import { RESOURCE_CATEGORY_CHOICES } from "@/common/constants"; + +import routes from "@/Utils/request/api"; +import query from "@/Utils/request/query"; +import { formatDateTime, formatName } from "@/Utils/utils"; + +export default function PrintResourceLetter({ id }: { id: string }) { + const { t } = useTranslation(); + + const { data, isLoading } = useQuery({ + queryKey: ["resource_request_letter", id], + queryFn: query(routes.getResourceDetails, { + pathParams: { id: id }, + }), + }); + + if (isLoading || !data) { + return ; + } + return ( + +
+
+ {/* Header */} +
+
{t("request_letter")}
+
+ {t("reference_no")}: {data.id} +
+
+ + {/* Date */} +
+
+ {t("date")}: {formatDateTime(data.created_date)} +
+
+ + {/* From Address */} +
+
{t("From")}:
+
{data.origin_facility.name}
+
+ + {/* Subject Line */} +
+
+ {t("subject")}: {t("request_for")} {data.title} +
+
+ + {/* Main Content */} +
+

+ {t("request_the_following_resource")} + {data.emergency ? t("on_emergency_basis") : ""}: +

+ +
+
+ {t("request_title")}:{" "} + {data.title} +
+
+ {t("category")}:{" "} + {RESOURCE_CATEGORY_CHOICES.find( + (item) => item.id === data.category, + )?.text || "--"} +
+
+ {t("quantity_required")}:{" "} + {data.requested_quantity} +
+
+ + {t("reason_for_request")}: + +

{data.reason || "--"}

+
+
+ + {/* Status Section */} +
+ {t("current_status")}: + + {data.status} + +
+
+ + {/* Signature Section */} +
+
+
+
{t("requested_by")}:
+
{formatName(data.created_by)}
+
+ {formatDateTime(data.created_date)} +
+
+
+ + {data.status !== "PENDING" && ( +
+
+
+ {data.status === "REJECTED" ? t("rejected") : t("approved")}{" "} + {t("by")}: +
+
{formatName(data.updated_by)}
+
+ {formatDateTime(data.modified_date)} +
+
+
+ )} +
+
+
+
+ ); +} diff --git a/src/components/Resource/ResourceDetails.tsx b/src/components/Resource/ResourceDetails.tsx index 4898691375a..6a0af2c62a8 100644 --- a/src/components/Resource/ResourceDetails.tsx +++ b/src/components/Resource/ResourceDetails.tsx @@ -1,6 +1,5 @@ -import { TFunction } from "i18next"; +import { useQuery } from "@tanstack/react-query"; import { navigate } from "raviger"; -import { useState } from "react"; import { useTranslation } from "react-i18next"; import CareIcon from "@/CAREUI/icons/CareIcon"; @@ -18,10 +17,9 @@ import CommentSection from "@/components/Resource/ResourceCommentSection"; import { RESOURCE_CATEGORY_CHOICES } from "@/common/constants"; import routes from "@/Utils/request/api"; -import useTanStackQueryInstead from "@/Utils/request/useQuery"; +import query from "@/Utils/request/query"; import { formatDateTime, formatName } from "@/Utils/utils"; import { PatientModel } from "@/types/emr/patient"; -import { ResourceRequest } from "@/types/resourceRequest/resourceRequest"; function PatientCard({ patient }: { patient: PatientModel }) { const { t } = useTranslation(); @@ -104,118 +102,17 @@ function FacilityCard({ ); } -const RequestLetter = (data: ResourceRequest, t: TFunction) => { - return ( -
-
- {/* Header */} -
-
{t("request_letter")}
-
- {t("reference_no")}: {data.id} -
-
- - {/* Date */} -
-
- {t("date")}: {formatDateTime(data.created_date)} -
-
- - {/* From Address */} -
-
{t("from")}:
-
{data.origin_facility.name}
-
- - {/* Subject Line */} -
-
- {t("subject")}: {t("request_for")} {data.title} -
-
- - {/* Main Content */} -
-

- {t("request_the_following_resource")} - {data.emergency ? t("on_emergency_basis") : ""}: -

- -
-
- {t("request_title")}:{" "} - {data.title} -
-
- {t("category")}:{" "} - {RESOURCE_CATEGORY_CHOICES.find( - (item) => item.id === data.category, - )?.text || "--"} -
-
- {t("quantity_required")}:{" "} - {data.requested_quantity} -
-
- {t("reason_for_request")}: -

{data.reason || "--"}

-
-
- - {/* Status Section */} -
- {t("current_status")}: - {data.status} -
-
- - {/* Signature Section */} -
-
-
-
{t("requested_by")}:
-
{formatName(data.created_by)}
-
- {formatDateTime(data.created_date)} -
-
-
- - {data.status !== "PENDING" && ( -
-
-
- {data.status === "REJECTED" ? t("rejected") : t("approved")} - {t("by")}: -
-
{formatName(data.updated_by)}
-
- {formatDateTime(data.modified_date)} -
-
-
- )} -
-
-
- ); -}; - export default function ResourceDetails(props: { id: string }) { - const [isPrintMode, setIsPrintMode] = useState(false); const { t } = useTranslation(); - const { data, loading } = useTanStackQueryInstead(routes.getResourceDetails, { - pathParams: { id: props.id }, - onResponse: ({ res, data }) => { - if (!res && !data) { - navigate("/not-found"); - } - }, + + const { data, isLoading } = useQuery({ + queryKey: ["resource_request", props.id], + queryFn: query(routes.getResourceDetails, { + pathParams: { id: props.id }, + }), }); - if (loading || !data) { + if (isLoading || !data) { return ; } @@ -230,7 +127,7 @@ export default function ResourceDetails(props: { id: string }) {
- - {/* Print Mode */} - {isPrintMode && ( -
-
-
- - -
- {RequestLetter(data, t)} -
-
- )} ); } From f508df5e8ff2e1b001484e4e81a4fe19d9869fde Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 29 Jan 2025 23:37:39 +0530 Subject: [PATCH 5/9] replace classNames with cn --- src/CAREUI/misc/PrintPreview.tsx | 6 +++--- src/components/Resource/PrintResourceLetter.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CAREUI/misc/PrintPreview.tsx b/src/CAREUI/misc/PrintPreview.tsx index c34c75f3299..3479b6a0347 100644 --- a/src/CAREUI/misc/PrintPreview.tsx +++ b/src/CAREUI/misc/PrintPreview.tsx @@ -1,6 +1,8 @@ import { ReactNode } from "react"; import { useTranslation } from "react-i18next"; +import { cn } from "@/lib/utils"; + import CareIcon from "@/CAREUI/icons/CareIcon"; import { ZoomControls, @@ -14,8 +16,6 @@ import Page from "@/components/Common/Page"; import useBreakpoints from "@/hooks/useBreakpoints"; -import { classNames } from "@/Utils/utils"; - type Props = { children: ReactNode; disabled?: boolean; @@ -41,7 +41,7 @@ export default function PrintPreview(props: Props) {
{props.children}
diff --git a/src/components/Resource/PrintResourceLetter.tsx b/src/components/Resource/PrintResourceLetter.tsx index 4d8fef0ebdd..bc1a80f72a8 100644 --- a/src/components/Resource/PrintResourceLetter.tsx +++ b/src/components/Resource/PrintResourceLetter.tsx @@ -26,7 +26,7 @@ export default function PrintResourceLetter({ id }: { id: string }) { } return ( -
+
{/* Header */}
From d93c32f4811b6cef0bab9a18ea84cd44575eb230 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 29 Jan 2025 23:49:26 +0530 Subject: [PATCH 6/9] rm data from top --- src/style/index.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/style/index.css b/src/style/index.css index 33b9f0aa0e8..0c97e1f40ad 100644 --- a/src/style/index.css +++ b/src/style/index.css @@ -431,6 +431,9 @@ button:disabled, } @media print { + @page { + margin-top: 0; + } body * { visibility: hidden; } From 0c752bc9e3d3a7409ce33bb2b39ce1e7c9e08c8b Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 29 Jan 2025 23:51:07 +0530 Subject: [PATCH 7/9] Empty-Commit From 6ef544d7cb903cefc89f421b12947c52a6e46f66 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 29 Jan 2025 23:59:56 +0530 Subject: [PATCH 8/9] Empty-Commit From 147960046a7fde9c9908d31c40cfc0ca52e71cb0 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Thu, 30 Jan 2025 00:13:49 +0530 Subject: [PATCH 9/9] Empty-Commit