From 16af629c188f7da7fc914101d018b6ee34e4d30a Mon Sep 17 00:00:00 2001 From: Nikhila C <115739037+NikhilA8606@users.noreply.github.com> Date: Thu, 13 Feb 2025 16:58:49 +0530 Subject: [PATCH] Migrated Dialog and ConfirmDialog with shadCN component (#10510) --- public/locale/en.json | 11 + src/components/Common/AvatarEditModal.tsx | 460 +++++++++--------- src/components/Common/ConfirmDialog.tsx | 51 -- src/components/Common/Dialog.tsx | 87 ---- src/components/Common/FilePreviewDialog.tsx | 447 ++++++++--------- .../Facility/DuplicatePatientDialog.tsx | 206 ++++---- src/components/Facility/FacilityHome.tsx | 91 ++-- src/components/Files/CameraCaptureDialog.tsx | 283 +++++------ src/components/Patient/PatientHome.tsx | 24 - .../Patient/PatientRegistration.tsx | 7 +- src/components/Users/UserAvatar.tsx | 2 +- src/components/Users/UserDeleteDialog.tsx | 53 +- src/components/Users/UserSummary.tsx | 2 + src/hooks/useFileManager.tsx | 393 +++++++-------- src/hooks/useFileUpload.tsx | 4 +- 15 files changed, 1033 insertions(+), 1088 deletions(-) delete mode 100644 src/components/Common/ConfirmDialog.tsx delete mode 100644 src/components/Common/Dialog.tsx diff --git a/public/locale/en.json b/public/locale/en.json index 131cb515b31..6b6d794ed53 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -383,6 +383,7 @@ "approved_by_district_covid_control_room": "Approved by District COVID Control Room", "approving_facility": "Name of Approving Facility", "archive": "Archive", + "archive_file": "Archive File", "archived": "Archived", "archived_at": "Archived at", "archived_by": "Archived by", @@ -394,6 +395,7 @@ "are_you_sure_want_to_delete": "Are you sure you want to delete {{name}}?", "are_you_sure_want_to_delete_this_record": "Are you sure want to delete this record?", "are_you_sure_want_to_remove": "Are you sure you want to remove {{name}} from the patient? This action cannot be undone", + "are_you_sure_you_want_to_delete_user": "Are you sure you want to delete this user?", "ari": "ARI - Acute Respiratory illness", "arrived": "Arrived", "as_needed_prn": "As Needed / PRN", @@ -696,8 +698,10 @@ "delete_account_btn": "Yes, delete this account", "delete_account_note": "Deleting this account will remove all associated data and cannot be undone.", "delete_facility": "Delete Facility", + "delete_facility_confirmation": "Are you sure you want to delete {{name}}? This action cannot be undone.", "delete_item": "Delete {{name}}", "delete_record": "Delete Record", + "delete_user": "Delete User", "deleting": "Deleting...", "demography": "Demography", "denied_on": "Denied On", @@ -994,6 +998,7 @@ "facility_consent_requests_page_title": "Patient Consent List", "facility_count_one": "{{count}} Facility", "facility_count_other": "{{count}} Facilities ", + "facility_deleted_successfully": "{{name}} has been deleted successfully.", "facility_district_name": "Facility/District Name", "facility_district_pincode": "Facility/District/Pincode", "facility_for_care_support": "Facility for Care Support", @@ -1373,6 +1378,8 @@ "new_password_same_as_old": "Your new password must not match the old password ", "new_password_validation": "New password is not valid.", "new_session": "New Session", + "next": "Next", + "next_file": "Next file", "next_month": "Next month", "next_sessions": "Next Sessions", "next_week_short": "Next wk", @@ -1695,6 +1702,7 @@ "preset_name_placeholder": "Specify an identifiable name for the new preset", "preset_updated": "Preset updated", "prev_sessions": "Prev Sessions", + "previous": "Previous", "primary_ph_no": "Primary Ph No.", "primary_phone_no": "Primary ph. no.", "principal": "Principal", @@ -1857,6 +1865,8 @@ "right": "Right", "role": "Role", "room_apt": "Room/Apt & Time", + "rotate_left": "Rotate Left", + "rotate_right": "Rotate Right", "route": "Route", "routine": "Routine", "sample_collection_date": "Sample Collection Date", @@ -2053,6 +2063,7 @@ "something_wrong": "Something went wrong! Try again later!", "sort_by": "Sort By", "source": "Source", + "source_file": "Source Files", "spdx_sbom_version": "SPDX SBOM Version", "spokes": "Spoke Facilities", "srf_id": "SRF ID", diff --git a/src/components/Common/AvatarEditModal.tsx b/src/components/Common/AvatarEditModal.tsx index 31d0f772a60..3c278ea80b0 100644 --- a/src/components/Common/AvatarEditModal.tsx +++ b/src/components/Common/AvatarEditModal.tsx @@ -12,18 +12,22 @@ import { toast } from "sonner"; import CareIcon from "@/CAREUI/icons/CareIcon"; import { Button } from "@/components/ui/button"; - -import DialogModal from "@/components/Common/Dialog"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; import useDragAndDrop from "@/hooks/useDragAndDrop"; interface Props { title: string; open: boolean; + onOpenChange: (open: boolean) => void; imageUrl?: string; handleUpload: (file: File, onError: () => void) => Promise; handleDelete: (onError: () => void) => Promise; - onClose?: () => void; hint?: React.ReactNode; } @@ -48,10 +52,10 @@ type IVideoConstraint = const AvatarEditModal = ({ title, open, + onOpenChange, imageUrl, handleUpload, handleDelete, - onClose, hint, }: Props) => { const [isProcessing, setIsProcessing] = useState(false); @@ -91,7 +95,7 @@ const AvatarEditModal = ({ setPreview(undefined); setIsProcessing(false); setSelectedFile(undefined); - onClose?.(); + onOpenChange(false); }; useEffect(() => { @@ -179,246 +183,246 @@ const AvatarEditModal = ({ const hintMessage = hint || defaultHint; return ( - -
-
- {!isCameraOpen ? ( - <> - {preview || imageUrl ? ( - <> -
- cover-photo -
-

- {hintMessage} -

- - ) : ( -
-
+
+ {!isCameraOpen ? ( + <> + {preview || imageUrl ? ( + <> +
+ cover-photo +
+

+ {hintMessage} +

+ + ) : ( +
- - -

- {dragProps.fileDropError !== "" - ? dragProps.fileDropError - : `${t("drag_drop_image_to_upload")}`} -

-

- {t("no_image_found")}. {hintMessage} -

-
- )} + +

+ {dragProps.fileDropError !== "" + ? dragProps.fileDropError + : `${t("drag_drop_image_to_upload")}`} +

+

+ {t("no_image_found")}. {hintMessage} +

+
+ )} -
-
+
+
+ +
-
- -
- - {imageUrl && ( +
- )} - -
- - ) : ( - <> -
- {!previewImage ? ( - <> - { - setIsCameraOpen(false); - toast.warning(t("camera_permission_denied")); - }} - /> - - ) : ( - <> - - - )} -
- {/* buttons for mobile screens */} -
- {!previewImage ? ( - <> - - - - ) : ( - <> + {imageUrl && ( - - - )} -
- -
- - )} + )} + +
+ + ) : ( + <> +
+ {!previewImage ? ( + <> + { + setIsCameraOpen(false); + toast.warning(t("camera_permission_denied")); + }} + /> + + ) : ( + <> + + + )} +
+ {/* buttons for mobile screens */} +
+ {!previewImage ? ( + <> + + + + ) : ( + <> + + + + )} +
+ +
+ + )} +
-
- + + ); }; diff --git a/src/components/Common/ConfirmDialog.tsx b/src/components/Common/ConfirmDialog.tsx deleted file mode 100644 index 78cebe23f8e..00000000000 --- a/src/components/Common/ConfirmDialog.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { Button, ButtonVariant } from "@/components/ui/button"; - -import DialogModal from "@/components/Common/Dialog"; - -type ConfirmDialogProps = { - className?: string; - title: React.ReactNode; - description?: React.ReactNode; - disabled?: boolean; - show: boolean; - action: React.ReactNode; - variant?: ButtonVariant; - onClose: () => void; - onConfirm: () => void; - children?: React.ReactNode; - cancelLabel?: string; - name?: string; -}; - -const ConfirmDialog = ({ - disabled, - variant, - action, - onConfirm, - cancelLabel, - children, - name, - ...props -}: ConfirmDialogProps) => { - return ( - - {children} -
- - -
-
- ); -}; - -export default ConfirmDialog; diff --git a/src/components/Common/Dialog.tsx b/src/components/Common/Dialog.tsx deleted file mode 100644 index a67981dd3f8..00000000000 --- a/src/components/Common/Dialog.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import { - Dialog, - DialogPanel, - DialogTitle, - Transition, - TransitionChild, -} from "@headlessui/react"; - -import { classNames } from "@/Utils/utils"; - -type DialogProps = { - title: React.ReactNode; - description?: React.ReactNode; - show: boolean; - onClose: () => void; - children: React.ReactNode; - className?: string; - titleAction?: React.ReactNode; - fixedWidth?: boolean; -}; - -const DialogModal = (props: DialogProps) => { - const { - title, - description, - show, - onClose, - children, - className, - fixedWidth = true, - } = props; - return ( -
- - - -
- - -
-
- - - -
-

{title}

-

- {description} -

-
- {props.titleAction} -
- {children} -
-
-
-
-
-
-
- ); -}; - -export default DialogModal; diff --git a/src/components/Common/FilePreviewDialog.tsx b/src/components/Common/FilePreviewDialog.tsx index fbcaf9ae69a..cb556b84aae 100644 --- a/src/components/Common/FilePreviewDialog.tsx +++ b/src/components/Common/FilePreviewDialog.tsx @@ -16,9 +16,14 @@ import useKeyboardShortcut from "use-keyboard-shortcut"; import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon"; import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; import CircularProgress from "@/components/Common/CircularProgress"; -import DialogModal from "@/components/Common/Dialog"; import { StateInterface } from "@/components/Files/FileUpload"; import { FileUploadModel } from "@/components/Patient/models"; @@ -148,11 +153,11 @@ const FilePreviewDialog = (props: FilePreviewProps) => { }; function getRotationClass(rotation: number) { - let normalizedRotation = ((rotation % 360) + 360) % 360; // Normalize rotation to be within [0, 360) + let normalizedRotation = ((rotation % 360) + 360) % 360; if (normalizedRotation > 180) { - normalizedRotation -= 360; // Adjust to be within [-180, 180) + normalizedRotation -= 360; } - return normalizedRotation === -90 // Special case for -90 rotation since tailwind doesn't support 270deg + return normalizedRotation === -90 ? "-rotate-90" : `rotate-${normalizedRotation}`; } @@ -164,232 +169,236 @@ const FilePreviewDialog = (props: FilePreviewProps) => { ); return ( - { - handleClose(); - }} - title={{t("file_preview")}} - show={show} - > - {fileUrl ? ( - <> -
-
- - - -

- {fileNameTooltip} -

-
- -

- {fileName} +

!open && handleClose()}> + + + + {t("file_preview")} + + + + {fileUrl ? ( + <> +
+
+ + + +

+ {fileNameTooltip} +

+
+ +

+ {fileName} +

+
+
+
+ {uploadedFiles && + uploadedFiles[index] && + uploadedFiles[index].created_date && ( +

+ {t("created_on")}{" "} + {new Date( + uploadedFiles[index].created_date!, + ).toLocaleString("en-US", { + dateStyle: "long", + timeStyle: "short", + })}

- - - - {uploadedFiles && - uploadedFiles[index] && - uploadedFiles[index].created_date && ( -

- {t("created_on")}{" "} - {new Date( - uploadedFiles[index].created_date!, - ).toLocaleString("en-US", { - dateStyle: "long", - timeStyle: "short", - })} -

+ )} +
+
+ {downloadURL && downloadURL.length > 0 && ( + )} + +
-
- {downloadURL && downloadURL.length > 0 && ( - )} - -
-
-
- {uploadedFiles && uploadedFiles.length > 1 && ( - - )} -
- {file_state.isImage ? ( - file - ) : file_state.extension === "pdf" ? ( - }> - { - setPage(1); - setNumPages(numPages); - }} - pageNumber={page} - scale={scale} +
+ {file_state.isImage ? ( + file - - ) : previewExtensions.includes(file_state.extension) ? ( -