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/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..bc1a80f72a8 --- /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 8308935f197..6a0af2c62a8 100644 --- a/src/components/Resource/ResourceDetails.tsx +++ b/src/components/Resource/ResourceDetails.tsx @@ -1,5 +1,5 @@ +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"; @@ -17,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(); @@ -103,119 +102,17 @@ function FacilityCard({ ); } -const RequestLetter = (data: ResourceRequest) => { - const { t } = useTranslation(); - 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)} -
-
- )} ); } diff --git a/src/style/index.css b/src/style/index.css index a779daf3e88..2f14f673a18 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; }