From 0befd6bc2c3b8d2dc6d01d635f57454992f9f0e3 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Wed, 9 Oct 2024 15:46:43 +0530 Subject: [PATCH 1/3] Fix: Error Messages Persist in UserAdd Component (#8721) --- src/Components/Users/UserAdd.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 855e2cb8f9a..6a87e64425c 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -294,6 +294,7 @@ export const UserAdd = (props: UserProps) => { const handleDateChange = (e: FieldChangeEvent) => { if (dayjs(e.value).isValid()) { + const errors = { ...state.errors, [e.name]: "" }; dispatch({ type: "set_form", form: { @@ -301,10 +302,12 @@ export const UserAdd = (props: UserProps) => { [e.name]: dayjs(e.value).format("YYYY-MM-DD"), }, }); + dispatch({ type: "set_errors", errors }); } }; const handleFieldChange = (event: FieldChangeEvent) => { + const errors = { ...state.errors, [event.name]: "" }; dispatch({ type: "set_form", form: { @@ -312,6 +315,7 @@ export const UserAdd = (props: UserProps) => { [event.name]: event.value, }, }); + dispatch({ type: "set_errors", errors }); }; useAbortableEffect(() => { From 4b2c827ed434b3eac22ac72582d3fdb863bcd670 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Wed, 9 Oct 2024 16:04:13 +0530 Subject: [PATCH 2/3] fix: Add user media ready and camera permission denied notifications (#8688) --- .../Facility/CoverImageEditModal.tsx | 64 +++++++++++++------ src/Locale/en.json | 3 +- src/Locale/hi.json | 3 +- src/Locale/kn.json | 1 + src/Locale/ml.json | 1 + src/Locale/ta.json | 1 + 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/Components/Facility/CoverImageEditModal.tsx b/src/Components/Facility/CoverImageEditModal.tsx index d65a1d0ebfd..f3b2b3ab761 100644 --- a/src/Components/Facility/CoverImageEditModal.tsx +++ b/src/Components/Facility/CoverImageEditModal.tsx @@ -1,11 +1,11 @@ -import { +import React, { + useState, ChangeEventHandler, useCallback, useEffect, useRef, - useState, } from "react"; -import { Success } from "../../Utils/Notifications"; +import { Success, Warn } from "../../Utils/Notifications"; import useDragAndDrop from "../../Utils/useDragAndDrop"; import { sleep } from "../../Utils/utils"; import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; @@ -67,9 +67,11 @@ const CoverImageEditModal = ({ const LaptopScreenBreakpoint = 640; const isLaptopScreen = width >= LaptopScreenBreakpoint; const { t } = useTranslation(); + const [isDragging, setIsDragging] = useState(false); + const handleSwitchCamera = useCallback(() => { - setConstraint((prev) => - prev.facingMode === "user" + setConstraint( + constraint.facingMode === "user" ? VideoConstraints.environment : VideoConstraints.user, ); @@ -85,6 +87,7 @@ const CoverImageEditModal = ({ setSelectedFile(myFile); }); }; + const closeModal = () => { setPreview(undefined); setSelectedFile(undefined); @@ -162,11 +165,25 @@ const CoverImageEditModal = ({ const onDrop = (e: React.DragEvent) => { e.preventDefault(); dragProps.setDragOver(false); - const dropedFile = e?.dataTransfer?.files[0]; - if (dropedFile.type.split("/")[0] !== "image") + setIsDragging(false); + const droppedFile = e?.dataTransfer?.files[0]; + if (droppedFile.type.split("/")[0] !== "image") return dragProps.setFileDropError("Please drop an image file to upload!"); - setSelectedFile(dropedFile); + setSelectedFile(droppedFile); + }; + + const onDragOver = (e: React.DragEvent) => { + e.preventDefault(); + dragProps.onDragOver(e); + setIsDragging(true); + }; + + const onDragLeave = (e: React.DragEvent) => { + e.preventDefault(); + dragProps.onDragLeave(); + setIsDragging(false); }; + const commonHint = ( <> {t("max_size_for_image_uploaded_should_be")} 1mb. @@ -202,16 +219,16 @@ const CoverImageEditModal = ({ ) : (

{ + setConstraint(() => VideoConstraints.user); setIsCameraOpen(true); }} > @@ -322,6 +346,10 @@ const CoverImageEditModal = ({ width={1280} ref={webRef} videoConstraints={constraint} + onUserMediaError={(_e) => { + setIsCameraOpen(false); + Warn({ msg: t("camera_permission_denied") }); + }} /> ) : ( diff --git a/src/Locale/en.json b/src/Locale/en.json index 94b9168e564..3359a89904a 100644 --- a/src/Locale/en.json +++ b/src/Locale/en.json @@ -198,6 +198,7 @@ "retake": "Retake", "submit": "Submit", "camera": "Camera", + "camera_permission_denied": "Camera Permission denied", "submitting": "Submitting", "view_details": "View Details", "type_to_search": "Type to search", @@ -1020,4 +1021,4 @@ "date_declared_positive": "Date of declaring positive", "date_of_result": "Covid confirmation date", "is_vaccinated": "Whether vaccinated" -} +} \ No newline at end of file diff --git a/src/Locale/hi.json b/src/Locale/hi.json index 3e967c35cb4..4844a2d787d 100644 --- a/src/Locale/hi.json +++ b/src/Locale/hi.json @@ -197,6 +197,7 @@ "retake": "फिर से लेना", "submit": "जमा करना", "camera": "कैमरा", + "camera_permission_denied": "कैमरा अनुमति नहीं दी गई", "submitting": "भेजने से", "view_details": "विवरण देखें", "type_to_search": "खोजने के लिए टाइप करें", @@ -809,4 +810,4 @@ "search_by_username": "उपयोगकर्ता नाम से खोजें", "last_online": "अंतिम ऑनलाइन", "total_users": "कुल उपयोगकर्ता" -} +} \ No newline at end of file diff --git a/src/Locale/kn.json b/src/Locale/kn.json index ee808b5ebc3..a2738edd9e9 100644 --- a/src/Locale/kn.json +++ b/src/Locale/kn.json @@ -197,6 +197,7 @@ "retake": "ಮರುಪಡೆಯಿರಿ", "submit": "ಸಲ್ಲಿಸಿ", "camera": "ಕ್ಯಾಮೆರಾ", + "camera_permission_denied": "ಕ್ಯಾಮೆರಾ ಅನುಮತಿ ನಿರಾಕರಿಸಲಾಗಿದೆ", "submitting": "ಸಲ್ಲಿಸಲಾಗುತ್ತಿದೆ", "view_details": "ವಿವರಗಳನ್ನು ವೀಕ್ಷಿಸಿ", "type_to_search": "ಹುಡುಕಲು ಟೈಪ್ ಮಾಡಿ", diff --git a/src/Locale/ml.json b/src/Locale/ml.json index 00f649c6952..614a4005ef9 100644 --- a/src/Locale/ml.json +++ b/src/Locale/ml.json @@ -197,6 +197,7 @@ "retake": "വീണ്ടും എടുക്കുക", "submit": "സമർപ്പിക്കുക", "camera": "ക്യാമറ", + "camera_permission_denied": "ക്യാമറ അനുമതി നിഷേധിച്ചു", "submitting": "സമർപ്പിക്കുന്നു", "view_details": "വിശദാംശങ്ങൾ കാണുക", "type_to_search": "തിരയാൻ ടൈപ്പ് ചെയ്യുക", diff --git a/src/Locale/ta.json b/src/Locale/ta.json index ddaebbe2183..cb2eb506bc2 100644 --- a/src/Locale/ta.json +++ b/src/Locale/ta.json @@ -197,6 +197,7 @@ "retake": "மீண்டும் எடுக்கவும்", "submit": "சமர்ப்பிக்கவும்", "camera": "கேமரா", + "camera_permission_denied": "கேமரா அனுமதி நிராகரித்தது", "submitting": "சமர்ப்பிக்கிறது", "view_details": "விவரங்களைக் காண்க", "type_to_search": "தேட தட்டச்சு செய்யவும்", From aa90ad5b4c8fc0670533a4cbe3e24c7c9b57a286 Mon Sep 17 00:00:00 2001 From: Noufal Rahim <120470585+noufalrahim@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:28:15 +0530 Subject: [PATCH 3/3] fix: Removed useQuery from wrapper (#8716) Co-authored-by: Khavin Shankar --- .../Facility/LocationManagement.tsx | 196 ++++++++++-------- 1 file changed, 110 insertions(+), 86 deletions(-) diff --git a/src/Components/Facility/LocationManagement.tsx b/src/Components/Facility/LocationManagement.tsx index 8df40d9c5f2..1aaf57b7233 100644 --- a/src/Components/Facility/LocationManagement.tsx +++ b/src/Components/Facility/LocationManagement.tsx @@ -13,6 +13,7 @@ import ConfirmDialog from "../Common/ConfirmDialog"; import DialogModal from "../Common/Dialog"; import Uptime from "../Common/Uptime"; import useAuthUser from "../../Common/hooks/useAuthUser"; +import useQuery from "../../Utils/request/useQuery"; import Loading from "@/Components/Common/Loading"; interface Props { @@ -223,97 +224,120 @@ const Location = ({ disabled, setShowDeletePopup, facilityId, -}: LocationProps) => ( -

-
-
-
-

- {name} -

-
-

- {location_type} +}: LocationProps) => { + const { loading, data } = useQuery(routes.listFacilityBeds, { + query: { + facility: facilityId, + location: id, + }, + }); + + const totalBeds = data?.count ?? 0; + + if (loading) { + return ; + } + + return ( +

+
+
+
+

+ {name}

+
+

+ {location_type} +

+
-
-

- {description || "-"} -

-

- Middleware Address: -

-

- {middleware_address || "-"} -

- - Middleware Uptime -

- } - centerInfoPanel - /> -
- - - - Manage Beds - -
-
- - - Edit - -
-
- - setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) - } + {description || "-"} +

+

+ Middleware Address: +

+

- - Delete - + {middleware_address || "-"} +

+ + Middleware Uptime +

+ } + centerInfoPanel + />
-
-
- - + + Manage Beds + + + {totalBeds} + + +
+
+ + + Edit + +
+
+ + setShowDeletePopup({ open: true, name: name ?? "", id: id ?? "" }) + } + > + + Delete + +
+
+ +
+ + +
-
-); + ); +};