added new modal for bucket management and splited code

This commit is contained in:
Pramod Mahajan 2025-05-25 00:23:10 +05:30
parent 98c6e9edbe
commit 89eaca4189

View File

@ -15,6 +15,9 @@ import usePagination from "../../hooks/usePagination";
import { ITEMS_PER_PAGE } from "../../utils/constants";
import ProfileContactDirectory from "../../components/Directory/ProfileContactDirectory";
import ConfirmModal from "../../components/common/ConfirmModal";
import DirectoryListTableHeader from "./DirectoryListTableHeader";
import DirectoryPageHeader from "./DirectoryPageHeader";
import ManageBucket from "../../components/Directory/ManageBucket";
const Directory = () =>
{
@ -29,7 +32,8 @@ const Directory = () =>
const [listView, setListView] = useState(false);
const [selectedBucketIds, setSelectedBucketIds] = useState([]);
const [deleteContact, setDeleteContact] = useState(null);
const [IsDeleting, setIsDeletng] = useState(false);
const [ IsDeleting, setIsDeletng ] = useState( false );
const [openBucketModal,setOpenBucketModal] = useState(false)
const [tempSelectedBucketIds, setTempSelectedBucketIds] = useState([]);
const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]);
@ -37,7 +41,8 @@ const Directory = () =>
const { contacts, loading } = useDirectory(IsActive);
const { contactCategory, loading: contactCategoryLoading } =
useContactCategory();
const { buckets } = useBuckets();
const {buckets} = useBuckets();
const submitContact = async (data) => {
try {
let response;
@ -248,216 +253,43 @@ const Directory = () =>
</div>
)}
<div className="card p-2" >
<div className="row mx-0 px-0 align-items-center">
<div className="col-12 col-md-4 mb-2 px-1 d-flex align-items-center ">
<input
type="search"
className="form-control form-control-sm me-2"
placeholder="Search Contact..."
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
/>
<div className="d-flex gap-2 ">
<button
type="button"
className={`btn btn-xs ${
!listView ? "btn-primary" : "btn-outline-primary"
}`}
onClick={() => setListView(false)}
data-bs-toggle="tooltip"
data-bs-offset="0,8"
data-bs-placement="top"
data-bs-custom-class="tooltip"
title="Card View"
>
<i className="bx bx-grid-alt bx-sm"></i>
</button>
<button
type="button"
className={`btn btn-xs ${
listView ? "btn-primary" : "btn-outline-primary"
}`}
onClick={() => setListView(true)}
data-bs-toggle="tooltip"
data-bs-offset="0,8"
data-bs-placement="top"
data-bs-custom-class="tooltip"
title="List View"
>
<i className="bx bx-list-ul bx-sm"></i>
</button>
</div>
<div className="dropdown" style={{ width: "fit-content" }}>
<div className="dropdown" style={{ width: "fit-content" }}>
<a
className="dropdown-toggle hide-arrow cursor-pointer d-flex align-items-center"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i className="fa-solid fa-filter ms-1 fs-5"></i>
</a>
{openBucketModal && (
<GlobalModel
isOpen={openBucketModal}
closeModal={() =>setOpenBucketModal(false)}
size="md"
>
<ManageBucket buckets={buckets} />
</GlobalModel>
)}
<ul className="dropdown-menu p-3" style={{ width: "320px" }}>
<div>
<p className="small-text fw-semibold text-muted m-0">Filter by</p>
{/* Bucket Filter */}
<div className="mt-1">
<p className="small-text mb-1 fw-semibold">Buckets</p>
<div className="d-flex flex-wrap">
{filteredBuckets.map(({ id, name }) => (
<div
className="form-check me-1 mb-1"
style={{ width: "33.33%" }}
key={id}
>
<input
className="form-check-input"
type="checkbox"
id={`bucket-${id}`}
checked={tempSelectedBucketIds.includes(id)}
onChange={() => handleTempBucketChange(id)}
/>
<label
className="form-check-label text-nowrap small-text"
htmlFor={`bucket-${id}`}
>
{name}
</label>
</div>
))}
</div>
</div>
<hr className="m-0" />
{/* Category Filter */}
<div className="mt-1">
<p className="small-text mb-1 fw-semibold">Categories</p>
<div className="d-flex flex-wrap">
{filteredCategories.map(({ id, name }) => (
<div
className="form-check me-1 mb-1"
style={{ width: "33.33%" }}
key={id}
>
<input
className="form-check-input"
type="checkbox"
id={`cat-${id}`}
checked={tempSelectedCategoryIds.includes(id)}
onChange={() => handleTempCategoryChange(id)}
/>
<label
className="form-check-label text-nowrap small-text"
htmlFor={`cat-${id}`}
>
{name}
</label>
</div>
))}
</div>
</div>
<div className="d-flex justify-content-end gap-2 mt-1">
<button
className="btn btn-xs btn-secondary"
onClick={clearFilter}
>
Clear
</button>
<button
className="btn btn-xs btn-primary"
onClick={applyFilter}
>
Apply Filter
</button>
</div>
</div>
</ul>
</div>
</div>
</div>
<div className="col-12 col-md-8 mb-2 px-1 text-md-end text-end">
<label className="switch switch-primary">
<input type="checkbox" className="switch-input" onChange={() => setIsActive( !IsActive )} value={IsActive} disabled={ loading} />
<span className="switch-toggle-slider">
<span className="switch-on">
{/* <i class="icon-base bx bx-check"></i> */}
</span>
<span className="switch-off">
{/* <i class="icon-base bx bx-x"></i> */}
</span>
</span>
<span className="switch-label small-text">Show Inactive Contacts</span>
</label>
<button
type="button"
className="btn btn-xs btn-primary"
onClick={() => setIsOpenModal(true)}
>
<i className="bx bx-plus-circle me-2"></i>
New Contact
</button>
</div>
</div>
<div className="card p-2">
<DirectoryPageHeader
searchText={searchText}
setSearchText={setSearchText}
setIsActive={setIsActive}
listView={listView}
setListView={setListView}
filteredBuckets={filteredBuckets}
tempSelectedBucketIds={tempSelectedBucketIds}
handleTempBucketChange={handleTempBucketChange}
filteredCategories={filteredCategories}
tempSelectedCategoryIds={tempSelectedCategoryIds}
handleTempCategoryChange={handleTempCategoryChange}
clearFilter={clearFilter}
applyFilter={applyFilter}
loading={loading}
IsActive={IsActive}
setIsOpenModal={setIsOpenModal}
setOpenBucketModal={setOpenBucketModal}
/>
{!listView && loading && <p>Loading...</p>}
{!listView && !loading && currentItems.length == 0 && (
<p>No Matching Contact Found</p>
)}
{listView ? (
<div className="table-responsive text-nowrap py-2 ">
<table className="table px-2">
<thead>
<tr>
<th colSpan={2}>
<div className="d-flex align-items-center gap-1">
<IconButton
size={12}
iconClass="bx bx-user"
color="secondary"
onClick={() => alert("User icon clicked")}
/>
<span>Name</span>
</div>
</th>
<th className="px-2 text-start">
<div className="d-flex text-center align-items-center gap-1 justify-content-start">
<IconButton
size={12}
iconClass="bx bx-envelope"
color="primary"
/>
<span>Email</span>
</div>
</th>
<th className="mx-2">
<div className="d-flex align-items-center m-0 p-0 gap-1">
<IconButton
size={12}
iconClass="bx bx-phone"
color="warning"
onClick={() => alert("User icon clicked")}
/>
<span>Phone</span>
</div>
</th>
<th className="mx-2">
<div className="d-flex align-items-center gap-1">
<IconButton
size={12}
iconClass="bx bxs-grid-alt"
color="info"
/>
<span>Organization</span>
</div>
</th>
<th className="mx-2">Category</th>
{IsActive && <th>Action</th>}
</tr>
</thead>
<tbody className="table-border-bottom-0 overflow-auto ">
{loading && (
<DirectoryListTableHeader IsActive={IsActive}>
{loading && (
<tr>
<td colSpan={10}>Loading...</td>
</tr>
@ -467,8 +299,7 @@ const Directory = () =>
<td colSpan={10}>No Matching Contact Found</td>
</tr>
)}
{!loading &&
{!loading &&
currentItems.map((contact) => (
<ListViewDirectory
key={contact.id}
@ -481,9 +312,7 @@ const Directory = () =>
IsDeleted={setDeleteContact}
/>
))}
</tbody>
</table>
</div>
</DirectoryListTableHeader>
) : (
<div className="row">
{!loading && currentItems.map((contact, index) => (