diff --git a/src/components/Directory/NoteCardDirectory.jsx b/src/components/Directory/NoteCardDirectory.jsx
index 71ef9843..6fe7b144 100644
--- a/src/components/Directory/NoteCardDirectory.jsx
+++ b/src/components/Directory/NoteCardDirectory.jsx
@@ -7,7 +7,7 @@ import showToast from "../../services/toastService";
import { cacheData, getCachedData } from "../../slices/apiDataManager";
import "../common/TextEditor/Editor.css";
-const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
+const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) => {
const [editing, setEditing] = useState(false);
const [editorValue, setEditorValue] = useState(noteItem.note);
const [isLoading, setIsLoading] = useState(false);
@@ -50,7 +50,8 @@ const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
cacheData("Contact Profile", updatedProfile);
}
setEditing(false);
- setIsLoading(false);
+ setIsLoading( false );
+
showToast("Note Updated successfully", "success");
} catch (error) {
setIsLoading(false);
@@ -104,7 +105,7 @@ const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
return (
@@ -128,7 +129,7 @@ const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
-
+
setEditing(true)}
diff --git a/src/components/Directory/NotesDirectory.jsx b/src/components/Directory/NotesDirectory.jsx
index ba4c1b31..5a3c38a4 100644
--- a/src/components/Directory/NotesDirectory.jsx
+++ b/src/components/Directory/NotesDirectory.jsx
@@ -10,12 +10,18 @@ import moment from "moment";
import { cacheData, getCachedData } from "../../slices/apiDataManager";
import NoteCardDirectory from "./NoteCardDirectory";
import showToast from "../../services/toastService";
+import {useContactNotes} from "../../hooks/useDirectory";
const schema = z.object({
note: z.string().min(1, { message: "Note is required" }),
});
-const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
+const NotesDirectory = ( {isLoading, contactProfile, setProfileContact} ) =>
+{
+ const [ IsActive, setIsActive ] = useState( true )
+ const {contactNotes} = useContactNotes(contactProfile?.id,!IsActive)
+
+
const [NotesData, setNotesData] = useState();
const [IsSubmitting, setIsSubmitting] = useState(false);
const [addNote, setAddNote] = useState(false);
@@ -66,7 +72,8 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
setValue("note", "");
setIsSubmitting(false);
showToast("Note added successfully!", "success");
- setAddNote(false);
+ setAddNote( false );
+ setIsActive(true)
} catch (error) {
setIsSubmitting(false);
const msg =
@@ -85,7 +92,21 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
{addNote && (
)}
{!isLoading &&
- [...(contactProfile?.notes || [])]
+ [...(IsActive ? contactProfile?.notes || [] : contactNotes || [])]
.reverse()
.map((noteItem) => (
) )}
-
{!isLoading && contactProfile?.notes.length == 0 && !addNote && (
No Notes Found
) }
+ {IsActive && (
{!isLoading && contactProfile?.notes.length == 0 && !addNote && (
No Notes Found
)} )}
+ {!IsActive && (
+
{!isLoading && contactNotes.length == 0 && !addNote && (
No Notes Found
) }
+
+ )}
);
diff --git a/src/hooks/useDirectory.js b/src/hooks/useDirectory.js
index b27dc63a..c21044fb 100644
--- a/src/hooks/useDirectory.js
+++ b/src/hooks/useDirectory.js
@@ -109,9 +109,9 @@ const fetchContactProfile = async () => {
}
-export const useContactNotes = (id) =>
+export const useContactNotes = (id,IsActive) =>
{
- const [ conatNotes, setContactNotes ] = useState( [] );
+ const [ contactNotes, setContactNotes ] = useState( [] );
const [ loading, setLoading ] = useState( false );
const [ Error, setError ] = useState( "" );
@@ -122,7 +122,7 @@ const fetchContactNotes = async () => {
if (!cached || cached.contactId !== id) {
setLoading(true);
try {
- const resp = await DirectoryRepository.GetNote(id);
+ const resp = await DirectoryRepository.GetNote(id,IsActive);
setContactNotes(resp.data);
cacheData("Contact Notes", { data: resp.data, contactId: id });
} catch (err) {
@@ -144,5 +144,5 @@ const fetchContactNotes = async () => {
}
}, [id]);
- return { conatProfile, loading, Error };
+ return { contactNotes, loading, Error };
}
diff --git a/src/hooks/useDirectoryFilter.js b/src/hooks/useDirectoryFilter.js
new file mode 100644
index 00000000..3bedbff2
--- /dev/null
+++ b/src/hooks/useDirectoryFilter.js
@@ -0,0 +1,21 @@
+import React, { useEffect } from "react";
+import { useDirectory } from "./useDirectory";
+
+export const useDirectoryFilter = (active) => {
+ const { contacts, loading, refetch } = useDirectory( active);
+ // Debounced search refetch
+ useEffect(() => {
+ // if (searchQuery) {
+ // const timer = setTimeout(() => {
+ // refetch(searchQuery, active, [], []);
+ // }, 1000);
+ // return () => clearTimeout(timer);
+ // }
+ refetch(active)
+ }, [ active]);
+
+ return {
+ contacts,
+ loading,
+ };
+};
diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx
index c3e3830f..ecc6e910 100644
--- a/src/pages/Directory/Directory.jsx
+++ b/src/pages/Directory/Directory.jsx
@@ -18,7 +18,7 @@ import ConfirmModal from "../../components/common/ConfirmModal";
const Directory = () =>
{
- const[IsActivite,setIsActive] = useState(true)
+ const[IsActive,setIsActive] = useState(true)
const [isOpenModal, setIsOpenModal] = useState(false);
const [isOpenModalNote, setIsOpenModalNote] = useState(false);
const [selectedContact, setSelectedContact] = useState(null);
@@ -34,7 +34,7 @@ const Directory = () =>
const [tempSelectedBucketIds, setTempSelectedBucketIds] = useState([]);
const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]);
- const { contacts, loading } = useDirectory(IsActivite);
+ const { contacts, loading } = useDirectory(IsActive);
const { contactCategory, loading: contactCategoryLoading } =
useContactCategory();
const { buckets } = useBuckets();
@@ -42,7 +42,7 @@ const Directory = () =>
try {
let response;
let updatedContacts;
- const contacts_cache = getCachedData("contacts") || [];
+ const contacts_cache = getCachedData("contacts")?.data || [];
if (selectedContact) {
response = await DirectoryRepository.UpdateContact(data.id, data);
@@ -58,7 +58,7 @@ const Directory = () =>
showToast("Contact created successfully", "success");
setIsOpenModal(false);
}
-
+ cacheData("Contacts", {data:updatedContacts,isActive:IsActive});
setContactList(updatedContacts);
} catch (error) {
const msg =
@@ -72,12 +72,12 @@ const Directory = () =>
const handleDeleteContact = async () => {
try {
setIsDeletng(true);
- const contacts_cache = getCachedData("contacts") || [];
+ const contacts_cache = getCachedData("contacts")?.data || [];
const response = await DirectoryRepository.DeleteContact(deleteContact);
const updatedContacts = ContactList.filter((c) => c.id !== deleteContact);
setContactList(updatedContacts);
- cacheData("Contacts", updatedContacts);
+ cacheData("Contacts", {data:updatedContacts,isActive:IsActive});
showToast("Contact deleted successfully", "success");
setDeleteContact(null);
@@ -104,7 +104,6 @@ const Directory = () =>
useEffect(() => {
setContactList(contacts);
- // Set temp filter list only (UI checkboxes, not actual filtering yet)
setTempSelectedCategoryIds([]);
setTempSelectedBucketIds([]);
}, [contacts]);
@@ -380,7 +379,7 @@ const Directory = () =>
Category |
- Action |
+ {IsActive && Action | }
@@ -473,6 +472,7 @@ const Directory = () =>
currentItems.map((contact) => (
className="col-12 col-sm-6 col-md-4 col-lg-4 mb-4"
>