Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaySagar-Git committed Dec 10, 2024
1 parent d29a2c1 commit 2dc1e10
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/components/Common/DiscussionNotesEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { t } from "i18next";
import React, { useEffect, useRef, useState } from "react";
import useKeyboardShortcut from "use-keyboard-shortcut";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -13,7 +14,7 @@ import NotePreview from "@/components/Common/NotePreview";
import useFileUpload from "@/hooks/useFileUpload";

import { getCaretCoordinates, getCaretInfo } from "@/Utils/textEditor";
import { classNames } from "@/Utils/utils";
import { classNames, isAppleDevice } from "@/Utils/utils";

interface DiscussionNotesEditorProps {
initialNote?: string;
Expand All @@ -23,6 +24,7 @@ interface DiscussionNotesEditorProps {
onRefetch?: () => void;
maxRows?: number;
className?: string;
parentRef?: React.RefObject<HTMLElement>;
}

const DiscussionNotesEditor: React.FC<DiscussionNotesEditorProps> = ({
Expand All @@ -33,6 +35,7 @@ const DiscussionNotesEditor: React.FC<DiscussionNotesEditorProps> = ({
onRefetch,
maxRows,
className,
parentRef,
}) => {
const editorRef = useRef<HTMLTextAreaElement>(null);
const [showMentions, setShowMentions] = useState(false);
Expand Down Expand Up @@ -154,6 +157,20 @@ const DiscussionNotesEditor: React.FC<DiscussionNotesEditorProps> = ({
});
};

useKeyboardShortcut(
[isAppleDevice ? "Meta" : "Shift", "Enter"],
async () => {
if (editorRef.current && text.trim()) {
await onAddNote();
setText("");
onRefetch?.();
}
},
{
ignoreInputFields: false,
},
);

return (
<div className="mx-2 mb-2">
<div className="relative">
Expand Down Expand Up @@ -287,6 +304,7 @@ const DiscussionNotesEditor: React.FC<DiscussionNotesEditorProps> = ({
position={mentionPosition}
filter={mentionFilter}
containerRef={editorRef}
parentRef={parentRef}
/>
)}

Expand Down
22 changes: 16 additions & 6 deletions src/components/Common/MentionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface MentionsDropdownProps {
position: { top: number; left: number };
filter: string;
containerRef: React.RefObject<HTMLTextAreaElement>;
parentRef?: React.RefObject<HTMLElement>;
}

const KEYS = {
Expand All @@ -28,6 +29,7 @@ const MentionsDropdown: React.FC<MentionsDropdownProps> = ({
position,
filter,
containerRef,
parentRef,
}) => {
const facilityId = useSlug("facility");
const { data, loading } = useQuery(routes.getFacilityUsers, {
Expand All @@ -38,16 +40,24 @@ const MentionsDropdown: React.FC<MentionsDropdownProps> = ({

const [dropdownPosition, setDropdownPosition] = useState({ top: 0, left: 0 });
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);

useEffect(() => {
if (containerRef.current) {
const rect = containerRef.current.getBoundingClientRect();
setDropdownPosition({
top: rect.top + position.top,
left: rect.left + position.left,
});
const parentRect = parentRef?.current?.getBoundingClientRect();

if (parentRef?.current && parentRect) {
setDropdownPosition({
top: rect.top - parentRect.top + position.top,
left: rect.left - parentRect.left + position.left,
});
} else {
setDropdownPosition({
top: rect.top + position.top,
left: rect.left + position.left,
});
}
}
}, [position, containerRef]);
}, [position, containerRef, parentRef]);

const filteredUsers = useMemo(() => {
return users.filter((user) =>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Facility/PatientNotesSlideover.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from "raviger";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon from "@/CAREUI/icons/CareIcon";
Expand Down Expand Up @@ -51,6 +51,8 @@ export default function PatientNotesSlideover(props: PatientNotesProps) {
undefined,
);

const slideoverRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (notificationSubscriptionState === "unsubscribed") {
Notification.Warn({
Expand Down Expand Up @@ -215,6 +217,7 @@ export default function PatientNotesSlideover(props: PatientNotesProps) {

return (
<div
ref={slideoverRef}
className={classNames(
"fixed bottom-0 z-20 sm:right-8",
show
Expand Down Expand Up @@ -283,6 +286,7 @@ export default function PatientNotesSlideover(props: PatientNotesProps) {
onRefetch={refetch}
maxRows={10}
className="mt-2"
parentRef={slideoverRef}
/>
</DoctorNoteReplyPreviewCard>
)}
Expand Down
41 changes: 35 additions & 6 deletions src/components/Files/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,21 @@ export const FileUpload = (props: FileUploadProps) => {
silent: true,
});

const discussionNotesQuery = useQuery(routes.viewUpload, {
query: {
file_type: "PATIENT_NOTES",
consultation_id: consultationId,
is_archived: false,
limit: RESULTS_PER_PAGE_LIMIT,
offset: offset,
},
});

const queries = {
UNARCHIVED: activeFilesQuery,
ARCHIVED: archivedFilesQuery,
DISCHARGE_SUMMARY: dischargeSummaryQuery,
PATIENT_NOTES: discussionNotesQuery,
};

const refetchAll = async () =>
Expand All @@ -173,6 +184,14 @@ export const FileUpload = (props: FileUploadProps) => {
},
]
: []),
...(discussionNotesQuery.data?.results?.length
? [
{
text: "Patient Notes",
value: "PATIENT_NOTES",
},
]
: []),
];

const fileUpload = useFileUpload({
Expand Down Expand Up @@ -225,6 +244,12 @@ export const FileUpload = (props: FileUploadProps) => {
onEdit: refetchAll,
});

const patientNotesFileManager = useFileManager({
type: "PATIENT_NOTES",
onArchive: refetchAll,
onEdit: refetchAll,
});

const uploadButtons: {
name: string;
icon: IconName;
Expand Down Expand Up @@ -258,7 +283,8 @@ export const FileUpload = (props: FileUploadProps) => {
{fileUpload.Dialogues}
{fileManager.Dialogues}
{dischargeSummaryFileManager.Dialogues}
{!hideUpload && (
{patientNotesFileManager.Dialogues}
{!hideUpload && tab !== "PATIENT_NOTES" && (
<AuthorizedChild authorizeFor={NonReadOnlyUsers}>
{({ isAuthorized }) =>
isAuthorized ? (
Expand Down Expand Up @@ -357,17 +383,20 @@ export const FileUpload = (props: FileUploadProps) => {
file={item}
key={item.id}
fileManager={
tab !== "DISCHARGE_SUMMARY"
? fileManager
: dischargeSummaryFileManager
{
DISCHARGE_SUMMARY: dischargeSummaryFileManager,
PATIENT_NOTES: patientNotesFileManager,
}[tab] || fileManager
}
associating_id={
tab === "PATIENT_NOTES" ? item.associating_id! : associatedId
}
associating_id={associatedId}
editable={
item?.uploaded_by?.username === authUser.username ||
authUser.user_type === "DistrictAdmin" ||
authUser.user_type === "StateAdmin"
}
archivable={tab !== "DISCHARGE_SUMMARY"}
archivable={!["PATIENT_NOTES", "DISCHARGE_SUMMARY"].includes(tab)}
/>
))}
{!(fileQuery?.data?.results || []).length && (
Expand Down

0 comments on commit 2dc1e10

Please sign in to comment.