diff --git a/src/components/common/TagInput.jsx b/src/components/common/TagInput.jsx
index c40a278f..6430197e 100644
--- a/src/components/common/TagInput.jsx
+++ b/src/components/common/TagInput.jsx
@@ -60,7 +60,7 @@ useEffect(() => {
};
const handleInputKeyDown = (e) => {
- if (e.key === "Enter" && input.trim() !== "") {
+ if ((e.key === "Enter" || e.key === " ")&& input.trim() !== "") {
e.preventDefault();
const existing = options.find(
(opt) => opt.name.toLowerCase() === input.trim().toLowerCase()
diff --git a/src/components/common/TextEditor/Editor.jsx b/src/components/common/TextEditor/Editor.jsx
index 84f9728f..dd6938f2 100644
--- a/src/components/common/TextEditor/Editor.jsx
+++ b/src/components/common/TextEditor/Editor.jsx
@@ -29,21 +29,22 @@ const Editor = ({
"code-block",
"link",
"align",
- "image"
+ "image",
];
return (
-
);
};
diff --git a/src/data/menuData.json b/src/data/menuData.json
index 0870d187..f0b6b12f 100644
--- a/src/data/menuData.json
+++ b/src/data/menuData.json
@@ -23,11 +23,6 @@
"text": "Employees",
"available": true,
"link": "/employees"
- },
- {
- "text": "Directory",
- "available": true,
- "link": "/directory"
}
]
},
@@ -68,6 +63,12 @@
"link": "/activities/gallary"
}
]
+ },
+ {
+ "text": "Directory",
+ "icon": "bx bx-folder",
+ "available": true,
+ "link": "/directory"
},
{
"text": "Administration",
diff --git a/src/hooks/useDirectory.js b/src/hooks/useDirectory.js
index df352b98..1c0c3433 100644
--- a/src/hooks/useDirectory.js
+++ b/src/hooks/useDirectory.js
@@ -72,14 +72,12 @@ export const useBuckets = () => {
};
export const useContactProfile = (id) => {
- const [conatProfile, setContactProfile] = useState(null);
+ const [contactProfile, setContactProfile] = useState(null);
const [loading, setLoading] = useState(false);
const [Error, setError] = useState("");
const fetchContactProfile = async () => {
- const cached = getCachedData("Contact Profile");
- if (!cached || cached.contactId !== id) {
setLoading(true);
try {
const resp = await DirectoryRepository.GetContactProfile(id);
@@ -94,18 +92,20 @@ export const useContactProfile = (id) => {
} finally {
setLoading(false);
}
+
+ };
+
+ useEffect( () =>
+ {
+ const cached = getCachedData("Contact Profile");
+ if (!cached || cached.contactId !== id) {
+ fetchContactProfile(id);
} else {
setContactProfile(cached.data);
}
- };
-
- useEffect(() => {
- if (id) {
- fetchContactProfile(id);
- }
}, [id]);
- return { conatProfile, loading, Error };
+ return { contactProfile, loading, Error ,refetch:fetchContactProfile};
};
export const useContactNotes = (id, IsActive) => {
@@ -113,10 +113,9 @@ export const useContactNotes = (id, IsActive) => {
const [loading, setLoading] = useState(false);
const [Error, setError] = useState("");
- const fetchContactNotes = async () => {
- const cached = getCachedData("Contact Notes");
+ const fetchContactNotes = async (id,IsActive) => {
+
- if (!cached || cached.contactId !== id) {
setLoading(true);
try {
const resp = await DirectoryRepository.GetNote(id, IsActive);
@@ -131,18 +130,19 @@ export const useContactNotes = (id, IsActive) => {
} finally {
setLoading(false);
}
- } else {
- setContactNotes(cached.data);
- }
+
};
useEffect(() => {
- if (id) {
- fetchContactNotes(id);
+ const cached = getCachedData("Contact Notes");
+ if (!cached || cached.contactId !== id) {
+ id && fetchContactNotes(id,IsActive);
+ } else {
+ setContactNotes(cached.data);
}
- }, [id]);
+ }, [id,IsActive]);
- return { contactNotes, loading, Error };
+ return { contactNotes, loading, Error,refetch:fetchContactNotes };
};
export const useOrganization = () => {
diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx
index b19eecf3..a9ceab49 100644
--- a/src/pages/Directory/Directory.jsx
+++ b/src/pages/Directory/Directory.jsx
@@ -19,6 +19,7 @@ import DirectoryListTableHeader from "./DirectoryListTableHeader";
import DirectoryPageHeader from "./DirectoryPageHeader";
import ManageBucket from "../../components/Directory/ManageBucket";
import {useFab} from "../../Context/FabContext";
+import {DireProvider, useDir} from "../../Context/DireContext";
const Directory = () =>
{
@@ -33,12 +34,15 @@ const Directory = () =>
const [listView, setListView] = useState(false);
const [selectedBucketIds, setSelectedBucketIds] = useState([]);
const [deleteContact, setDeleteContact] = useState(null);
- const [ IsDeleting, setIsDeletng ] = useState( false );
- const [openBucketModal,setOpenBucketModal] = useState(false)
+ const [ IsDeleting, setDeleting ] = useState( false );
+ const [ openBucketModal, setOpenBucketModal ] = useState( false )
+
const [tempSelectedBucketIds, setTempSelectedBucketIds] = useState([]);
const [ tempSelectedCategoryIds, setTempSelectedCategoryIds ] = useState( [] );
- const {setActions} = useFab()
+ const {setActions} = useFab()
+ const { dirActions, setDirActions } = useDir();
+
const { contacts, loading , refetch} = useDirectory(IsActive);
const { contactCategory, loading: contactCategoryLoading } =
@@ -78,28 +82,43 @@ const Directory = () =>
}
};
- const handleDeleteContact = async () => {
- try {
- setIsDeletng(true);
- const contacts_cache = getCachedData("contacts")?.data || [];
-
- const response = await DirectoryRepository.DeleteContact(deleteContact);
- const updatedContacts = ContactList.filter( ( c ) => c.id !== deleteContact );
- setContactList(updatedContacts);
- cacheData("Contacts", {data:updatedContacts,isActive:IsActive});
- showToast("Contact deleted successfully", "success");
- setDeleteContact(null);
-
- setIsDeletng(false);
- } catch (error) {
- const msg =
- error.response.data.message ||
- error.message ||
- "Error occured during API calling";
- showToast(msg, "error");
- setIsDeletng(false);
+const handleDeleteContact = async (overrideId = null) => {
+ try
+ {
+ if (!IsActive) {
+ setDirActions((prev) => ({ ...prev, action: true }));
+ } else {
+ setDeleting(true);
}
- };
+ const id = overrideId || (!IsActive ? dirActions.id : deleteContact);
+ if (!id) {
+ showToast("No contact selected for deletion", "error");
+ return;
+ }
+
+ await DirectoryRepository.DeleteContact(id, !IsActive);
+
+ const updatedContacts = ContactList.filter((c) => c.id !== id);
+ setContactList(updatedContacts);
+ cacheData("Contacts", { data: updatedContacts, isActive: IsActive });
+
+ showToast(`Contact ${IsActive ? "Deleted":"Restored"} successfully`, "success");
+
+ setDeleteContact(null);
+ setDirActions({ action: false, id: null });
+ setDeleting(false);
+ } catch (error) {
+ const msg =
+ error?.response?.data?.message ||
+ error.message ||
+ "Error occurred during API call";
+ showToast(msg, "error");
+
+ setDeleting(false);
+ setDirActions({ action: false, id: null });
+ }
+};
+
const closedModel = () => {
setIsOpenModal(false);
@@ -306,7 +325,6 @@ const Directory = () =>
applyFilter={applyFilter}
loading={loading}
IsActive={IsActive}
- setIsOpenModal={setIsOpenModal}
setOpenBucketModal={setOpenBucketModal}
/>
{!listView && loading &&
Loading...
}
@@ -314,7 +332,7 @@ const Directory = () =>
No Matching Contact Found
)}
{listView ? (
-
+
{loading && (
Loading... |
@@ -336,6 +354,7 @@ const Directory = () =>
setOpen_contact={setOpen_contact}
setIsOpenModalNote={setIsOpenModalNote}
IsDeleted={setDeleteContact}
+ restore={handleDeleteContact}
/>
))}
@@ -354,15 +373,16 @@ const Directory = () =>
setOpen_contact={setOpen_contact}
setIsOpenModalNote={setIsOpenModalNote}
IsDeleted={setDeleteContact}
+ restore={handleDeleteContact}
/>
))}
)}
-
-
+
+
- {!loading && currentItems < ITEMS_PER_PAGE && (
+ {!loading && currentItems < ITEMS_PER_PAGE && (
)}
-
+
);
};
diff --git a/src/pages/Directory/DirectoryListTableHeader.jsx b/src/pages/Directory/DirectoryListTableHeader.jsx
index fd372b3d..3c53e02d 100644
--- a/src/pages/Directory/DirectoryListTableHeader.jsx
+++ b/src/pages/Directory/DirectoryListTableHeader.jsx
@@ -1,14 +1,12 @@
-import React from 'react'
-import IconButton from '../../components/common/IconButton';
+import React from "react";
+import IconButton from "../../components/common/IconButton";
-
-const DirectoryListTableHeader = ( {children, IsActive} ) =>
-{
+const DirectoryListTableHeader = ({ children }) => {
return (
-
+
Name
@@ -25,13 +23,10 @@ const DirectoryListTableHeader = ( {children, IsActive} ) =>
|
-
-
- Organization
-
+ Organization
|
Category |
- {IsActive && Action | }
+ Action |
@@ -41,4 +36,4 @@ const DirectoryListTableHeader = ( {children, IsActive} ) =>
);
};
-export default DirectoryListTableHeader;
\ No newline at end of file
+export default DirectoryListTableHeader;
diff --git a/src/pages/Directory/DirectoryPageHeader.jsx b/src/pages/Directory/DirectoryPageHeader.jsx
index fcf603f4..fb782c3f 100644
--- a/src/pages/Directory/DirectoryPageHeader.jsx
+++ b/src/pages/Directory/DirectoryPageHeader.jsx
@@ -16,7 +16,6 @@ const DirectoryPageHeader = ({
applyFilter,
loading,
IsActive,
- setIsOpenModal,
setOpenBucketModal,
}) => {
const [filtered, setFiltered] = useState();
@@ -99,7 +98,7 @@ const DirectoryPageHeader = ({
{filteredBuckets.map(({ id, name }) => (
@@ -127,7 +126,7 @@ const DirectoryPageHeader = ({
{filteredCategories.map(({ id, name }) => (
@@ -169,38 +168,10 @@ const DirectoryPageHeader = ({
-
-
-
>
diff --git a/src/repositories/DirectoryRepository.jsx b/src/repositories/DirectoryRepository.jsx
index c123cf82..ac9fa617 100644
--- a/src/repositories/DirectoryRepository.jsx
+++ b/src/repositories/DirectoryRepository.jsx
@@ -6,7 +6,7 @@ export const DirectoryRepository = {
GetContacts: (isActive) => api.get( `/api/directory?active=${isActive}` ),
CreateContact: ( data ) => api.post( '/api/directory', data ),
UpdateContact: ( id, data ) => api.put( `/api/directory/${ id }`, data ),
- DeleteContact: ( id ) => api.delete( `/api/directory/${ id }` ),
+ DeleteContact: ( id,isActive) => api.delete( `/api/directory/${ id }/?active=${isActive}` ),
AssignedBuckets:(id,data)=>api.post(`/api/directory/assign-bucket/${id}`,data),
GetBucktes: () => api.get( `/api/directory/buckets` ),
@@ -19,5 +19,5 @@ export const DirectoryRepository = {
CreateNote: ( data ) => api.post( '/api/directory/note', data ),
GetNote: ( id,isActive ) => api.get( `/api/directory/notes/${ id }?active=${isActive}` ),
UpdateNote: ( id, data ) => api.put( `/api/directory/note/${ id }`, data ),
- DeleteNote:(id)=> api.delete(`/api/directory/note/${ id }`)
+ DeleteNote:(id,isActive)=> api.delete(`/api/directory/note/${ id }?active=${isActive}`)
}
\ No newline at end of file