Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanuj1718 committed Feb 28, 2025
2 parents 60b419c + 6c95ea4 commit 582fb5c
Show file tree
Hide file tree
Showing 49 changed files with 3,646 additions and 944 deletions.
130 changes: 127 additions & 3 deletions public/locale/en.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ import AuthUserProvider from "@/Providers/AuthUserProvider";
import HistoryAPIProvider from "@/Providers/HistoryAPIProvider";
import Routers from "@/Routers";
import { handleHttpError } from "@/Utils/request/errorHandler";
import { HTTPError } from "@/Utils/request/types";

import { PubSubProvider } from "./Utils/pubsubContext";

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 2,
retry: (failureCount, error) => {
// Only retry network errors or server errors (502, 503, 504) up to 3 times
if (
error.message === "Network Error" ||
(error instanceof HTTPError && [502, 503, 504].includes(error.status))
) {
return failureCount < 3;
}
return false;
},
refetchOnWindowFocus: false,
},
},
Expand Down
6 changes: 6 additions & 0 deletions src/CAREUI/misc/PrintPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Button } from "@/components/ui/button";

import Page from "@/components/Common/Page";

import useAppHistory from "@/hooks/useAppHistory";
import useBreakpoints from "@/hooks/useBreakpoints";

type Props = {
Expand All @@ -26,11 +27,16 @@ type Props = {
export default function PrintPreview(props: Props) {
const normalScale = useBreakpoints({ default: 1 });
const { t } = useTranslation();
const { goBack } = useAppHistory();

return (
<Page title={props.title}>
<div className="mx-auto my-8 xl:w-[50rem] border rounded-xl border-gray-200 shadow-2xl overflow-hidden">
<div className="top-0 z-20 flex gap-2 bg-secondary-100 px-2 py-4 xl:absolute xl:right-6 xl:top-8 xl:justify-end">
<Button variant="outline" onClick={() => goBack()}>
<CareIcon icon="l-arrow-left" className="text-lg" />
{t("back")}
</Button>
<Button variant="primary" disabled={props.disabled} onClick={print}>
<CareIcon icon="l-print" className="text-lg" />
{t("print")}
Expand Down
8 changes: 6 additions & 2 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const consultationRoutes: AppRoutes = {
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/treatment_summary":
({ facilityId, encounterId }) => (
<TreatmentSummary facilityId={facilityId} encounterId={encounterId} />
({ facilityId, encounterId, patientId }) => (
<TreatmentSummary
facilityId={facilityId}
encounterId={encounterId}
patientId={patientId}
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/questionnaire":
({ facilityId, encounterId, patientId }) => (
Expand Down
12 changes: 9 additions & 3 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DOMPurify from "dompurify";
import React, {
ChangeEventHandler,
useCallback,
Expand Down Expand Up @@ -135,11 +136,12 @@ const AvatarEditModal = ({
setSelectedFile(undefined);
return;
}
if (!isImageFile(e.target.files[0])) {
const file = e.target.files[0];
if (!isImageFile(file)) {
toast.warning(t("please_upload_an_image_file"));
return;
}
setSelectedFile(e.target.files[0]);
setSelectedFile(file);
};

const uploadAvatar = async () => {
Expand Down Expand Up @@ -231,7 +233,11 @@ const AvatarEditModal = ({
<>
<div className="flex flex-1 items-center justify-center rounded-lg">
<img
src={preview || imageUrl}
src={
preview && preview.startsWith("blob:")
? DOMPurify.sanitize(preview)
: imageUrl
}
alt="cover-photo"
className="h-full w-full object-cover"
/>
Expand Down
66 changes: 66 additions & 0 deletions src/components/Common/PrintTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { t } from "i18next";

import { cn } from "@/lib/utils";

import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";

type HeaderRow = {
key: string;
width?: number;
};

type TableRowType = Record<string, string | undefined>;
interface GenericTableProps {
headers: HeaderRow[];
rows: TableRowType[] | undefined;
}

export default function PrintTable({ headers, rows }: GenericTableProps) {
return (
<div className="overflow-hidden rounded-lg border border-gray">
<Table className="w-full">
<TableHeader>
<TableRow className="bg-transparent hover:bg-transparent divide-x divide-gray border-b-gray">
{headers.map(({ key, width }, index) => (
<TableHead
className={cn(
index == 0 && "first:rounded-l-md",
"h-auto py-1 pl-2 pr-2 text-black text-center ",
width && `w-${width}`,
)}
key={key}
>
{t(key)}
</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{!!rows &&
rows.map((row, index) => (
<TableRow
key={index}
className="bg-transparent hover:bg-transparent divide-x divide-gray"
>
{headers.map(({ key }) => (
<TableCell
className="break-words whitespace-normal text-center"
key={key}
>
{row[key] || "-"}
</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,23 @@ function StructuredResponseBadge({
);
}

function ResponseCard({ item }: { item: QuestionnaireResponse }) {
function ResponseCard({
item,
isPrintPreview,
}: {
item: QuestionnaireResponse;
isPrintPreview?: boolean;
}) {
const isStructured = !item.questionnaire;
const structuredType = Object.keys(item.structured_responses || {})[0];

return (
<Card className="flex flex-col py-3 px-4 transition-colors hover:bg-muted/50">
<Card
className={cn(
"flex flex-col py-3 px-4 transition-colors hover:bg-muted/50",
isPrintPreview && "shadow-none",
)}
>
<div className="flex items-start justify-between">
<div className="space-y-1">
<div className="flex items-center gap-2 text-xs text-gray-500">
Expand Down Expand Up @@ -317,7 +328,12 @@ export default function QuestionnaireResponsesList({
) : (
<div>
{questionnarieResponses?.results?.length === 0 ? (
<Card className="p-6">
<Card
className={cn(
"p-6",
isPrintPreview && "shadow-none border-gray",
)}
>
<div className="text-lg font-medium text-gray-500">
{t("no_questionnaire_responses")}
</div>
Expand All @@ -327,7 +343,11 @@ export default function QuestionnaireResponsesList({
{questionnarieResponses?.results?.map(
(item: QuestionnaireResponse) => (
<li key={item.id} className="w-full">
<ResponseCard key={item.id} item={item} />
<ResponseCard
key={item.id}
item={item}
isPrintPreview={isPrintPreview}
/>
</li>
),
)}
Expand Down
22 changes: 21 additions & 1 deletion src/components/Location/LocationSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
import { useTranslation } from "react-i18next";

import {
Command,
Expand Down Expand Up @@ -33,6 +34,7 @@ export function LocationSearch({
disabled,
value,
}: LocationSearchProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const [search, setSearch] = useState("");

Expand Down Expand Up @@ -60,6 +62,7 @@ export function LocationSearch({
<CommandInput
placeholder="Search locations..."
value={search}
className="outline-none border-none ring-0 shadow-none"
onValueChange={setSearch}
/>
<CommandEmpty>No locations found.</CommandEmpty>
Expand All @@ -73,7 +76,15 @@ export function LocationSearch({
setOpen(false);
}}
>
{location.name}
<span>{location.name}</span>
<span className="text-xs text-gray-500">
{t(`location_form__${location.form}`)}
{" in "}
{formatLocationParent(location)}
</span>
<span className="text-xs text-gray-500 ml-auto">
{t(`location_status__${location.status}`)}
</span>
</CommandItem>
))}
</CommandGroup>
Expand All @@ -82,3 +93,12 @@ export function LocationSearch({
</Popover>
);
}

const formatLocationParent = (location: LocationList) => {
const parents: string[] = [];
while (location.parent?.name) {
parents.push(location.parent?.name);
location = location.parent;
}
return parents.reverse().join(" > ");
};
Loading

0 comments on commit 582fb5c

Please sign in to comment.