added new modal for bucket management and splited code
This commit is contained in:
parent
199cf4867f
commit
8f94cf6e2d
@ -15,6 +15,9 @@ import usePagination from "../../hooks/usePagination";
|
|||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
import ProfileContactDirectory from "../../components/Directory/ProfileContactDirectory";
|
import ProfileContactDirectory from "../../components/Directory/ProfileContactDirectory";
|
||||||
import ConfirmModal from "../../components/common/ConfirmModal";
|
import ConfirmModal from "../../components/common/ConfirmModal";
|
||||||
|
import DirectoryListTableHeader from "./DirectoryListTableHeader";
|
||||||
|
import DirectoryPageHeader from "./DirectoryPageHeader";
|
||||||
|
import ManageBucket from "../../components/Directory/ManageBucket";
|
||||||
|
|
||||||
const Directory = () =>
|
const Directory = () =>
|
||||||
{
|
{
|
||||||
@ -29,7 +32,8 @@ const Directory = () =>
|
|||||||
const [listView, setListView] = useState(false);
|
const [listView, setListView] = useState(false);
|
||||||
const [selectedBucketIds, setSelectedBucketIds] = useState([]);
|
const [selectedBucketIds, setSelectedBucketIds] = useState([]);
|
||||||
const [deleteContact, setDeleteContact] = useState(null);
|
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 [tempSelectedBucketIds, setTempSelectedBucketIds] = useState([]);
|
||||||
const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]);
|
const [tempSelectedCategoryIds, setTempSelectedCategoryIds] = useState([]);
|
||||||
@ -37,7 +41,8 @@ const Directory = () =>
|
|||||||
const { contacts, loading } = useDirectory(IsActive);
|
const { contacts, loading } = useDirectory(IsActive);
|
||||||
const { contactCategory, loading: contactCategoryLoading } =
|
const { contactCategory, loading: contactCategoryLoading } =
|
||||||
useContactCategory();
|
useContactCategory();
|
||||||
const { buckets } = useBuckets();
|
const {buckets} = useBuckets();
|
||||||
|
|
||||||
const submitContact = async (data) => {
|
const submitContact = async (data) => {
|
||||||
try {
|
try {
|
||||||
let response;
|
let response;
|
||||||
@ -248,216 +253,43 @@ const Directory = () =>
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="card p-2" >
|
{openBucketModal && (
|
||||||
<div className="row mx-0 px-0 align-items-center">
|
<GlobalModel
|
||||||
<div className="col-12 col-md-4 mb-2 px-1 d-flex align-items-center ">
|
isOpen={openBucketModal}
|
||||||
<input
|
closeModal={() =>setOpenBucketModal(false)}
|
||||||
type="search"
|
size="md"
|
||||||
className="form-control form-control-sm me-2"
|
>
|
||||||
placeholder="Search Contact..."
|
<ManageBucket buckets={buckets} />
|
||||||
value={searchText}
|
</GlobalModel>
|
||||||
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>
|
|
||||||
|
|
||||||
<ul className="dropdown-menu p-3" style={{ width: "320px" }}>
|
<div className="card p-2">
|
||||||
<div>
|
<DirectoryPageHeader
|
||||||
<p className="small-text fw-semibold text-muted m-0">Filter by</p>
|
searchText={searchText}
|
||||||
|
setSearchText={setSearchText}
|
||||||
{/* Bucket Filter */}
|
setIsActive={setIsActive}
|
||||||
<div className="mt-1">
|
listView={listView}
|
||||||
<p className="small-text mb-1 fw-semibold">Buckets</p>
|
setListView={setListView}
|
||||||
<div className="d-flex flex-wrap">
|
filteredBuckets={filteredBuckets}
|
||||||
{filteredBuckets.map(({ id, name }) => (
|
tempSelectedBucketIds={tempSelectedBucketIds}
|
||||||
<div
|
handleTempBucketChange={handleTempBucketChange}
|
||||||
className="form-check me-1 mb-1"
|
filteredCategories={filteredCategories}
|
||||||
style={{ width: "33.33%" }}
|
tempSelectedCategoryIds={tempSelectedCategoryIds}
|
||||||
key={id}
|
handleTempCategoryChange={handleTempCategoryChange}
|
||||||
>
|
clearFilter={clearFilter}
|
||||||
<input
|
applyFilter={applyFilter}
|
||||||
className="form-check-input"
|
loading={loading}
|
||||||
type="checkbox"
|
IsActive={IsActive}
|
||||||
id={`bucket-${id}`}
|
setIsOpenModal={setIsOpenModal}
|
||||||
checked={tempSelectedBucketIds.includes(id)}
|
setOpenBucketModal={setOpenBucketModal}
|
||||||
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>
|
|
||||||
{!listView && loading && <p>Loading...</p>}
|
{!listView && loading && <p>Loading...</p>}
|
||||||
{!listView && !loading && currentItems.length == 0 && (
|
{!listView && !loading && currentItems.length == 0 && (
|
||||||
<p>No Matching Contact Found</p>
|
<p>No Matching Contact Found</p>
|
||||||
)}
|
)}
|
||||||
{listView ? (
|
{listView ? (
|
||||||
<div className="table-responsive text-nowrap py-2 ">
|
<DirectoryListTableHeader IsActive={IsActive}>
|
||||||
<table className="table px-2">
|
{loading && (
|
||||||
<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 && (
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={10}>Loading...</td>
|
<td colSpan={10}>Loading...</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -467,8 +299,7 @@ const Directory = () =>
|
|||||||
<td colSpan={10}>No Matching Contact Found</td>
|
<td colSpan={10}>No Matching Contact Found</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
|
{!loading &&
|
||||||
{!loading &&
|
|
||||||
currentItems.map((contact) => (
|
currentItems.map((contact) => (
|
||||||
<ListViewDirectory
|
<ListViewDirectory
|
||||||
key={contact.id}
|
key={contact.id}
|
||||||
@ -481,9 +312,7 @@ const Directory = () =>
|
|||||||
IsDeleted={setDeleteContact}
|
IsDeleted={setDeleteContact}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</DirectoryListTableHeader>
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
{!loading && currentItems.map((contact, index) => (
|
{!loading && currentItems.map((contact, index) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user