Merge branch 'Issues_April_4W' of https://git.marcoaiot.com/admin/marco.pms.web into pramod_Feature#51ProjectLisFilter
This commit is contained in:
commit
3e71511d8e
@ -34,18 +34,24 @@ const AssignRoleModel = ({ assignData, onClose }) => {
|
|||||||
const [selectedRole, setSelectedRole] = useState("all");
|
const [selectedRole, setSelectedRole] = useState("all");
|
||||||
const [selectedEmployees, setSelectedEmployees] = useState([]);
|
const [selectedEmployees, setSelectedEmployees] = useState([]);
|
||||||
|
|
||||||
|
const {
|
||||||
const { handleSubmit, control, setValue, watch, formState: { errors },reset } = useForm({
|
handleSubmit,
|
||||||
defaultValues: {
|
control,
|
||||||
selectedEmployees: [],
|
setValue,
|
||||||
description:""
|
watch,
|
||||||
},
|
formState: { errors },
|
||||||
resolver: (data) => {
|
reset,
|
||||||
const validation = schema.safeParse(data);
|
} = useForm({
|
||||||
if (validation.success) return { values: data, errors: {} };
|
defaultValues: {
|
||||||
return { values: {}, errors: validation.error.formErrors.fieldErrors };
|
selectedEmployees: [],
|
||||||
},
|
description: "",
|
||||||
});
|
},
|
||||||
|
resolver: (data) => {
|
||||||
|
const validation = schema.safeParse(data);
|
||||||
|
if (validation.success) return { values: data, errors: {} };
|
||||||
|
return { values: {}, errors: validation.error.formErrors.fieldErrors };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleRoleChange = (event) => {
|
const handleRoleChange = (event) => {
|
||||||
setSelectedRole(event.plannedTask.value);
|
setSelectedRole(event.plannedTask.value);
|
||||||
@ -78,62 +84,51 @@ const { handleSubmit, control, setValue, watch, formState: { errors },reset } =
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (data) => {
|
||||||
|
const formattedData = {
|
||||||
|
taskTeam: data.selectedEmployees,
|
||||||
|
plannedTask: parseInt(plannedTask, 10),
|
||||||
|
description: data.description,
|
||||||
|
assignmentDate: new Date().toISOString(),
|
||||||
|
workItemId: assignData?.workItem?.workItem.id,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
let response = await TasksRepository.assignTask(formattedData);
|
||||||
|
showToast( "Task Successfully Assigend", "success" );
|
||||||
|
setSelectedEmployees([])
|
||||||
|
reset();
|
||||||
|
closeModal()
|
||||||
|
|
||||||
const onSubmit = async(data) => {
|
} catch (error) {
|
||||||
const formattedData = {
|
showToast("something wrong", "error");
|
||||||
taskTeam: data.selectedEmployees,
|
}
|
||||||
plannedTask: parseInt( plannedTask, 10 ),
|
|
||||||
description: data.description,
|
|
||||||
assignmentDate: new Date().toISOString(),
|
|
||||||
workItemId:assignData?.workItem?.workItem.id
|
|
||||||
};
|
};
|
||||||
try
|
useEffect(() => {
|
||||||
{
|
dispatch(changeMaster("Job Role"));
|
||||||
let response = await TasksRepository.assignTask( formattedData );
|
return () => setSelectedRole("all");
|
||||||
showToast( "Task Successfully Assigend", "success" )
|
}, [dispatch]);
|
||||||
reset()
|
|
||||||
onClose()
|
|
||||||
} catch ( error )
|
|
||||||
{
|
|
||||||
showToast("something wrong","error")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
useEffect(()=>{
|
|
||||||
dispatch(changeMaster("Job Role"))
|
|
||||||
return ()=> setSelectedRole("all")
|
|
||||||
},[dispatch])
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="container my-1">
|
<div className="container my-1">
|
||||||
<div className="mb-2">
|
<div className="mb-">
|
||||||
<div className="bs-stepper wizard-numbered d-flex justify-content-center align-items-center flex-wrap">
|
<p className="fs-sm-5 fs-6 text-dark text-start d-flex align-items-center flex-wrap">
|
||||||
{[
|
{[
|
||||||
assignData?.building?.name,
|
assignData?.building?.name,
|
||||||
assignData?.floor?.floorName,
|
assignData?.floor?.floorName,
|
||||||
assignData?.workArea?.areaName,
|
assignData?.workArea?.areaName,
|
||||||
assignData?.workItem?.workItem?.activityMaster?.activityName,
|
assignData?.workItem?.workItem?.activityMaster?.activityName,
|
||||||
].map((item, index, array) => (
|
]
|
||||||
<div
|
.filter(Boolean)
|
||||||
key={index}
|
.map((item, index, array) => (
|
||||||
className="col d-flex justify-content-center align-items-center"
|
<span key={index} className="d-flex align-items-center">
|
||||||
>
|
{item}
|
||||||
<div className="bs-stepper-header p-1 text-center">
|
|
||||||
<span className="fs-5">{item}</span>
|
|
||||||
|
|
||||||
{/* Arrow between items */}
|
|
||||||
{index < array.length - 1 && (
|
{index < array.length - 1 && (
|
||||||
<div className="line">
|
<i className="bx bx-chevron-right mx-2"></i>
|
||||||
<i className="icon-base bx bx-chevron-right scaleX-n1-rtl"></i>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</span>
|
||||||
</div>
|
))}
|
||||||
))}
|
</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="row mb-1">
|
<div className="row mb-1">
|
||||||
@ -166,7 +161,10 @@ useEffect(()=>{
|
|||||||
<div className="divider text-start">
|
<div className="divider text-start">
|
||||||
<div className="divider-text">Employee</div>
|
<div className="divider-text">Employee</div>
|
||||||
</div>
|
</div>
|
||||||
{selectedRole !== "" && (
|
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12 col-md-8 h-sm-25 overflow-auto">
|
||||||
|
{selectedRole !== "" && (
|
||||||
<div className="row mb-2">
|
<div className="row mb-2">
|
||||||
<div className="col-sm-12">
|
<div className="col-sm-12">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
@ -178,7 +176,7 @@ useEffect(()=>{
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={emp.id}
|
key={emp.id}
|
||||||
className="col-6 col-sm-4 col-md-4 col-lg-3 mb-1"
|
className="col-6 col-sm-6 col-md-4 col-lg-4 mb-1"
|
||||||
>
|
>
|
||||||
<div className="form-check text-start p-0">
|
<div className="form-check text-start p-0">
|
||||||
<div className="li-wrapper d-flex justify-content-start align-items-start">
|
<div className="li-wrapper d-flex justify-content-start align-items-start">
|
||||||
@ -200,10 +198,19 @@ useEffect(()=>{
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="list-content">
|
<div className="list-content">
|
||||||
<h6 className="mb-0">
|
<p
|
||||||
|
className=" mb-0"
|
||||||
|
style={{
|
||||||
|
fontSize: "12px",
|
||||||
|
fontWeight: "bolder",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{emp.firstName} {emp.lastName}
|
{emp.firstName} {emp.lastName}
|
||||||
</h6>
|
</p>
|
||||||
<small className="text-muted">
|
<small
|
||||||
|
className="lead"
|
||||||
|
style={{ fontSize: "10px" }}
|
||||||
|
>
|
||||||
{loading && (
|
{loading && (
|
||||||
<p
|
<p
|
||||||
className="skeleton para"
|
className="skeleton para"
|
||||||
@ -224,7 +231,9 @@ useEffect(()=>{
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-4 h-25 overflow-auto" style={{maxHeight:"200px"}}>
|
||||||
|
|
||||||
{selectedEmployees.length > 0 && (
|
{selectedEmployees.length > 0 && (
|
||||||
<div className="mt-1">
|
<div className="mt-1">
|
||||||
<div className="text-start px-2">
|
<div className="text-start px-2">
|
||||||
@ -233,7 +242,7 @@ useEffect(()=>{
|
|||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
key={empId}
|
key={empId}
|
||||||
className="badge bg-label-primary d-inline-flex align-items-center gap-2 me-1 p-2 mb-2"
|
className="badge bg-label-primary d-inline-flex align-items-center gap-2 me-1 p-1 mb-2"
|
||||||
>
|
>
|
||||||
{emp.firstName} {emp.lastName}
|
{emp.firstName} {emp.lastName}
|
||||||
<p
|
<p
|
||||||
@ -256,6 +265,10 @@ useEffect(()=>{
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div className="col-md text-start mx-0 px-0">
|
<div className="col-md text-start mx-0 px-0">
|
||||||
<div className="form-check form-check-inline mt-4 px-1">
|
<div className="form-check form-check-inline mt-4 px-1">
|
||||||
@ -273,7 +286,7 @@ useEffect(()=>{
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control form-control-sm "
|
className="form-control form-control-xs"
|
||||||
value={plannedTask}
|
value={plannedTask}
|
||||||
onChange={(e) => setPlannedTask(e.target.value)}
|
onChange={(e) => setPlannedTask(e.target.value)}
|
||||||
id="defaultFormControlInput"
|
id="defaultFormControlInput"
|
||||||
@ -298,7 +311,7 @@ useEffect(()=>{
|
|||||||
{...field}
|
{...field}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
id="exampleFormControlTextarea1"
|
id="exampleFormControlTextarea1"
|
||||||
rows="3"
|
rows="2"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
@ -159,8 +159,14 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
|||||||
</a>
|
</a>
|
||||||
<a className="dropdown-item">
|
<a className="dropdown-item">
|
||||||
{" "}
|
{" "}
|
||||||
<i className="bx bx-trash me-1 text-danger"></i>Delete
|
<i className="bx bx-trash me-1 text-danger" ></i>Delete
|
||||||
</a>
|
</a>
|
||||||
|
{!projectId && ( <a className="dropdown-item" data-bs-toggle="modal"
|
||||||
|
data-bs-target="#project-modal"
|
||||||
|
onClick={openModal}>
|
||||||
|
{" "}
|
||||||
|
<i className="bx bx-task me-1 text-info" ></i>Assign
|
||||||
|
</a> )}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@ -79,18 +79,18 @@ const ProjectBanner = ( {project_data} ) =>
|
|||||||
{/* Project Banner */}
|
{/* Project Banner */}
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card mb-6 pb-0">
|
<div className="card mb-6 pb-0">
|
||||||
<div className="d-flex align-items-center justify-content-between p-4 flex-wrap">
|
<div className="d-flex align-items-center justify-content-between p-2 flex-wrap">
|
||||||
{/* Left: Icon + Name */}
|
{/* Left: Icon + Name */}
|
||||||
<div className="d-flex align-items-center gap-3">
|
<div className="d-flex align-items-center gap-3">
|
||||||
<img
|
<img
|
||||||
src="../../assets/icons/civil-engineering.svg"
|
src="../../assets/icons/civil-engineering.svg"
|
||||||
alt="user image"
|
alt="user image"
|
||||||
className="rounded-3"
|
className="rounded-3"
|
||||||
style={{ width: "60px", height: "60px" }}
|
style={{ width: "40px", height: "40px" }}
|
||||||
/>
|
/>
|
||||||
<h4 className="mb-0">
|
<h5 className="mb-0">
|
||||||
{CurrentProject.name ? CurrentProject.name : "N/A"}
|
{CurrentProject.name ? CurrentProject.name : "N/A"}
|
||||||
</h4>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
{manageProject && (
|
{manageProject && (
|
||||||
<button
|
<button
|
||||||
|
@ -45,7 +45,7 @@ const GlobalModel = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`modal fade ${modalType}`}
|
className={`modal fade ${ modalType }`}
|
||||||
id="customModal"
|
id="customModal"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
aria-labelledby="exampleModalLabel"
|
aria-labelledby="exampleModalLabel"
|
||||||
@ -53,9 +53,9 @@ const GlobalModel = ({
|
|||||||
ref={modalRef} // Assign the ref to the modal element
|
ref={modalRef} // Assign the ref to the modal element
|
||||||
{...dataAttributesProps}
|
{...dataAttributesProps}
|
||||||
>
|
>
|
||||||
<div className={`modal-dialog ${dialogClass} ${modalSizeClass}`} role={role}>
|
<div className={`modal-dialog ${dialogClass} ${modalSizeClass } mx-sm-auto mx-1`} role={role}>
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
<div className="modal-header">
|
<div className="modal-header p-0">
|
||||||
{/* Close button inside the modal header */}
|
{/* Close button inside the modal header */}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@ -65,7 +65,7 @@ const GlobalModel = ({
|
|||||||
onClick={closeModal} // Trigger the React closeModal function
|
onClick={closeModal} // Trigger the React closeModal function
|
||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-body">
|
<div className="modal-body p-sm-4 p-0">
|
||||||
{children} {/* Render children here, which can be the ReportTask component */}
|
{children} {/* Render children here, which can be the ReportTask component */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,6 +7,7 @@ import { setProjectId } from "../slices/localVariablesSlice";
|
|||||||
|
|
||||||
export const useProjects = () =>
|
export const useProjects = () =>
|
||||||
{
|
{
|
||||||
|
const {profile} = useProfile()
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [projects, setProjects] = useState([]);
|
const [projects, setProjects] = useState([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@ -48,9 +49,19 @@ export const useProjects = () =>
|
|||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect( () =>
|
||||||
dispatch(setProjectId(projects[0]?.id));
|
{
|
||||||
}, [projects]);
|
if (projects )
|
||||||
|
{
|
||||||
|
if ( profile?.projects && profile?.projects?.length > 0 )
|
||||||
|
{
|
||||||
|
dispatch(setProjectId(profile?.projects[0]))
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
dispatch(setProjectId(1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [profile]);
|
||||||
|
|
||||||
return { projects, loading, error, refetch: fetchData };
|
return { projects, loading, error, refetch: fetchData };
|
||||||
};
|
};
|
||||||
|
@ -19,15 +19,37 @@ const DailyTask = () => {
|
|||||||
const { profile: LoggedUser } = useProfile();
|
const { profile: LoggedUser } = useProfile();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const projectId = searchParams.get("project");
|
const projectId = searchParams.get("project");
|
||||||
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
const {
|
const {
|
||||||
projects,
|
projects,
|
||||||
loading: project_lodaing,
|
loading: project_lodaing,
|
||||||
error: projects_Error,
|
error: projects_Error,
|
||||||
} = useProjects();
|
} = useProjects();
|
||||||
const selectedProject = useSelector(
|
|
||||||
(store) => store.localVariables.projectId
|
|
||||||
);
|
|
||||||
|
const [initialized, setInitialized] = useState(false);
|
||||||
|
|
||||||
|
// Sync projectId (either from URL or pick first accessible one)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!project_lodaing && projects.length > 0) {
|
||||||
|
const userProjects = projects.filter((p) =>
|
||||||
|
LoggedUser?.projects?.map(Number).includes(p.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (projectId) {
|
||||||
|
dispatch(setProjectId(projectId));
|
||||||
|
} else if (!selectedProject && userProjects.length > 0) {
|
||||||
|
dispatch(setProjectId(userProjects[0].id));
|
||||||
|
}
|
||||||
|
|
||||||
|
setInitialized(true);
|
||||||
|
}
|
||||||
|
}, [project_lodaing, projects, projectId, selectedProject]);
|
||||||
|
|
||||||
|
|
||||||
const dispatch = useDispatch(selectedProject);
|
const dispatch = useDispatch(selectedProject);
|
||||||
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
||||||
|
|
||||||
@ -60,9 +82,6 @@ const DailyTask = () => {
|
|||||||
openModal();
|
openModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (projectId) dispatch(setProjectId(projectId));
|
|
||||||
}, [projectId]);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@ -161,6 +180,11 @@ const DailyTask = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
|
{(!initialized || !selectedProject) && ( <tr>
|
||||||
|
<td colSpan={7} className="text-center">
|
||||||
|
<p>Loading..</p>
|
||||||
|
</td>
|
||||||
|
</tr>)}
|
||||||
|
|
||||||
{TaskLists.map((task, index) => {
|
{TaskLists.map((task, index) => {
|
||||||
const accordionId = `accordion-${index}`;
|
const accordionId = `accordion-${index}`;
|
||||||
|
@ -35,13 +35,17 @@ const ForgotPasswordPage = () => {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
const response = await AuthRepository.forgotPassword(data)
|
const response = await AuthRepository.forgotPassword(data)
|
||||||
if ( response.data && response.success )
|
if ( response.data && response.success )
|
||||||
showToast( response.message, "success" )
|
showToast( "verification email has been sent to your registered email address", "success" )
|
||||||
reset()
|
reset()
|
||||||
setLoading( false )
|
setLoading( false )
|
||||||
} catch ( err )
|
} catch ( err )
|
||||||
{
|
{
|
||||||
|
if(err.response.status === 404){
|
||||||
|
showToast( "verification email has been sent to your registered email address", "success" )
|
||||||
|
}else{
|
||||||
|
showToast("Something wrong","error")
|
||||||
|
}
|
||||||
|
|
||||||
showToast( err.message, "error" )
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ const LoginPage = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
navigate("/dashboard");
|
navigate("/dashboard");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
showToast("Invalid username or password.","error")
|
||||||
console.log("Unable to proceed. Please try again.");
|
console.log("Unable to proceed. Please try again.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
@ -163,30 +163,32 @@ const EmployeeList = () => {
|
|||||||
className="dataTables_length text-start"
|
className="dataTables_length text-start"
|
||||||
id="DataTables_Table_0_length"
|
id="DataTables_Table_0_length"
|
||||||
>
|
>
|
||||||
<label>
|
<label>
|
||||||
<select
|
<select
|
||||||
id="project-select"
|
id="project-select"
|
||||||
onChange={(e) => setSelectedProject(e.target.value)}
|
onChange={(e) => setSelectedProject(e.target.value)}
|
||||||
name="DataTables_Table_0_length"
|
name="DataTables_Table_0_length"
|
||||||
aria-controls="DataTables_Table_0"
|
aria-controls="DataTables_Table_0"
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
value={selectedProject || ""}
|
value={selectedProject || ""}
|
||||||
>
|
>
|
||||||
{projectLoading ? (
|
{projectLoading ? (
|
||||||
<option value="Loading">Loading...</option>
|
<option value="Loading">Loading...</option>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<option value="">All Employees</option>
|
<option value="">All Employees</option>
|
||||||
{Array.isArray(projects) &&
|
{Array.isArray(projects) &&
|
||||||
projects.map((item) => (
|
projects
|
||||||
<option key={item.id} value={item.id}>
|
.filter((item) => loginUser?.projects?.includes(String(item.id)))
|
||||||
{item.name}
|
.map((item) => (
|
||||||
</option>
|
<option key={item.id} value={item.id}>
|
||||||
))}
|
{item.name}
|
||||||
</>
|
</option>
|
||||||
)}
|
))}
|
||||||
</select>
|
</>
|
||||||
</label>
|
)}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -210,6 +210,17 @@ const ProjectList = () => {
|
|||||||
currentItems.map((item) => (
|
currentItems.map((item) => (
|
||||||
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
||||||
))}
|
))}
|
||||||
|
=======
|
||||||
|
|
||||||
|
|
||||||
|
{Array.isArray(currentItems) && loginUser?.projects && (
|
||||||
|
currentItems
|
||||||
|
.filter((item) => loginUser.projects.includes(String(item.id)))
|
||||||
|
.map((item) => (
|
||||||
|
<ProjectCard projectData={item} key={item.id} />
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
>>>>>>> 148058d1d22430d0c2a314cdade3509b38c5d090
|
||||||
</div>
|
</div>
|
||||||
{/* Pagination */}
|
{/* Pagination */}
|
||||||
{!loading && (
|
{!loading && (
|
||||||
|
@ -11,7 +11,6 @@ export const axiosClient = axios.create({
|
|||||||
"Content-Type": "application/json", // Specify the content type
|
"Content-Type": "application/json", // Specify the content type
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
axiosRetry(axiosClient, { retries: 3 });
|
axiosRetry(axiosClient, { retries: 3 });
|
||||||
|
|
||||||
// Request interceptor to add Bearer token
|
// Request interceptor to add Bearer token
|
||||||
@ -21,6 +20,10 @@ axiosClient.interceptors.request.use(
|
|||||||
const token = localStorage.getItem("jwtToken");
|
const token = localStorage.getItem("jwtToken");
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers["Authorization"] = `Bearer ${token}`;
|
config.headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
config._retry = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
config._retry = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
@ -32,7 +35,9 @@ axiosClient.interceptors.request.use(
|
|||||||
// Add an interceptor to handle expired tokens
|
// Add an interceptor to handle expired tokens
|
||||||
axiosClient.interceptors.response.use(
|
axiosClient.interceptors.response.use(
|
||||||
(response) => response,
|
(response) => response,
|
||||||
|
|
||||||
async (error) => {
|
async (error) => {
|
||||||
|
|
||||||
const originalRequest = error.config;
|
const originalRequest = error.config;
|
||||||
|
|
||||||
if (!originalRequest) {
|
if (!originalRequest) {
|
||||||
@ -80,13 +85,12 @@ axiosClient.interceptors.response.use(
|
|||||||
if (error.config.url.indexOf("refresh-token") != -1) {
|
if (error.config.url.indexOf("refresh-token") != -1) {
|
||||||
//showToast("Server is unreachable. Try again later!", "error");
|
//showToast("Server is unreachable. Try again later!", "error");
|
||||||
console.log("4 - error fetching refresh token :", error);
|
console.log("4 - error fetching refresh token :", error);
|
||||||
} else {
|
}
|
||||||
showToast(error.response.data.message, "error");
|
// else {
|
||||||
}
|
// // showToast(error.response.data.message, "error"); // repeted toast
|
||||||
|
// }
|
||||||
if (error.response.status === 401 && !originalRequest._retry) {
|
if (error.response.status === 401 && !originalRequest._retry) {
|
||||||
originalRequest._retry = true;
|
originalRequest._retry = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the refresh token from secure storage
|
// Get the refresh token from secure storage
|
||||||
const refreshToken = localStorage.getItem("refreshToken");
|
const refreshToken = localStorage.getItem("refreshToken");
|
||||||
@ -129,11 +133,11 @@ axiosClient.interceptors.response.use(
|
|||||||
//showToast("Server is unreachable. Try again later!", "error");
|
//showToast("Server is unreachable. Try again later!", "error");
|
||||||
console.log("6 - error fetching refresh token :", error);
|
console.log("6 - error fetching refresh token :", error);
|
||||||
}
|
}
|
||||||
showToast(
|
// showToast(
|
||||||
error.response.data?.message ||
|
// error.response.data?.message ||
|
||||||
"An error occurred. Please try again.",
|
// "An error occurred. Please try again.",
|
||||||
"error"
|
// "error"
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("An unknown error occurred:", error.message);
|
console.error("An unknown error occurred:", error.message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user