diff --git a/src/components/Directory/NotesDirectory.jsx b/src/components/Directory/NotesDirectory.jsx index 2b4d0450..f310bfcc 100644 --- a/src/components/Directory/NotesDirectory.jsx +++ b/src/components/Directory/NotesDirectory.jsx @@ -19,18 +19,13 @@ const NotesDirectory = ({ refetchProfile, isLoading, contactProfile, // This contactProfile now reliably includes firstName, middleName, lastName, and fullName - contactProfile, // This contactProfile now reliably includes firstName, middleName, lastName, and fullName setProfileContact, }) => { const [IsActive, setIsActive] = useState(true); - const { contactNotes, refetch } = useContactNotes( - contactProfile?.id, - IsActive - ); + const { contactNotes, refetch } = useContactNotes(contactProfile?.id, IsActive); const [IsSubmitting, setIsSubmitting] = useState(false); const [showEditor, setShowEditor] = useState(false); - const [showEditor, setShowEditor] = useState(false); const { register, handleSubmit, @@ -71,30 +66,22 @@ const NotesDirectory = ({ const updatedProfile = { ...cached_contactProfile.data, notes: [...(cached_contactProfile.data.notes || []), createdNote], - notes: [...(cached_contactProfile.data.notes || []), createdNote], }; - cacheData("Contact Profile", { - contactId: contactProfile?.id, - data: updatedProfile, - }); + cacheData("Contact Profile", { contactId: contactProfile?.id, data: updatedProfile }); } setValue("note", ""); setIsSubmitting(false); showToast("Note added successfully!", "success"); setShowEditor(false); - setShowEditor(false); setIsActive(true); refetch(contactProfile?.id, true); - refetch(contactProfile?.id, true); } catch (error) { setIsSubmitting(false); const msg = - error.response?.data?.message || error.response?.data?.message || error.message || "Error occurred during API calling"; - "Error occurred during API calling"; showToast(msg, "error"); } }; @@ -102,11 +89,8 @@ const NotesDirectory = ({ const onCancel = () => { setValue("note", ""); setShowEditor(false); - setValue("note", ""); - setShowEditor(false); }; - const handleSwitch = () => { setIsActive((prevIsActive) => { const newState = !prevIsActive; @@ -116,35 +100,36 @@ const NotesDirectory = ({ }; // Use the fullName from contactProfile, which now includes middle and last names if available - const contactName = - contactProfile?.fullName || contactProfile?.firstName || "Contact"; + const contactName = contactProfile?.fullName || contactProfile?.firstName || "Contact"; const noNotesMessage = `Be the first to share your insights! ${contactName} currently has no notes.`; - const notesToDisplay = IsActive - ? contactProfile?.notes || [] - : contactNotes || []; + const notesToDisplay = IsActive ? (contactProfile?.notes || []) : (contactNotes || []); return ( -
-
-
-

Notes :

-
-
- {" "} -
-
+
+
+ {(contactProfile?.notes?.length > 0 || contactNotes?.length > 0) && ( + + )} + {!(contactProfile?.notes?.length > 0 || contactNotes?.length > 0) && ( +
+ - - {!showEditor && ( -
- -
- )}
-
+ )}
+ + {!showEditor && ( +
+ +
+ )} +
{showEditor && (
- setShowEditor(false)} - > - - + >
- {errors.note && ( {errors.note && (

{errors.note.message}

)} @@ -205,7 +189,6 @@ const NotesDirectory = ({
)} -
{isLoading && (
@@ -213,28 +196,31 @@ const NotesDirectory = ({

Loading...

{" "}
)} - {!isLoading && notesToDisplay.length > 0 - ? notesToDisplay - .slice() - .reverse() - .map((noteItem) => ( - - )) - : !isLoading && - !showEditor && ( -
{noNotesMessage}
- )} + {!isLoading && notesToDisplay.length > 0 ? ( + notesToDisplay + .slice() + .reverse() + .map((noteItem) => ( + + )) + ) : ( + !isLoading && !showEditor && ( +
+ {noNotesMessage} +
+ ) + )}
); }; -export default NotesDirectory; +export default NotesDirectory; \ No newline at end of file