From af996196a1560a8ea4bcb969a01d2ea43feaf6ac Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Fri, 23 May 2025 16:55:42 +0530 Subject: [PATCH 1/9] modified hook, for taking active or incative params --- src/hooks/useDirectory.js | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/hooks/useDirectory.js b/src/hooks/useDirectory.js index 7d18a554..b27dc63a 100644 --- a/src/hooks/useDirectory.js +++ b/src/hooks/useDirectory.js @@ -2,35 +2,43 @@ import { useEffect, useState } from "react"; import { DirectoryRepository } from "../repositories/DirectoryRepository"; import { cacheData, getCachedData } from "../slices/apiDataManager"; -export const useDirectory = () => { +export const useDirectory = (isActive) => { const [contacts, setContacts] = useState([]); const [loading, setLoading] = useState(false); - const [error, setError] = useState(); + const [error, setError] = useState(null); - const fetch = async () => { - const cache_contacts = getCachedData("contacts"); - if (!cache_contacts) { - setLoading(true); - try { - const response = await DirectoryRepository.GetContacts(); - setContacts(response.data); - cacheData("contacts", response.data); - setLoading(false); - } catch (error) { - setError(error); - setLoading(false); - } - } else { - setContacts(cache_contacts); + const fetch = async (activeParam = isActive) => { + setLoading(true); + try { + const response = await DirectoryRepository.GetContacts(activeParam); + setContacts(response.data); + cacheData("contacts", { data: response.data, isActive: activeParam }); + } catch (error) { + setError(error); + } finally { + setLoading(false); } }; - useState(() => { - fetch(); - }, []); - return { contacts, loading, error }; + useEffect(() => { + const cachedContacts = getCachedData("contacts"); + if (!cachedContacts?.data || cachedContacts.isActive !== isActive) { + fetch(isActive); + } else { + setContacts(cachedContacts.data); + } + }, [isActive]); + + return { + contacts, + loading, + error, + refetch: fetch, + }; }; + + export const useBuckets = () => { const [buckets, setBuckets] = useState([]); const [loading, setLoading] = useState(false); -- 2.43.0 From 6943f4e9ca9ac6ce8d7121e512705bf8feddb608 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Fri, 23 May 2025 16:56:52 +0530 Subject: [PATCH 2/9] modified enable option only active contact --- .../Directory/CardViewDirectory.jsx | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/components/Directory/CardViewDirectory.jsx b/src/components/Directory/CardViewDirectory.jsx index a18f0f18..657f7353 100644 --- a/src/components/Directory/CardViewDirectory.jsx +++ b/src/components/Directory/CardViewDirectory.jsx @@ -3,11 +3,11 @@ import Avatar from "../common/Avatar"; import {getBucketNameById} from "./DirectoryUtils"; import {useBuckets} from "../../hooks/useDirectory"; import { getPhoneIcon } from "./DirectoryUtils"; -const CardViewDirectory = ( {contact, setSelectedContact, setIsOpenModal, setOpen_contact, setIsOpenModalNote, IsDeleted} ) => +const CardViewDirectory = ( {IsActive,contact, setSelectedContact, setIsOpenModal, setOpen_contact, setIsOpenModalNote, IsDeleted} ) => { const {buckets} = useBuckets() return ( -
+
@@ -23,7 +23,7 @@ const CardViewDirectory = ( {contact, setSelectedContact, setIsOpenModal, setOpe

{contact.name}

-
+
{ + if ( IsActive ) + { + setIsOpenModalNote(true) setOpen_contact(contact) + } }}>
{contact.contactEmails[0] && ( @@ -108,19 +118,19 @@ const CardViewDirectory = ( {contact, setSelectedContact, setIsOpenModal, setOpe -
    - {contact.bucketIds.map( ( bucketId ) => ( - <> - -
  • - -
  • -
  • - {getBucketNameById(buckets,bucketId)} -
  • - ))} - -
+
    + {contact.bucketIds.map((bucketId) => ( + +
  • + +
  • +
  • + {getBucketNameById(buckets, bucketId)} +
  • +
    + ))} +
+
); -- 2.43.0 From 7e4f4c897352a56af7d6ee4a4f50cdbcad403a85 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Fri, 23 May 2025 16:58:03 +0530 Subject: [PATCH 3/9] modified GetContact method of taking parma active or inactive --- src/repositories/DirectoryRepository.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repositories/DirectoryRepository.jsx b/src/repositories/DirectoryRepository.jsx index 5de1691b..aba2fd4a 100644 --- a/src/repositories/DirectoryRepository.jsx +++ b/src/repositories/DirectoryRepository.jsx @@ -1,7 +1,7 @@ import {api} from "../utils/axiosClient"; export const DirectoryRepository = { - GetContacts: () => api.get( '/api/directory' ), + 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}`), -- 2.43.0 From 64973029ccd80b5dd78ec785cea5e919af368745 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Fri, 23 May 2025 16:59:14 +0530 Subject: [PATCH 4/9] modified display active as well as inactives contact --- src/pages/Directory/Directory.jsx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx index dfbcbb81..c3e3830f 100644 --- a/src/pages/Directory/Directory.jsx +++ b/src/pages/Directory/Directory.jsx @@ -16,7 +16,9 @@ import { ITEMS_PER_PAGE } from "../../utils/constants"; import ProfileContactDirectory from "../../components/Directory/ProfileContactDirectory"; import ConfirmModal from "../../components/common/ConfirmModal"; -const Directory = () => { +const Directory = () => +{ + const[IsActivite,setIsActive] = useState(true) const [isOpenModal, setIsOpenModal] = useState(false); const [isOpenModalNote, setIsOpenModalNote] = useState(false); const [selectedContact, setSelectedContact] = useState(null); @@ -32,7 +34,7 @@ const Directory = () => { const [tempSelectedBucketIds, setTempSelectedBucketIds] = useState([]); const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]); - const { contacts, loading } = useDirectory(); + const { contacts, loading } = useDirectory(IsActivite); const { contactCategory, loading: contactCategoryLoading } = useContactCategory(); const { buckets } = useBuckets(); @@ -247,7 +249,7 @@ const Directory = () => {
)} -
+
{