From c3a52c46ebfee49799f8909c36153039d9c467de Mon Sep 17 00:00:00 2001 From: Vikas Nale Date: Tue, 10 Jun 2025 12:46:53 +0530 Subject: [PATCH] Add cosmatic changes --- .../Directory/CardViewDirectory.jsx | 43 +- src/pages/Directory/Directory.jsx | 468 +++++++++--------- src/pages/Directory/DirectoryPageHeader.jsx | 56 ++- 3 files changed, 295 insertions(+), 272 deletions(-) diff --git a/src/components/Directory/CardViewDirectory.jsx b/src/components/Directory/CardViewDirectory.jsx index 32317d71..5cfe3af8 100644 --- a/src/components/Directory/CardViewDirectory.jsx +++ b/src/components/Directory/CardViewDirectory.jsx @@ -23,12 +23,17 @@ const CardViewDirectory = ({ >
-
{ - if (IsActive) { - setIsOpenModalNote(true); - setOpen_contact(contact); - } - }}> +
{ + if (IsActive) { + setIsOpenModalNote(true); + setOpen_contact(contact); + } + }} + >
{ if (IsActive) { setIsOpenModalNote(true); @@ -119,7 +126,7 @@ const CardViewDirectory = ({ >
{contact.contactEmails[0] && ( -
    +
    • @@ -130,7 +137,7 @@ const CardViewDirectory = ({ )} {contact.contactPhones[0] && ( -
        +
        • +
          • - +
          • {contact?.contactCategory?.name}
          ) : ( -
            +
            • - +
            • Other
            )} -
              +
                {contact?.bucketIds?.map((bucketId) => (
              • -{ - const [ projectPrefernce, setPerfence ] = useState( null ) - const[IsActive,setIsActive] = useState(true) +const Directory = ({ IsPage = true, prefernceContacts }) => { + const [projectPrefernce, setPerfence] = useState(null); + const [IsActive, setIsActive] = useState(true); const [isOpenModal, setIsOpenModal] = useState(false); const [isOpenModalNote, setIsOpenModalNote] = useState(false); const [selectedContact, setSelectedContact] = useState(null); @@ -35,21 +34,22 @@ const Directory = ({IsPage=true,prefernceContacts}) => const [listView, setListView] = useState(false); const [selectedBucketIds, setSelectedBucketIds] = useState([]); const [deleteContact, setDeleteContact] = useState(null); - const [ IsDeleting, setDeleting ] = 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 { dirActions, setDirActions } = useDir(); + const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]); + const { setActions } = useFab(); + const { dirActions, setDirActions } = useDir(); - - const { contacts, loading , refetch} = useDirectory(IsActive,projectPrefernce); + const { contacts, loading, refetch } = useDirectory( + IsActive, + projectPrefernce + ); const { contactCategory, loading: contactCategoryLoading } = - useContactCategory(); - const {buckets,refetch:refetchBucket} = useBuckets(); - + useContactCategory(); + const { buckets, refetch: refetchBucket } = useBuckets(); + const submitContact = async (data) => { try { let response; @@ -63,18 +63,18 @@ const Directory = ({IsPage=true,prefernceContacts}) => ); showToast("Contact updated successfully", "success"); setIsOpenModal(false); - setSelectedContact( null ); + setSelectedContact(null); } else { response = await DirectoryRepository.CreateContact(data); updatedContacts = [...contacts_cache, response.data]; showToast("Contact created successfully", "success"); setIsOpenModal(false); } - + // cacheData("Contacts", {data:updatedContacts,isActive:IsActive}); // setContactList(updatedContacts); - refetch( IsActive, prefernceContacts ) - refetchBucket() + refetch(IsActive, prefernceContacts); + refetchBucket(); } catch (error) { const msg = error.response?.data?.message || @@ -84,44 +84,45 @@ const Directory = ({IsPage=true,prefernceContacts}) => } }; -const handleDeleteContact = async (overrideId = null) => { - try - { - if (!IsActive) { - setDirActions((prev) => ({ ...prev, action: true })); - } else { - setDeleting(true); - } + 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; + 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); + refetchBucket(); + 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 }); } - - 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 ); - refetchBucket() - 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); @@ -181,7 +182,13 @@ const handleDeleteContact = async (overrideId = null) => { return matchesSearch && matchesCategory && matchesBucket; }).sort((a, b) => a.name.localeCompare(b.name)); - }, [ContactList, searchText, selectedCategoryIds, selectedBucketIds,selectedContact]); + }, [ + ContactList, + searchText, + selectedCategoryIds, + selectedBucketIds, + selectedContact, + ]); const applyFilter = () => { setSelectedBucketIds(tempSelectedBucketIds); @@ -218,46 +225,44 @@ const handleDeleteContact = async (overrideId = null) => { } }; + useEffect(() => { + const actions = []; - useEffect(() => { - const actions = []; + if (IsPage) { + actions.push({ + label: "Manage Bucket", + icon: "fa-solid fa-bucket fs-5", + color: "primary", + onClick: () => setOpenBucketModal(true), + }); + } + if (buckets?.length > 0) { + actions.push({ + label: "New Contact", + icon: "bx bx-plus-circle", + color: "warning", + onClick: () => setIsOpenModal(true), + }); + } - if (IsPage) { - actions.push({ - label: "Manage Bucket", - icon: "fa-solid fa-bucket fs-5", - color:"primary", - onClick: () => setOpenBucketModal(true), - }); - } - if ( buckets?.length > 0 ) - { - actions.push( { - label: "New Contact", - icon: "bx bx-plus-circle", - color: "warning", - onClick: () => setIsOpenModal( true ), - } ); - } + setActions(actions); - setActions(actions); - - return () => setActions([]); -}, [IsPage,buckets]); - useEffect( () => - { - setPerfence(prefernceContacts) -},[prefernceContacts]) + return () => setActions([]); + }, [IsPage, buckets]); + useEffect(() => { + setPerfence(prefernceContacts); + }, [prefernceContacts]); return (
                - - {IsPage && ( )} + {IsPage && ( + + )} {isOpenModal && ( { setSelectedContact(null); setIsOpenModal(false); }} - size="lg" + size="xl" > {renderModalContent()} @@ -312,155 +317,164 @@ const handleDeleteContact = async (overrideId = null) => { )} {openBucketModal && ( - setOpenBucketModal(false)} + closeModal={() => setOpenBucketModal(false)} size="lg" > )} -
                - +
                + - {/* Messages when listView is false */} - {!listView && ( -
                - {loading &&

                Loading...

                } - {!loading && contacts?.length === 0 &&

                No contact found

                } - {!loading && contacts?.length > 0 && currentItems.length === 0 && ( -

                No matching contact found

                - )} -
                - )} - - {/* Table view (listView === true) */} - {listView ? ( - - {loading && ( - - Loading... - - )} - - {!loading && contacts?.length === 0 && ( - - No contact found - - )} - - {!loading && currentItems.length === 0 && contacts?.length > 0 && ( - - No matching contact found - - )} - - {!loading && - currentItems.map((contact) => ( - - ))} - - ) : ( -
                - {!loading && - currentItems.map((contact) => ( -
                - + {/* Messages when listView is false */} + {!listView && ( +
                + {loading &&

                Loading...

                } + {!loading && contacts?.length === 0 && ( +

                No contact found

                + )} + {!loading && contacts?.length > 0 && currentItems.length === 0 && ( +

                No matching contact found

                + )}
                - ))} -
                - )} + )} - {/* Pagination */} - {!loading && - contacts?.length > 0 && - currentItems.length < ITEMS_PER_PAGE && ( - - )} -
                + {!loading && currentItems.length === 0 && contacts?.length > 0 && ( + + +

                No matching contact found

                + + + )} + {!loading && + currentItems.map((contact) => ( + + ))} + + ) : ( +
                + {!loading && + currentItems.map((contact) => ( +
                + +
                + ))} +
                + )} + {/* Pagination */} + {!loading && + contacts?.length > 0 && + currentItems.length > ITEMS_PER_PAGE && ( + + )}
                +
                ); }; diff --git a/src/pages/Directory/DirectoryPageHeader.jsx b/src/pages/Directory/DirectoryPageHeader.jsx index efb5e0cc..c4a1e77a 100644 --- a/src/pages/Directory/DirectoryPageHeader.jsx +++ b/src/pages/Directory/DirectoryPageHeader.jsx @@ -27,15 +27,16 @@ const DirectoryPageHeader = ({ }, [tempSelectedBucketIds, tempSelectedCategoryIds]); return ( <> -
                -
                + {/*
                vikas
                */} +
                setSearchText(e.target.value)} + style={{ width: "200px" }} />
                @@ -74,12 +75,16 @@ const DirectoryPageHeader = ({ data-bs-toggle="dropdown" aria-expanded="false" > - 0 ? 'text-primary' : 'text-muted'}`}> + 0 ? "text-primary" : "text-muted" + }`} + > {filtered > 0 && ( {filtered} @@ -88,9 +93,7 @@ const DirectoryPageHeader = ({
                  -

                  - Filter by -

                  +

                  Filter by

                  {/* Bucket Filter */}
                  @@ -168,22 +171,22 @@ const DirectoryPageHeader = ({
                  - +
                @@ -191,4 +194,3 @@ const DirectoryPageHeader = ({ }; export default DirectoryPageHeader; -