Merge pull request 'pramod_Task-#355 : implemented Manage Buckets modal with bucket creation and listing' (#145) from pramod_Task-#355 into Feature_Directory
Reviewed-on: #145
This commit is contained in:
commit
2224b10842
@ -53,5 +53,13 @@ export const ContactSchema = z
|
|||||||
// return hasValidEmail || hasValidPhone;
|
// return hasValidEmail || hasValidPhone;
|
||||||
// }, {
|
// }, {
|
||||||
// message: "At least one contact (email or phone) is required",
|
// message: "At least one contact (email or phone) is required",
|
||||||
// path: ["contactPhone"],
|
// path: ["contactPhone"],
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// Buckets
|
||||||
|
|
||||||
|
export const bucketScheam = z.object( {
|
||||||
|
name: z.string().min( 1, {message: "Name is required"} ),
|
||||||
|
description:z.string().min(1,{message:"Description is required"})
|
||||||
|
})
|
||||||
226
src/components/Directory/ManageBucket.jsx
Normal file
226
src/components/Directory/ManageBucket.jsx
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import IconButton from "../common/IconButton";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { bucketScheam } from "./DirectorySchema";
|
||||||
|
import showToast from "../../services/toastService";
|
||||||
|
import Directory from "../../pages/Directory/Directory";
|
||||||
|
import { DirectoryRepository } from "../../repositories/DirectoryRepository";
|
||||||
|
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
||||||
|
import { useBuckets } from "../../hooks/useDirectory";
|
||||||
|
|
||||||
|
const ManageBucket = () =>
|
||||||
|
{
|
||||||
|
const [bucketList, setBucketList] = useState([]);
|
||||||
|
|
||||||
|
const { buckets } = useBuckets();
|
||||||
|
const [action_bucket, setAction_bucket] = useState(false);
|
||||||
|
const [isSubmitting, setSubmitting] = useState(false);
|
||||||
|
const [selected_bucket, select_bucket] = useState(null);
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(bucketScheam),
|
||||||
|
defaultValues: {
|
||||||
|
name: "",
|
||||||
|
description: "",
|
||||||
|
},
|
||||||
|
} );
|
||||||
|
|
||||||
|
const onSubmit = async (data) => {
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
let response;
|
||||||
|
|
||||||
|
if ( selected_bucket )
|
||||||
|
{
|
||||||
|
let payload ={...data, id:selected_bucket.id}
|
||||||
|
response = await DirectoryRepository.UpdateBuckets(selected_bucket.id, payload);
|
||||||
|
const cache_buckets = getCachedData("buckets") || [];
|
||||||
|
const updatedBuckets = cache_buckets.map((bucket) =>
|
||||||
|
bucket.id === selected_bucket.id ? response?.data : bucket
|
||||||
|
);
|
||||||
|
cacheData( "buckets", updatedBuckets );
|
||||||
|
setBucketList(updatedBuckets);
|
||||||
|
showToast("Bucket Updated Successfully", "success");
|
||||||
|
} else {
|
||||||
|
response = await DirectoryRepository.CreateBuckets(data);
|
||||||
|
const cache_buckets = getCachedData("buckets") || [];
|
||||||
|
const updatedBuckets = [...cache_buckets, response?.data];
|
||||||
|
cacheData( "buckets", updatedBuckets );
|
||||||
|
setBucketList(updatedBuckets);
|
||||||
|
showToast("Bucket Created Successfully", "success");
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBack();
|
||||||
|
} catch (error) {
|
||||||
|
const message =
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error?.message ||
|
||||||
|
"Error occurred during API call";
|
||||||
|
showToast(message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset({
|
||||||
|
name: selected_bucket?.name || "",
|
||||||
|
description: selected_bucket?.description || "",
|
||||||
|
});
|
||||||
|
}, [ selected_bucket ] );
|
||||||
|
|
||||||
|
useEffect( () =>
|
||||||
|
{
|
||||||
|
setBucketList( buckets )
|
||||||
|
}, [ buckets ] )
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
select_bucket(null);
|
||||||
|
setAction_bucket(false);
|
||||||
|
setSubmitting(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="container m-0 p-0" style={{ minHeight: "200px" }}>
|
||||||
|
<div className="d-flex justify-content-center">
|
||||||
|
<p className="fs-h6 fw-semibold m-0">Manage Buckets</p>
|
||||||
|
</div>
|
||||||
|
<div className="d-flex justify-content-between px-2 px-sm-0 mt-5 mt-sm-1 align-items-center">
|
||||||
|
<i
|
||||||
|
className={`fa-solid fa-arrow-left fs-5 cursor-pointer ${
|
||||||
|
action_bucket ? "" : "d-none"
|
||||||
|
}`}
|
||||||
|
onClick={handleBack}
|
||||||
|
></i>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`btn btn-xs btn-primary ms-auto ${
|
||||||
|
action_bucket ? "d-none" : ""
|
||||||
|
}`}
|
||||||
|
onClick={() => setAction_bucket(true)}
|
||||||
|
>
|
||||||
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
|
Add Bucket
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{!action_bucket ? (
|
||||||
|
<div className="table-responsive text-nowrap pt-1 px-2 px-sm-0">
|
||||||
|
<table className="table px-2">
|
||||||
|
<thead className="p-0">
|
||||||
|
<tr className="p-0">
|
||||||
|
<th colSpan={2}>
|
||||||
|
<div className="d-flex justify-content-start align-items-center gap-1">
|
||||||
|
<IconButton
|
||||||
|
size={12}
|
||||||
|
iconClass="fa-solid fa-bucket"
|
||||||
|
color="info"
|
||||||
|
/>
|
||||||
|
<span>Name</span>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
<th className="text-start d-none d-sm-table-cell">
|
||||||
|
<div className="d-flex align-items-center justify-content-start gap-1">
|
||||||
|
<IconButton
|
||||||
|
size={12}
|
||||||
|
iconClass="fa-solid fa-file-lines"
|
||||||
|
color="primary"
|
||||||
|
/>
|
||||||
|
<span>Description</span>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<div className="d-flex align-items-center justify-content-center gap-1">
|
||||||
|
<IconButton
|
||||||
|
size={12}
|
||||||
|
iconClass="fa-solid fa-gear"
|
||||||
|
color="secondary"
|
||||||
|
/>
|
||||||
|
<span>Action</span>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody className="table-border-bottom-0 overflow-auto">
|
||||||
|
{bucketList.map((bucket) => (
|
||||||
|
<tr key={bucket.id}>
|
||||||
|
<td colSpan={2} className="text-start">
|
||||||
|
{bucket.name}
|
||||||
|
</td>
|
||||||
|
<td className="text-start d-none d-sm-table-cell">
|
||||||
|
{bucket.description}
|
||||||
|
</td>
|
||||||
|
<td className="justify-content-center">
|
||||||
|
<div className="d-flex justify-content-center align-items-center gap-2">
|
||||||
|
<i
|
||||||
|
className="bx bx-edit bx-sm text-primary cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
select_bucket(bucket);
|
||||||
|
setAction_bucket(true);
|
||||||
|
}}
|
||||||
|
></i>
|
||||||
|
<i className="bx bx-trash bx-sm text-danger cursor-pointer"></i>
|
||||||
|
<i className="bx bx-user-plus cursor-pointer"></i>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="px-2 px-sm-0">
|
||||||
|
<div className="">
|
||||||
|
<label className="form-label">Bucket Name</label>
|
||||||
|
<input
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("name")}
|
||||||
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<small className="danger-text">{errors.name.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="">
|
||||||
|
<label className="form-label">Bucket Discription</label>
|
||||||
|
<textarea
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("description")}
|
||||||
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.description.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 d-flex justify-content-center gap-3">
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-secondary"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
{isSubmitting ? "Please wait..." : "Submit"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManageBucket;
|
||||||
@ -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) => (
|
||||||
|
|||||||
65
src/pages/Directory/DirectoryListTableHeader.jsx
Normal file
65
src/pages/Directory/DirectoryListTableHeader.jsx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import IconButton from '../../components/common/IconButton';
|
||||||
|
|
||||||
|
|
||||||
|
const DirectoryListTableHeader = ( {children, IsActive} ) =>
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
<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">
|
||||||
|
{children}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default DirectoryListTableHeader;
|
||||||
202
src/pages/Directory/DirectoryPageHeader.jsx
Normal file
202
src/pages/Directory/DirectoryPageHeader.jsx
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const DirectoryPageHeader = ({
|
||||||
|
searchText,
|
||||||
|
setSearchText,
|
||||||
|
setIsActive,
|
||||||
|
listView,
|
||||||
|
setListView,
|
||||||
|
filteredBuckets,
|
||||||
|
tempSelectedBucketIds,
|
||||||
|
handleTempBucketChange,
|
||||||
|
filteredCategories,
|
||||||
|
tempSelectedCategoryIds,
|
||||||
|
handleTempCategoryChange,
|
||||||
|
clearFilter,
|
||||||
|
applyFilter,
|
||||||
|
loading,
|
||||||
|
IsActive,
|
||||||
|
setIsOpenModal,
|
||||||
|
setOpenBucketModal
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="row">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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={{ minWidth: "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={{ minWidth: "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="col-12 d-flex justify-content-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-xs btn-primary"
|
||||||
|
onClick={()=>setOpenBucketModal(true)}
|
||||||
|
>
|
||||||
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
|
Manage Buckets
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DirectoryPageHeader;
|
||||||
@ -7,6 +7,8 @@ export const DirectoryRepository = {
|
|||||||
DeleteContact:(id)=>api.delete(`/api/directory/${id}`),
|
DeleteContact:(id)=>api.delete(`/api/directory/${id}`),
|
||||||
|
|
||||||
GetBucktes: () => api.get( `/api/directory/buckets` ),
|
GetBucktes: () => api.get( `/api/directory/buckets` ),
|
||||||
|
CreateBuckets: ( data ) => api.post( `/api/Directory/bucket`, data ),
|
||||||
|
UpdateBuckets: (id,data) => api.put( `/api/Directory/bucket/${id}`,data ),
|
||||||
|
|
||||||
GetContactProfile: ( id ) => api.get( `/api/directory/profile/${ id }` ),
|
GetContactProfile: ( id ) => api.get( `/api/directory/profile/${ id }` ),
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user