diff --git a/src/pages/Directory/Directory.jsx b/src/pages/Directory/Directory.jsx index d1736a6c..7de59ce5 100644 --- a/src/pages/Directory/Directory.jsx +++ b/src/pages/Directory/Directory.jsx @@ -1,18 +1,45 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import Breadcrumb from "../../components/common/Breadcrumb"; import IconButton from "../../components/common/IconButton"; import GlobalModel from "../../components/common/GlobalModel"; import ManageDirectory from "../../components/Directory/ManageDirectory"; import ListViewDirectory from "../../components/Directory/ListViewDirectory"; -import {useDirectory} from "../../hooks/useDirectory"; - +import { useDirectory } from "../../hooks/useDirectory"; +import { DirectoryRepository } from "../../repositories/DirectoryRepository"; +import { getCachedData } from "../../slices/apiDataManager"; +import showToast from "../../services/toastService"; const Directory = () => { const [isOpenModal, setIsOpenModal] = useState(false); - const closedModel = () => setIsOpenModal( false ); - - const {contacts} = useDirectory(); - console.log(contacts) + const closedModel = () => setIsOpenModal(false); + const [ContatList, setContactList] = useState([]); + + const { contacts, loading } = useDirectory(); + const submitContact = async (data, setLoading, reset) => { + try + { + debugger + const resp = await DirectoryRepository.CreateContact(data) + const contacts_cache = getCachedData("contacts") || []; + const updated_contacts = [...contacts_cache, resp.data]; + + setContactList(updated_contacts); + showToast(resp.message || "Contact created successfully", "success"); + setLoading(false); + reset(); + setIsOpenModal(false); + } catch (error) { + const msg = + error.response.data.message || + error.message || + "Error Occured during api calling !"; + showToast(msg, "error"); + } + }; + + useEffect(() => { + setContactList(contacts); + }, [contacts]); return (
{ ]} > - - - + {isOpenModal && ( + setIsOpenModal(false)} size="lg"> + + + )}
@@ -48,9 +80,9 @@ const Directory = () => {
- - - + + - - {contacts.map((contact) => ( - - ))} + {(loading && ContatList.length === 0) && ( + + + + )} + {(!loading && contacts.length == 0 && ContatList.length === 0) && ( + + + + )} + {!loading && + ContatList.map((contact) => ( + + ))}
+
{ Name
-
+
+
{
Loading...
No Contact Found