managebucket component is split
This commit is contained in:
parent
957f790fce
commit
1abed1de3a
@ -1,13 +1,67 @@
|
|||||||
import React from "react";
|
import { useState, useEffect } from "react";
|
||||||
import EmployeeList from "./EmployeeList";
|
import EmployeeList from "./EmployeeList";
|
||||||
|
import { useAllEmployees } from "../../hooks/useEmployees";
|
||||||
|
import showToast from "../../services/toastService";
|
||||||
|
import { DirectoryRepository } from "../../repositories/DirectoryRepository";
|
||||||
|
import { useAssignEmpToBucket } from "../../hooks/useDirectory";
|
||||||
|
|
||||||
const AssignedBucket = ({ employees, selectedBucket, onChange }) => {
|
const AssignedBucket = ({ selectedBucket, handleClose }) => {
|
||||||
if (!selectedBucket) return null;
|
const { employeesList } = useAllEmployees(false);
|
||||||
|
const [selectedEmployees, setSelectedEmployees] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedBucket) {
|
||||||
|
const preselected = employeesList
|
||||||
|
.filter((emp) => selectedBucket?.employeeIds?.includes(emp.employeeId))
|
||||||
|
.map((emp) => ({ ...emp, isActive: true }));
|
||||||
|
|
||||||
|
setSelectedEmployees(preselected);
|
||||||
|
}
|
||||||
|
}, [selectedBucket, employeesList]);
|
||||||
|
|
||||||
|
const { mutate: AssignEmployee, isPending } = useAssignEmpToBucket(() =>
|
||||||
|
handleClose()
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const existingEmployeeIds = selectedBucket?.employeeIds || [];
|
||||||
|
|
||||||
|
const employeesToUpdate = selectedEmployees.filter((emp) => {
|
||||||
|
const isExisting = existingEmployeeIds.includes(emp.employeeId);
|
||||||
|
return (!isExisting && emp.isActive) || (isExisting && !emp.isActive);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (employeesToUpdate.length === 0) {
|
||||||
|
showToast("No changes to update", "info");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignEmployee({
|
||||||
|
bucketId: selectedBucket.id,
|
||||||
|
EmployeePayload: employeesToUpdate.map((emp) => ({
|
||||||
|
employeeId: emp.employeeId,
|
||||||
|
isActive: emp.isActive,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-1">
|
<form onSubmit={handleSubmit}>
|
||||||
<EmployeeList employees={employees} onChange={onChange} bucket={selectedBucket} />
|
<EmployeeList
|
||||||
</div>
|
employees={employeesList}
|
||||||
|
bucket={selectedBucket}
|
||||||
|
selectedEmployees={selectedEmployees}
|
||||||
|
onChange={setSelectedEmployees}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="mt-3 d-flex justify-content-end gap-3">
|
||||||
|
<button type="submit" className="btn btn-sm btn-primary" disabled={isPending}>
|
||||||
|
{isPending ? "Please Wait...":"Assign"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import React from "react";
|
import { useEffect } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { bucketScheam } from "./DirectorySchema";
|
import { bucketScheam } from "./DirectorySchema";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import Label from "../common/Label";
|
||||||
|
|
||||||
const BucketForm = ({ onSubmit, selectedBucket, onCancel, isSubmitting }) => {
|
const BucketForm = ({ selectedBucket, mode, onSubmit, onCancel, isPending }) => {
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -11,33 +12,83 @@ const BucketForm = ({ onSubmit, selectedBucket, onCancel, isSubmitting }) => {
|
|||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(bucketScheam),
|
resolver: zodResolver(bucketScheam),
|
||||||
defaultValues: {
|
defaultValues: selectedBucket || { name: "", description: "" },
|
||||||
name: selectedBucket?.name || "",
|
|
||||||
description: selectedBucket?.description || "",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset(selectedBucket || { name: "", description: "" });
|
||||||
|
}, [selectedBucket, reset]);
|
||||||
|
|
||||||
|
const isEditMode = mode === "edit";
|
||||||
|
const isCreateMode = mode === "create";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="px-2 px-sm-0">
|
<div className="row">
|
||||||
<div className="mb-3">
|
<div className="d-flex justify-content-between align-items-center">
|
||||||
<label htmlFor="bucketName" className="form-label">Bucket Name</label>
|
<i
|
||||||
<input id="bucketName" className="form-control form-control-sm" {...register("name")} />
|
className="bx bx-left-arrow-alt bx-md cursor-pointer"
|
||||||
{errors.name && <small className="danger-text">{errors.name.message}</small>}
|
onClick={onCancel}
|
||||||
|
></i>
|
||||||
|
|
||||||
|
{/* Show edit toggle only for existing bucket in edit mode */}
|
||||||
|
{/* {isEditMode && (
|
||||||
|
<i className="bx bx-edit bx-sm text-primary cursor-pointer"></i>
|
||||||
|
)} */}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-3">
|
{(isCreateMode || isEditMode) ? (
|
||||||
<label htmlFor="bucketDescription" className="form-label">Bucket Description</label>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<textarea id="bucketDescription" className="form-control form-control-sm" rows="3" {...register("description")} />
|
<div className="mb-3">
|
||||||
{errors.description && <small className="danger-text">{errors.description.message}</small>}
|
<Label htmlFor="Name" className="text-start" required>
|
||||||
</div>
|
Name
|
||||||
|
</Label>
|
||||||
|
<input
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("name")}
|
||||||
|
/>
|
||||||
|
{errors.name && (
|
||||||
|
<small className="danger-text">{errors.name.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 d-flex justify-content-center gap-3">
|
<div className="mb-3">
|
||||||
<button type="button" onClick={onCancel} className="btn btn-sm btn-secondary" disabled={isSubmitting}>Cancel</button>
|
<Label htmlFor="description" className="text-start" required>
|
||||||
<button type="submit" className="btn btn-sm btn-primary" disabled={isSubmitting}>
|
Description
|
||||||
{isSubmitting ? "Please wait..." : "Submit"}
|
</Label>
|
||||||
</button>
|
<textarea
|
||||||
</div>
|
className="form-control form-control-sm"
|
||||||
</form>
|
{...register("description")}
|
||||||
|
rows="3"
|
||||||
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<small className="danger-text">{errors.description.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 d-flex gap-3 justify-content-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-sm btn-secondary"
|
||||||
|
onClick={onCancel}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button type="submit" className="btn btn-sm btn-primary" disabled={isPending}>
|
||||||
|
{isPending ? "Please Wait " : isEditMode ? "Update" : "Create"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<dl className="row text-start my-2">
|
||||||
|
<dt className="col-sm-2">Name</dt>
|
||||||
|
<dd className="col-sm-10">{selectedBucket?.name || "-"}</dd>
|
||||||
|
|
||||||
|
<dt className="col-sm-2">Description</dt>
|
||||||
|
<dd className="col-sm-10">{selectedBucket?.description || "-"}</dd>
|
||||||
|
</dl>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
import React from "react";
|
const BucketList = ({ buckets, loading, searchTerm, onEdit, onDelete }) => {
|
||||||
|
const sorted = buckets.filter((bucket) =>
|
||||||
const BucketList = ({ buckets, searchTerm, onEdit, onDelete, loading }) => {
|
|
||||||
const filteredBuckets = buckets.filter(bucket =>
|
|
||||||
bucket.name.toLowerCase().includes(searchTerm.toLowerCase())
|
bucket.name.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loading) return <p className="text-center">Loading...</p>;
|
if (loading) return <div>Loading...</div>;
|
||||||
if (filteredBuckets.length === 0) return <p className="text-center">No buckets found.</p>;
|
if (!loading && sorted.length === 0) return <div>No buckets found</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3 pt-3 px-2 px-sm-0">
|
<div className="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-3 pt-3 px-2 px-sm-0">
|
||||||
{filteredBuckets.map(bucket => (
|
{sorted.map((bucket) => (
|
||||||
<div className="col" key={bucket.id}>
|
<div className="col" key={bucket.id}>
|
||||||
<div className="card h-100">
|
<div className="card h-100">
|
||||||
<div className="card-body p-4">
|
<div className="card-body p-4">
|
||||||
<h6 className="card-title d-flex justify-content-between">
|
<h6 className="card-title d-flex justify-content-between">
|
||||||
<span>{bucket.name}</span>
|
<span>{bucket.name}</span>
|
||||||
<div className="d-flex gap-2">
|
<div className="d-flex gap-2">
|
||||||
<i className="bx bx-edit bx-sm text-primary cursor-pointer" onClick={() => onEdit(bucket)}></i>
|
<i
|
||||||
<i className="bx bx-trash bx-sm text-danger cursor-pointer" onClick={() => onDelete(bucket.id)}></i>
|
className="bx bx-edit bx-sm text-primary cursor-pointer"
|
||||||
|
onClick={() => onEdit(bucket)}
|
||||||
|
/>
|
||||||
|
<i
|
||||||
|
className="bx bx-trash bx-sm text-danger cursor-pointer"
|
||||||
|
onClick={() => onDelete(bucket.id)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</h6>
|
</h6>
|
||||||
<h6 className="card-subtitle mb-2 text-muted">Contacts: {bucket.numberOfContacts || 0}</h6>
|
<h6 className="card-subtitle mb-2 text-muted">
|
||||||
<p className="card-text" title={bucket.description}>
|
Contacts: {bucket.numberOfContacts || 0}
|
||||||
{bucket.description || "No description available."}
|
</h6>
|
||||||
</p>
|
<p className="card-text">{bucket.description || "No description"}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -33,4 +37,4 @@ const BucketList = ({ buckets, searchTerm, onEdit, onDelete, loading }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BucketList;
|
export default BucketList;
|
@ -1,14 +1,98 @@
|
|||||||
import React from "react";
|
import { useState } from "react";
|
||||||
|
import {
|
||||||
|
useBucketList,
|
||||||
|
useBuckets,
|
||||||
|
useCreateBucket,
|
||||||
|
useUpdateBucket,
|
||||||
|
} from "../../hooks/useDirectory";
|
||||||
|
import { useAllEmployees } from "../../hooks/useEmployees";
|
||||||
|
import BucketList from "./BucketList";
|
||||||
|
import BucketForm from "./BucketForm";
|
||||||
|
import AssignEmployees from "./AssignedBucket";
|
||||||
|
import AssignedBucket from "./AssignedBucket";
|
||||||
|
|
||||||
|
const ManageBucket1 = () => {
|
||||||
|
const { data, isError, isLoading, error } = useBucketList();
|
||||||
|
const { employeesList } = useAllEmployees(false);
|
||||||
|
const [action, setAction] = useState(null); // "create" | "edit" | null
|
||||||
|
const [selectedBucket, setSelectedBucket] = useState(null);
|
||||||
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
|
|
||||||
|
const handleClose = ()=>{
|
||||||
|
setAction(null);
|
||||||
|
setSelectedBucket(null);
|
||||||
|
}
|
||||||
|
const { mutate: createBucket, isPending: creating } = useCreateBucket(() => {
|
||||||
|
handleClose()
|
||||||
|
});
|
||||||
|
const { mutate: updateBucket, isPending: updating } = useUpdateBucket(() => {
|
||||||
|
handleClose()
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (BucketPayload) => {
|
||||||
|
if (selectedBucket) {
|
||||||
|
updateBucket({
|
||||||
|
bucketId: selectedBucket.id,
|
||||||
|
BucketPayload: { ...BucketPayload, id: selectedBucket.id },
|
||||||
|
});
|
||||||
|
} else createBucket(BucketPayload);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const ManageBucket1 = ({ closeModal }) => {
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container m-0 p-0" style={{ minHeight: "00px" }}>
|
||||||
<div className="text-center">
|
<div className="d-flex justify-content-center">
|
||||||
<h5 className="fw-semibold">Manage Bucket</h5>
|
<p className="fs-6 fw-semibold m-0">Manage Buckets</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-start p-0"></div>
|
{action ? (
|
||||||
|
<>
|
||||||
|
<BucketForm
|
||||||
|
selectedBucket={selectedBucket}
|
||||||
|
mode={action} // pass create | edit
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
onCancel={() => {
|
||||||
|
setAction(null);
|
||||||
|
setSelectedBucket(null);
|
||||||
|
}}
|
||||||
|
isPending={creating || updating}
|
||||||
|
/>
|
||||||
|
{action === "edit" && selectedBucket && (
|
||||||
|
<AssignedBucket selectedBucket={selectedBucket} handleClose={handleClose} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="d-flex justify-content-between align-items-center gap-2 my-2">
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
className="form-control form-control-sm w-25"
|
||||||
|
placeholder="Search..."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
onClick={() => setAction("create")}
|
||||||
|
>
|
||||||
|
<i className="bx bx-plus-circle me-2"></i>
|
||||||
|
Add Bucket
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<BucketList
|
||||||
|
buckets={data}
|
||||||
|
loading={isLoading}
|
||||||
|
searchTerm={searchTerm}
|
||||||
|
onEdit={(bucket) => {
|
||||||
|
setSelectedBucket(bucket);
|
||||||
|
setAction("edit");
|
||||||
|
}}
|
||||||
|
onDelete={(id) => console.log("delete", id)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ManageBucket1;
|
export default ManageBucket1;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { DirectoryRepository } from "../repositories/DirectoryRepository";
|
import { DirectoryRepository } from "../repositories/DirectoryRepository";
|
||||||
import { cacheData, getCachedData } from "../slices/apiDataManager";
|
import { cacheData, getCachedData } from "../slices/apiDataManager";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import showToast from "../services/toastService";
|
||||||
|
|
||||||
export const useDirectory = (isActive,prefernceContacts) => {
|
export const useDirectory = (isActive, prefernceContacts) => {
|
||||||
const [contacts, setContacts] = useState([]);
|
const [contacts, setContacts] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
@ -11,7 +12,10 @@ export const useDirectory = (isActive,prefernceContacts) => {
|
|||||||
const fetch = async (activeParam = isActive) => {
|
const fetch = async (activeParam = isActive) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await DirectoryRepository.GetContacts(activeParam,prefernceContacts);
|
const response = await DirectoryRepository.GetContacts(
|
||||||
|
activeParam,
|
||||||
|
prefernceContacts
|
||||||
|
);
|
||||||
setContacts(response.data);
|
setContacts(response.data);
|
||||||
cacheData("contacts", { data: response.data, isActive: activeParam });
|
cacheData("contacts", { data: response.data, isActive: activeParam });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -23,12 +27,16 @@ export const useDirectory = (isActive,prefernceContacts) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cachedContacts = getCachedData("contacts");
|
const cachedContacts = getCachedData("contacts");
|
||||||
if (!cachedContacts?.data || cachedContacts.isActive !== isActive || prefernceContacts) {
|
if (
|
||||||
fetch(isActive,prefernceContacts);
|
!cachedContacts?.data ||
|
||||||
|
cachedContacts.isActive !== isActive ||
|
||||||
|
prefernceContacts
|
||||||
|
) {
|
||||||
|
fetch(isActive, prefernceContacts);
|
||||||
} else {
|
} else {
|
||||||
setContacts(cachedContacts.data);
|
setContacts(cachedContacts.data);
|
||||||
}
|
}
|
||||||
}, [isActive,prefernceContacts]);
|
}, [isActive, prefernceContacts]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contacts,
|
contacts,
|
||||||
@ -55,7 +63,7 @@ export const useBuckets = () => {
|
|||||||
error?.response?.data?.message ||
|
error?.response?.data?.message ||
|
||||||
error?.message ||
|
error?.message ||
|
||||||
"Something went wrong";
|
"Something went wrong";
|
||||||
setError( msg );
|
setError(msg);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -78,35 +86,30 @@ export const useContactProfile = (id) => {
|
|||||||
const [Error, setError] = useState("");
|
const [Error, setError] = useState("");
|
||||||
|
|
||||||
const fetchContactProfile = async () => {
|
const fetchContactProfile = async () => {
|
||||||
|
setLoading(true);
|
||||||
setLoading(true);
|
try {
|
||||||
try {
|
const resp = await DirectoryRepository.GetContactProfile(id);
|
||||||
const resp = await DirectoryRepository.GetContactProfile(id);
|
setContactProfile(resp.data);
|
||||||
setContactProfile(resp.data);
|
cacheData("Contact Profile", { data: resp.data, contactId: id });
|
||||||
cacheData("Contact Profile", { data: resp.data, contactId: id });
|
} catch (err) {
|
||||||
} catch (err) {
|
const msg =
|
||||||
const msg =
|
err?.response?.data?.message || err?.message || "Something went wrong";
|
||||||
err?.response?.data?.message ||
|
setError(msg);
|
||||||
err?.message ||
|
} finally {
|
||||||
"Something went wrong";
|
setLoading(false);
|
||||||
setError(msg);
|
}
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect( () =>
|
useEffect(() => {
|
||||||
{
|
|
||||||
const cached = getCachedData("Contact Profile");
|
const cached = getCachedData("Contact Profile");
|
||||||
if (!cached || cached.contactId !== id) {
|
if (!cached || cached.contactId !== id) {
|
||||||
fetchContactProfile(id);
|
fetchContactProfile(id);
|
||||||
} else {
|
} else {
|
||||||
setContactProfile(cached.data);
|
setContactProfile(cached.data);
|
||||||
}
|
}
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
return { contactProfile, loading, Error ,refetch:fetchContactProfile};
|
return { contactProfile, loading, Error, refetch: fetchContactProfile };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useContactNotes = (id, IsActive) => {
|
export const useContactNotes = (id, IsActive) => {
|
||||||
@ -114,36 +117,31 @@ export const useContactNotes = (id, IsActive) => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [Error, setError] = useState("");
|
const [Error, setError] = useState("");
|
||||||
|
|
||||||
const fetchContactNotes = async (id,IsActive) => {
|
const fetchContactNotes = async (id, IsActive) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
setLoading(true);
|
const resp = await DirectoryRepository.GetNote(id, IsActive);
|
||||||
try {
|
setContactNotes(resp.data);
|
||||||
const resp = await DirectoryRepository.GetNote(id, IsActive);
|
cacheData("Contact Notes", { data: resp.data, contactId: id });
|
||||||
setContactNotes(resp.data);
|
} catch (err) {
|
||||||
cacheData("Contact Notes", { data: resp.data, contactId: id });
|
const msg =
|
||||||
} catch (err) {
|
err?.response?.data?.message || err?.message || "Something went wrong";
|
||||||
const msg =
|
setError(msg);
|
||||||
err?.response?.data?.message ||
|
} finally {
|
||||||
err?.message ||
|
setLoading(false);
|
||||||
"Something went wrong";
|
}
|
||||||
setError(msg);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cached = getCachedData("Contact Notes");
|
const cached = getCachedData("Contact Notes");
|
||||||
if (!cached || cached.contactId !== id) {
|
if (!cached || cached.contactId !== id) {
|
||||||
id && fetchContactNotes(id,IsActive);
|
id && fetchContactNotes(id, IsActive);
|
||||||
} else {
|
} else {
|
||||||
setContactNotes(cached.data);
|
setContactNotes(cached.data);
|
||||||
}
|
}
|
||||||
}, [id,IsActive]);
|
}, [id, IsActive]);
|
||||||
|
|
||||||
return { contactNotes, loading, Error,refetch:fetchContactNotes };
|
return { contactNotes, loading, Error, refetch: fetchContactNotes };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useOrganization = () => {
|
export const useOrganization = () => {
|
||||||
@ -212,21 +210,115 @@ export const useDesignation = () => {
|
|||||||
return { designationList, loading, error };
|
return { designationList, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------Query--------------------------------------------
|
// ------------------------------Query------------------------------------------------------------------
|
||||||
|
|
||||||
export const useBucketList =()=>{
|
export const useBucketList = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey:["bucketList"],
|
queryKey: ["bucketList"],
|
||||||
queryFn:async()=>{
|
queryFn: async () => {
|
||||||
const resp = await DirectoryRepository.GetBucktes();
|
const resp = await DirectoryRepository.GetBucktes();
|
||||||
return resp.data;
|
return resp.data;
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDirectoryNotes = (
|
||||||
|
pageSize,
|
||||||
|
pageNumber,
|
||||||
|
filter,
|
||||||
|
searchString
|
||||||
|
) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["directoryNotes", pageSize, pageNumber, filter, searchString],
|
||||||
|
queryFn: async () =>
|
||||||
|
await DirectoryRepository.GetBucktes(
|
||||||
|
pageSize,
|
||||||
|
pageNumber,
|
||||||
|
filter,
|
||||||
|
searchString
|
||||||
|
),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------Mutation------------------------------------------------------------------
|
||||||
|
|
||||||
|
export const useCreateBucket =(onSuccessCallBack)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn:async(BucketPayload)=> await DirectoryRepository.CreateBuckets(BucketPayload),
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({queryKey: ["bucketList"]})
|
||||||
|
showToast("Bucket created Successfully", "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.response.data.message ||
|
||||||
|
"Something went wrong.Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDirectoryNotes=(pageSize, pageNumber, filter, searchString)=>{
|
|
||||||
return useQuery({
|
export const useUpdateBucket = (onSuccessCallBack) => {
|
||||||
queryKey:["directoryNotes",pageSize, pageNumber, filter, searchString],
|
const queryClient = useQueryClient();
|
||||||
queryFn:async()=> await DirectoryRepository.GetBucktes(pageSize, pageNumber, filter, searchString),
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({ bucketId, BucketPayload}) => await DirectoryRepository.UpdateBuckets(bucketId, BucketPayload),
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["bucketList"] });
|
||||||
|
showToast("Bucket updated successfully", "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
"Something went wrong. Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const useAssignEmpToBucket =()=>{
|
||||||
|
return useMutation({
|
||||||
|
|
||||||
|
mutationFn:async({bucketId,EmployeePayload})=> await DirectoryRepository.AssignedBuckets(bucketId,EmployeePayload),
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
const {EmployeePayload} = variables
|
||||||
|
queryClient.invalidateQueries({queryKey: ["bucketList"]})
|
||||||
|
showToast(`Bucket shared ${EmployeePayload?.length} Employee Successfully`, "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.response.data.message ||
|
||||||
|
"Something went wrong.Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export const useDeleteBucket = (onSuccessCallBack) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (bucketId) =>
|
||||||
|
await DirectoryRepository.DeleteBucket(bucketId),
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({queryKey: ["bucketList"]})
|
||||||
|
showToast("Bucket deleted Successfully", "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.response.data.message ||
|
||||||
|
"Something went wrong.Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user