diff --git a/src/components/Directory/NoteCardDirectory.jsx b/src/components/Directory/NoteCardDirectory.jsx index 6fe7b144..2b5c0868 100644 --- a/src/components/Directory/NoteCardDirectory.jsx +++ b/src/components/Directory/NoteCardDirectory.jsx @@ -7,11 +7,12 @@ import showToast from "../../services/toastService"; import { cacheData, getCachedData } from "../../slices/apiDataManager"; import "../common/TextEditor/Editor.css"; -const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) => { +const NoteCardDirectory = ({refetchProfile,refetchNotes, noteItem, contactId, setProfileContact, }) => { const [editing, setEditing] = useState(false); const [editorValue, setEditorValue] = useState(noteItem.note); const [isLoading, setIsLoading] = useState(false); - const [isDeleting, setIsDeleting] = useState(false); + const [ isDeleting, setIsDeleting ] = useState( false ); + const [isActivProcess,setActiveProcessing]= useState(false) const handleUpdateNote = async () => { try { setIsLoading(true); @@ -63,10 +64,10 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) } }; - const handleDeleteNote = async () => { + const handleDeleteNote = async (activeStatue) => { try { - setIsDeleting(true); - const resp = await DirectoryRepository.DeleteNote(noteItem.id); + activeStatue ? setActiveProcessing(true) : setIsDeleting(true) + const resp = await DirectoryRepository.DeleteNote(noteItem.id,activeStatue); setProfileContact((prev) => ({ ...prev, notes: prev.notes.filter((note) => note.id !== noteItem.id), @@ -90,8 +91,11 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) cacheData("Contact Profile", updatedCache); } - setIsDeleting(false); - showToast("Note Deleted Successfully", "success"); + setIsDeleting( false ); + setActiveProcessing( false ) + refetchNotes( contactId, false ) + refetchProfile(contactId) + showToast(`Note ${activeStatue ? "Restored":"Deleted"} Successfully`, "success"); } catch (error) { setIsDeleting(false); const msg = @@ -101,13 +105,13 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) showToast(msg, "error"); } }; - return (
+
-
- setEditing(true)} - > - {!isDeleting && ( - - )} - {isDeleting && ( -
- Loading... -
- )} +
+ {noteItem.isActive ? ( + <> + setEditing(true)} + > + + {!isDeleting ? ( + handleDeleteNote(!noteItem.isActive)} + > + ) : ( +
+ Loading...
+ )} + + ) : isActivProcess ? ( + < i className='bx bx-refresh text-primary bx-spin' > + ) : ( + handleDeleteNote(!noteItem.isActive)} + title="Restore" + > + )} +
+

diff --git a/src/components/Directory/NotesDirectory.jsx b/src/components/Directory/NotesDirectory.jsx index 1c94d9d6..87707596 100644 --- a/src/components/Directory/NotesDirectory.jsx +++ b/src/components/Directory/NotesDirectory.jsx @@ -16,9 +16,9 @@ const schema = z.object({ note: z.string().min(1, { message: "Note is required" }), }); -const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { +const NotesDirectory = ({refetchProfile, isLoading, contactProfile, setProfileContact }) => { const [IsActive, setIsActive] = useState(true); - const { contactNotes } = useContactNotes(contactProfile?.id, !IsActive); + const {contactNotes,refetch} = useContactNotes( contactProfile?.id, true ); const [NotesData, setNotesData] = useState(); const [IsSubmitting, setIsSubmitting] = useState(false); @@ -85,6 +85,14 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { const onCancel = () => { setValue("note", ""); }; + const handleSwitch = () => + { + setIsActive( !IsActive ) + if ( IsActive ) + { + refetch(contactProfile?.id, false) + } + } return (
@@ -95,7 +103,7 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { setIsActive(!IsActive)} + onChange={()=>handleSwitch(!IsActive)} value={IsActive} /> @@ -106,9 +114,13 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { {/* */} - Show Inactive Notes + Show Including Inactive Notes - +
+
+ setAddNote(!addNote)} > @@ -119,7 +131,6 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { > */} {addNote ? "close" : "Add Note"} -
{addNote && (
@@ -143,30 +154,34 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { )} {!isLoading && - [...(IsActive ? contactProfile?.notes || [] : contactNotes || [])] - .reverse() - .map((noteItem) => ( - - ))} + [...(IsActive ? contactProfile?.notes || [] : contactNotes || [])] + .reverse() + .map((noteItem) => ( + + ))} + {IsActive && ( -

+

{!isLoading && contactProfile?.notes.length == 0 && !addNote && ( -

No Notes Found

+
No Notes Found
)} -

+
)} {!IsActive && ( -

+

{!isLoading && contactNotes.length == 0 && !addNote && ( -

No Notes Found

+
No Notes Found
)} -

+
)}