Skip to content

Commit a84bd76

Browse files
committed
Removed unncessary edit query in the Excalidraw editor page and other i18n conversions
1 parent aa5327a commit a84bd76

File tree

4 files changed

+25
-44
lines changed

4 files changed

+25
-44
lines changed

public/locale/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,10 @@
983983
"error_fetching_user_details": "Error while fetching user details: ",
984984
"error_fetching_users_data": "Failed to load user data. Please try again later.",
985985
"error_generating_discharge_summary": "Error generating discharge summary",
986+
"error_in_createUpload": "Error in createUpload",
986987
"error_loading_questionnaire_response": "Error loading questionnaire response",
987988
"error_updating_encounter": "Error to Updating Encounter",
989+
"error_uploading_file": "Error uploading file",
988990
"error_verifying_otp": "Error while verifying OTP, Please request a new OTP",
989991
"error_while_deleting_record": "Error while deleting record",
990992
"escape": "Escape",
@@ -1665,6 +1667,7 @@
16651667
"please_check_your_messages": "Please check your messages",
16661668
"please_confirm_password": "Please confirm your new password.",
16671669
"please_enter_a_name": "Please enter a name!",
1670+
"please_enter_a_name_for_the_drawing.": "Please enter a name for the drawing.",
16681671
"please_enter_a_reason_for_the_shift": "Please enter a reason for the shift.",
16691672
"please_enter_a_valid_reason": "Please enter a valid reason!",
16701673
"please_enter_confirm_password": "Please confirm your new password",

src/Routers/routes/ConsultationRoutes.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { AppRoutes } from "@/Routers/AppRouter";
99
import { EncounterShow } from "@/pages/Encounters/EncounterShow";
1010
import { PrintPrescription } from "@/pages/Encounters/PrintPrescription";
1111

12-
const ExcalidrawPage = lazy(() => import("@/components/Files/ExcalidrawPage"));
12+
const ExcalidrawEditor = lazy(
13+
() => import("@/components/Files/ExcalidrawEditor"),
14+
);
1315
const ExcalidrawView = lazy(() => import("@/components/Files/ExcalidrawView"));
1416

1517
const consultationRoutes: AppRoutes = {
@@ -37,7 +39,7 @@ const consultationRoutes: AppRoutes = {
3739
encounterId,
3840
}) => (
3941
<Suspense fallback={<Loading />}>
40-
<ExcalidrawPage associatingId={encounterId} fileType="encounter" />
42+
<ExcalidrawEditor associatingId={encounterId} fileType="encounter" />
4143
</Suspense>
4244
),
4345
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/drawings/:drawingId":

src/Routers/routes/PatientRoutes.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import { AppRoutes } from "@/Routers/AppRouter";
1313
import { EncounterList } from "@/pages/Encounters/EncounterList";
1414
import VerifyPatient from "@/pages/Patients/VerifyPatient";
1515

16-
const ExcalidrawPage = lazy(() => import("@/components/Files/ExcalidrawPage"));
16+
const ExcalidrawEditor = lazy(
17+
() => import("@/components/Files/ExcalidrawEditor"),
18+
);
1719
const ExcalidrawView = lazy(() => import("@/components/Files/ExcalidrawView"));
1820

1921
const PatientRoutes: AppRoutes = {
@@ -53,7 +55,7 @@ const PatientRoutes: AppRoutes = {
5355
"/facility/:facilityId/patient/:id/drawings": ({ id }) => {
5456
return (
5557
<Suspense fallback={<Loading />}>
56-
<ExcalidrawPage associatingId={id} fileType="patient" />
58+
<ExcalidrawEditor associatingId={id} fileType="patient" />
5759
</Suspense>
5860
);
5961
},

src/components/Files/ExcalidrawPage.tsx renamed to src/components/Files/ExcalidrawEditor.tsx

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Excalidraw } from "@excalidraw/excalidraw";
22
import { type ExcalidrawElement } from "@excalidraw/excalidraw/types/element/types";
3-
import { useMutation, useQuery } from "@tanstack/react-query";
3+
import { useMutation } from "@tanstack/react-query";
44
import { t } from "i18next";
55
import { navigate } from "raviger";
66
import { useEffect, useState } from "react";
@@ -18,50 +18,24 @@ import { CreateFileResponse } from "@/components/Patient/models";
1818

1919
import routes from "@/Utils/request/api";
2020
import mutate from "@/Utils/request/mutate";
21-
import query from "@/Utils/request/query";
2221

2322
type Props = {
2423
associatingId: string;
2524
fileType: string;
26-
drawingId?: string;
2725
};
2826

29-
export default function ExcalidrawPage({
30-
associatingId,
31-
drawingId,
32-
fileType,
33-
}: Props) {
27+
export default function ExcalidrawEditor({ associatingId, fileType }: Props) {
3428
const [elements, setElements] = useState<readonly ExcalidrawElement[] | null>(
35-
drawingId ? null : [],
29+
[],
3630
);
3731
const [name, setName] = useState("");
38-
const [id, setId] = useState(drawingId);
32+
const [id, setId] = useState("");
3933
const [isDirty, setIsDirty] = useState(false);
4034

41-
const { data, isLoading } = useQuery({
42-
queryKey: ["file", id],
43-
queryFn: query(routes.retrieveUpload, {
44-
pathParams: { id: id || "" },
45-
}),
46-
enabled: !!id,
47-
});
48-
4935
useEffect(() => {
5036
setIsDirty(!!elements?.length);
5137
}, [elements?.length]);
5238

53-
useEffect(() => {
54-
if (!data) {
55-
return;
56-
}
57-
setName(data.name!);
58-
const fetchData = async () => {
59-
const response = await fetch(data.read_signed_url!);
60-
const json = await response.json();
61-
setElements(json.elements);
62-
};
63-
fetchData();
64-
}, [data]);
6539
const { mutateAsync: markUploadComplete, error: markUploadCompleteError } =
6640
useMutation({
6741
mutationFn: mutate(routes.markUploadCompleted, {
@@ -78,24 +52,24 @@ export default function ExcalidrawPage({
7852

7953
const handleSave = async () => {
8054
if (!name.trim()) {
81-
toast.error("Please enter a name for the drawing.");
55+
toast.error(t("please_enter_a_name_for_the_drawing"));
8256
return;
8357
}
8458

8559
const obj = {
8660
type: "excalidraw",
8761
version: "2",
88-
source: "https://care.ohc.network.com",
62+
source: window.location.origin,
8963
elements: elements,
9064
appState: {},
9165
files: {},
9266
};
9367

9468
try {
9569
const file = new File([JSON.stringify(obj)], `${name}.excalidraw`, {
96-
type: "text/plain",
70+
type: "application/vnd.excalidraw",
9771
});
98-
let signedUrl = data?.read_signed_url || "";
72+
let signedUrl = "";
9973
let response: CreateFileResponse | null = null;
10074
if (!id) {
10175
response = await createUpload({
@@ -118,7 +92,7 @@ export default function ExcalidrawPage({
11892
});
11993

12094
if (!upload.ok) {
121-
toast.error("Error uploading file");
95+
toast.error(t("error_uploading_file"));
12296

12397
return;
12498
}
@@ -131,12 +105,12 @@ export default function ExcalidrawPage({
131105
toast.success(t("file_success__upload_complete"));
132106
navigate(`drawings/${response!.id}`);
133107
}
134-
} catch (error) {
135-
console.error("Error in Step 1 (createUpload):", error);
108+
} catch {
109+
toast.error(t("error_in_createUpload"));
136110
}
137111
};
138112

139-
if (isLoading || elements === null) {
113+
if (elements === null) {
140114
return <Loading />;
141115
}
142116

@@ -151,7 +125,7 @@ export default function ExcalidrawPage({
151125
<Input
152126
type="text"
153127
value={name}
154-
placeholder="Enter the File Name"
128+
placeholder={t("enter_the_file_name")}
155129
onChange={(e) => setName(e.target.value)}
156130
/>
157131
</div>
@@ -175,7 +149,7 @@ export default function ExcalidrawPage({
175149
initialData={{
176150
appState: { theme: "light" },
177151
}}
178-
onChange={debounce(async (elements) => {
152+
onChange={debounce((elements) => {
179153
setElements(elements);
180154
}, 100)}
181155
/>

0 commit comments

Comments
 (0)