pramod_Bug#62CreateActivity #40
@ -12,8 +12,9 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => {
|
|||||||
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
||||||
|
|
||||||
// Set the default selected date to the current date
|
// Set the default selected date to the current date
|
||||||
const currentDate = new Date().toISOString().split("T")[0]; // "YYYY-MM-DD"
|
|
||||||
|
// const currentDate = new Date().toISOString().split("T")[0]; // "YYYY-MM-DD"
|
||||||
|
const currentDate = new Date().toLocaleDateString('en-CA');
|
||||||
const handleDateChange = (e) => {
|
const handleDateChange = (e) => {
|
||||||
const date = e.target.value;
|
const date = e.target.value;
|
||||||
setSelectedDate(date);
|
setSelectedDate(date);
|
||||||
|
@ -35,7 +35,6 @@ const CheckCheckOutmodel = ({modeldata,closeModal,handleSubmitForm,}) => {
|
|||||||
|
|
||||||
const onSubmit = ( data ) =>
|
const onSubmit = ( data ) =>
|
||||||
{
|
{
|
||||||
console.log(data)
|
|
||||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,action:modeldata.action,id:modeldata?.id || null}
|
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,action:modeldata.action,id:modeldata?.id || null}
|
||||||
if(modeldata.forWhichTab === 1){
|
if(modeldata.forWhichTab === 1){
|
||||||
handleSubmitForm(record)
|
handleSubmitForm(record)
|
||||||
@ -134,7 +133,8 @@ export const Regularization = ({modeldata,closeModal,handleSubmitForm})=>{
|
|||||||
|
|
||||||
const getCurrentDate = () => {
|
const getCurrentDate = () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
return today.toISOString().split("T")[0];
|
// return today.toISOString().split("T")[0];
|
||||||
|
return today.toLocaleDateString('en-CA');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -143,7 +143,6 @@ export const Regularization = ({modeldata,closeModal,handleSubmitForm})=>{
|
|||||||
|
|
||||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude, }
|
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude, }
|
||||||
|
|
||||||
console.log(record)
|
|
||||||
handleSubmitForm(record)
|
handleSubmitForm(record)
|
||||||
closeModal()
|
closeModal()
|
||||||
};
|
};
|
||||||
|
@ -37,7 +37,8 @@ const Dashboard = () => {
|
|||||||
|
|
||||||
const days = getDaysFromRange(range);
|
const days = getDaysFromRange(range);
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const FromDate = today.toISOString().split("T")[0]; // Always today
|
// const FromDate = today.toISOString().split("T")[0];
|
||||||
|
const FromDate = today.toLocaleDateString('en-CA'); // Always today
|
||||||
|
|
||||||
const { projectsCardData } = useDashboardProjectsCardData();
|
const { projectsCardData } = useDashboardProjectsCardData();
|
||||||
const { teamsCardData } = useDashboardTeamsCardData();
|
const { teamsCardData } = useDashboardTeamsCardData();
|
||||||
|
@ -23,8 +23,10 @@ const ManageEmployee = () => {
|
|||||||
employee,
|
employee,
|
||||||
error,
|
error,
|
||||||
loading: empLoading,
|
loading: empLoading,
|
||||||
} = useEmployeeProfile(employeeId);
|
} = useEmployeeProfile( employeeId );
|
||||||
dispatch(changeMaster("Job Role"));
|
|
||||||
|
dispatch( changeMaster( "Job Role" ) );
|
||||||
|
|
||||||
const [disabledEmail, setDisabledEmail] = useState(false);
|
const [disabledEmail, setDisabledEmail] = useState(false);
|
||||||
const { data: job_role, loading } = useMaster();
|
const { data: job_role, loading } = useMaster();
|
||||||
const [isloading, setLoading] = useState(false);
|
const [isloading, setLoading] = useState(false);
|
||||||
@ -39,7 +41,7 @@ const ManageEmployee = () => {
|
|||||||
MiddleName: z.string().optional(),
|
MiddleName: z.string().optional(),
|
||||||
LastName: z.string().min(1, { message: "Last Name is required" }),
|
LastName: z.string().min(1, { message: "Last Name is required" }),
|
||||||
Email: z
|
Email: z
|
||||||
.string()
|
.string().max(80,"Email cannot exceed 80 characters")
|
||||||
.optional()
|
.optional()
|
||||||
.refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
|
.refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
|
||||||
message: "Invalid email format",
|
message: "Invalid email format",
|
||||||
@ -59,7 +61,7 @@ const ManageEmployee = () => {
|
|||||||
CurrentAddress: z
|
CurrentAddress: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Current Address is required" })
|
.min(1, { message: "Current Address is required" })
|
||||||
.max(500, { message: "Address cannot exceed 250 characters" }),
|
.max(500, { message: "Address cannot exceed 500 characters" }),
|
||||||
BirthDate: z
|
BirthDate: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Birth Date is required" })
|
.min(1, { message: "Birth Date is required" })
|
||||||
@ -111,7 +113,7 @@ const ManageEmployee = () => {
|
|||||||
PermanentAddress: z
|
PermanentAddress: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Permanent Address is required" })
|
.min(1, { message: "Permanent Address is required" })
|
||||||
.max(500, { message: "Address cannot exceed 250 characters" }),
|
.max(500, { message: "Address cannot exceed 500 characters" }),
|
||||||
PhoneNumber: z
|
PhoneNumber: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Phone Number is required" })
|
.min(1, { message: "Phone Number is required" })
|
||||||
@ -150,7 +152,8 @@ const ManageEmployee = () => {
|
|||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
const AadharNumberValue = watch("AadharNumber") || "";
|
const AadharNumberValue = watch( "AadharNumber" ) || "";
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -181,8 +184,11 @@ const ManageEmployee = () => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
showToast("Employee details updated successfully.", "success");
|
showToast("Employee details updated successfully.", "success");
|
||||||
clearCacheKey("employeeListByProject");
|
clearCacheKey("employeeListByProject");
|
||||||
clearCacheKey("allEmployeeList");
|
clearCacheKey( "allEmployeeList" );
|
||||||
setLoading(false);
|
clearCacheKey("employeeProfile")
|
||||||
|
|
||||||
|
setLoading( false );
|
||||||
|
reset()
|
||||||
navigation("/employees");
|
navigation("/employees");
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -251,7 +257,7 @@ const ManageEmployee = () => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
{!currentEmployee && empLoading && (
|
{(!currentEmployee && empLoading) && (
|
||||||
<p>Loading Employee Data...</p>
|
<p>Loading Employee Data...</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -324,7 +330,7 @@ const ManageEmployee = () => {
|
|||||||
{...register("Email")}
|
{...register("Email")}
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
placeholder="example@domain.com"
|
placeholder="example@domain.com"
|
||||||
aria-label=""
|
maxLength={80}
|
||||||
aria-describedby="Email"
|
aria-describedby="Email"
|
||||||
disabled={!!currentEmployee?.email}
|
disabled={!!currentEmployee?.email}
|
||||||
/>
|
/>
|
||||||
@ -347,6 +353,7 @@ const ManageEmployee = () => {
|
|||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
placeholder="Phone Number"
|
placeholder="Phone Number"
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
|
maxLength={10}
|
||||||
/>
|
/>
|
||||||
{errors.PhoneNumber && (
|
{errors.PhoneNumber && (
|
||||||
<div
|
<div
|
||||||
@ -438,15 +445,16 @@ const ManageEmployee = () => {
|
|||||||
placeholder="Current Address"
|
placeholder="Current Address"
|
||||||
aria-label="Current Address"
|
aria-label="Current Address"
|
||||||
aria-describedby="basic-icon-default-message2"
|
aria-describedby="basic-icon-default-message2"
|
||||||
{...register("CurrentAddress")}
|
{...register( "CurrentAddress" )}
|
||||||
|
maxLength={500}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setCurrentAddressLength(e.target.value.length);
|
setCurrentAddressLength(e.target.value.length);
|
||||||
// let react-hook-form still handle it
|
// let react-hook-form still handle it
|
||||||
register("CurrentAddress").onChange(e);
|
register("CurrentAddress").onChange(e);
|
||||||
}}
|
}}
|
||||||
></textarea>
|
></textarea>
|
||||||
<div className="text-end small">
|
<div className="text-end muted">
|
||||||
{500 - currentAddressLength} characters left
|
<small> {500 - currentAddressLength} characters left</small>
|
||||||
</div>
|
</div>
|
||||||
{errors.CurrentAddress && (
|
{errors.CurrentAddress && (
|
||||||
<div
|
<div
|
||||||
@ -468,14 +476,15 @@ const ManageEmployee = () => {
|
|||||||
placeholder="Permanent Address"
|
placeholder="Permanent Address"
|
||||||
aria-label="Permanent Address"
|
aria-label="Permanent Address"
|
||||||
aria-describedby="basic-icon-default-message2"
|
aria-describedby="basic-icon-default-message2"
|
||||||
{...register("PermanentAddress")}
|
{...register( "PermanentAddress" )}
|
||||||
|
maxLength={500}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPermanentAddressLength(e.target.value.length);
|
setPermanentAddressLength(e.target.value.length);
|
||||||
register("PermanentAddress").onChange(e);
|
register("PermanentAddress").onChange(e);
|
||||||
}}
|
}}
|
||||||
></textarea>
|
></textarea>
|
||||||
<div className="text-end small">
|
<div className="text-end muted">
|
||||||
{500 - permanentAddressLength} characters left
|
<small>{500 - permanentAddressLength} characters left</small>
|
||||||
</div>
|
</div>
|
||||||
{errors.PermanentAddress && (
|
{errors.PermanentAddress && (
|
||||||
<div
|
<div
|
||||||
@ -554,6 +563,7 @@ const ManageEmployee = () => {
|
|||||||
id="EmergencyPhoneNumber"
|
id="EmergencyPhoneNumber"
|
||||||
placeholder="Phone Number"
|
placeholder="Phone Number"
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
|
maxLength={10}
|
||||||
/>
|
/>
|
||||||
{errors.EmergencyPhoneNumber && (
|
{errors.EmergencyPhoneNumber && (
|
||||||
<div
|
<div
|
||||||
|
@ -30,7 +30,7 @@ const ManageRole = ({ employeeId, onClosed }) => {
|
|||||||
const buildDefaultRoles = () => {
|
const buildDefaultRoles = () => {
|
||||||
const defaults = {};
|
const defaults = {};
|
||||||
data.forEach((role) => {
|
data.forEach((role) => {
|
||||||
const isRoleEnabled = employeeRoles?.data?.some(
|
const isRoleEnabled = employeeRoles?.some(
|
||||||
(empRole) => empRole.roleId === role.id
|
(empRole) => empRole.roleId === role.id
|
||||||
);
|
);
|
||||||
defaults[role.id] = isRoleEnabled;
|
defaults[role.id] = isRoleEnabled;
|
||||||
|
@ -3,7 +3,8 @@ import { useForm, Controller } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const currentDate = new Date().toISOString().split("T")[0];
|
// const currentDate = new Date().toISOString().split("T")[0];
|
||||||
|
const currentDate = new Date().toLocaleDateString('en-CA');
|
||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
return currentDate;
|
return currentDate;
|
||||||
@ -12,7 +13,8 @@ const formatDate = (date) => {
|
|||||||
if (isNaN(d.getTime())) {
|
if (isNaN(d.getTime())) {
|
||||||
return currentDate;
|
return currentDate;
|
||||||
}
|
}
|
||||||
return d.toISOString().split("T")[0];
|
// return d.toISOString().split("T")[0];
|
||||||
|
return d.toLocaleDateString('en-CA');
|
||||||
};
|
};
|
||||||
const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
||||||
const [CurrentProject, setCurrentProject] = useState();
|
const [CurrentProject, setCurrentProject] = useState();
|
||||||
|
@ -4,7 +4,7 @@ import {useEmployeesByProjectAllocated, useProjects} from "../../hooks/useProjec
|
|||||||
const ProjectOverview = ({project}) =>
|
const ProjectOverview = ({project}) =>
|
||||||
{
|
{
|
||||||
const {projects} = useProjects()
|
const {projects} = useProjects()
|
||||||
const teamSize = projects.find((pro)=>pro.id == project)
|
const project_detail = projects.find( ( pro ) => pro.id == project )
|
||||||
return (
|
return (
|
||||||
<div className="card mb-6">
|
<div className="card mb-6">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
@ -15,17 +15,18 @@ const teamSize = projects.find((pro)=>pro.id == project)
|
|||||||
<li className="d-flex align-items-center mb-4">
|
<li className="d-flex align-items-center mb-4">
|
||||||
<i className="bx bx-check"></i>
|
<i className="bx bx-check"></i>
|
||||||
<span className="fw-medium mx-2">Task Planned:</span>{" "}
|
<span className="fw-medium mx-2">Task Planned:</span>{" "}
|
||||||
<span>13.5k</span>
|
<span>{project_detail?.plannedWork
|
||||||
|
}</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex align-items-center mb-4">
|
<li className="d-flex align-items-center mb-4">
|
||||||
<i className="bx bx-star"></i>
|
<i className="bx bx-star"></i>
|
||||||
<span className="fw-medium mx-2">Task Completed:</span>{" "}
|
<span className="fw-medium mx-2">Task Completed:</span>{" "}
|
||||||
<span>146</span>
|
<span>{project_detail?.completedWork }</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex align-items-center">
|
<li className="d-flex align-items-center">
|
||||||
<i className="bx bx-user"></i>
|
<i className="bx bx-user"></i>
|
||||||
<span className="fw-medium mx-2">Current team Size:</span>{" "}
|
<span className="fw-medium mx-2">Current team Size:</span>{" "}
|
||||||
<span>{teamSize?.teamSize}</span>
|
<span>{project_detail?.teamSize}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,10 +20,12 @@ const DateRangePicker = ({ onRangeChange }) => {
|
|||||||
onRangeChange?.({ startDate, endDate });
|
onRangeChange?.({ startDate, endDate });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
onRangeChange?.({
|
onRangeChange?.({
|
||||||
startDate: fifteenDaysAgo.toISOString().split("T")[0],
|
// startDate: fifteenDaysAgo.toISOString().split("T")[0],
|
||||||
endDate: today.toISOString().split("T")[0],
|
// endDate: today.toISOString().split("T")[0],
|
||||||
|
startDate: fifteenDaysAgo.toLocaleDateString('en-CA'),
|
||||||
|
endDate: today.toLocaleDateString('en-CA'),
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -14,7 +14,7 @@ const schema = z.object({
|
|||||||
checkList: z
|
checkList: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
check: z.string().min(1, { message: "Checklist item cannot be empty" }),
|
description: z.string().min(1, { message: "descriptionlist item cannot be empty" }),
|
||||||
isMandatory: z.boolean().default(false),
|
isMandatory: z.boolean().default(false),
|
||||||
id: z.any().default(0),
|
id: z.any().default(0),
|
||||||
})
|
})
|
||||||
@ -82,18 +82,18 @@ const CreateActivity = ({ onClose }) => {
|
|||||||
const lastIndex = checkListItems.length - 1;
|
const lastIndex = checkListItems.length - 1;
|
||||||
if (
|
if (
|
||||||
checkListItems.length > 0 &&
|
checkListItems.length > 0 &&
|
||||||
(!values?.[lastIndex] || values[lastIndex].check.trim() === "")
|
(!values?.[lastIndex] || values[lastIndex].description.trim() === "")
|
||||||
) {
|
) {
|
||||||
setError(`checkList.${lastIndex}.check`, {
|
setError(`checkList.${lastIndex}.description`, {
|
||||||
type: "manual",
|
type: "manual",
|
||||||
message: "Please fill this checklist item before adding another.",
|
message: "Please fill this checklist item before adding another.",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearErrors(`checkList.${lastIndex}.check`);
|
clearErrors(`checkList.${lastIndex}.description`);
|
||||||
append({
|
append({
|
||||||
id: 0,
|
id: 0,
|
||||||
check: "",
|
description: "",
|
||||||
isMandatory: false,
|
isMandatory: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -167,19 +167,19 @@ const CreateActivity = ({ onClose }) => {
|
|||||||
{...register(`checkList.${index}.id`)}
|
{...register(`checkList.${index}.id`)}
|
||||||
></input>
|
></input>
|
||||||
<input
|
<input
|
||||||
{...register(`checkList.${index}.check`)}
|
{...register(`checkList.${index}.description`)}
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
placeholder={`Checklist item ${index + 1}`}
|
placeholder={`Checklist item ${index + 1}`}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
handleChecklistChange(index, e.target.value)
|
handleChecklistChange(index, e.target.value)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{errors.checkList?.[index]?.check && (
|
{errors.checkList?.[index]?.description && (
|
||||||
<small
|
<small
|
||||||
style={{ fontSize: "10px" }}
|
style={{ fontSize: "10px" }}
|
||||||
className="danger-text"
|
className="danger-text"
|
||||||
>
|
>
|
||||||
{errors.checkList[index]?.check?.message}
|
{errors.checkList[index]?.description?.message}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
@ -14,7 +14,7 @@ const schema = z.object({
|
|||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.any().default(0),
|
id: z.any().default(0),
|
||||||
check: z.string().min(1, { message: "Checklist item cannot be empty" }),
|
description: z.string().min(1, { message: "Checklist item cannot be empty" }),
|
||||||
isMandatory: z.boolean().default(false),
|
isMandatory: z.boolean().default(false),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -106,17 +106,17 @@ const UpdateActivity = ({ activityData, onClose }) => {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
checkListItems.length > 0 &&
|
checkListItems.length > 0 &&
|
||||||
(!values?.[lastIndex] || values[lastIndex].check.trim() === "")
|
(!values?.[lastIndex] || values[lastIndex].description.trim() === "")
|
||||||
) {
|
) {
|
||||||
setError(`checkList.${lastIndex}.check`, {
|
setError(`checkList.${lastIndex}.description`, {
|
||||||
type: "manual",
|
type: "manual",
|
||||||
message: "Please fill this checklist item before adding another.",
|
message: "Please fill this checklist item before adding another.",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearErrors(`checkList.${lastIndex}.check`);
|
clearErrors(`checkList.${lastIndex}.description`);
|
||||||
append({ id: 0, check: "", isMandatory: false });
|
append({ id: 0, description: "", isMandatory: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeChecklistItem = (index) => {
|
const removeChecklistItem = (index) => {
|
||||||
@ -178,19 +178,19 @@ const UpdateActivity = ({ activityData, onClose }) => {
|
|||||||
{...register(`checkList.${index}.id`)}
|
{...register(`checkList.${index}.id`)}
|
||||||
></input>
|
></input>
|
||||||
<input
|
<input
|
||||||
{...register(`checkList.${index}.check`)}
|
{...register(`checkList.${index}.description`)}
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
placeholder={`Checklist item ${index + 1}`}
|
placeholder={`Checklist item ${index + 1}`}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
handleChecklistChange(index, e.target.value)
|
handleChecklistChange(index, e.target.value)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{errors.checkList?.[index]?.check && (
|
{errors.checkList?.[index]?.description && (
|
||||||
<small
|
<small
|
||||||
style={{ fontSize: "10px" }}
|
style={{ fontSize: "10px" }}
|
||||||
className="danger-text"
|
className="danger-text"
|
||||||
>
|
>
|
||||||
{errors.checkList[index]?.check?.message}
|
{errors.checkList[index]?.description?.message}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
@ -208,7 +208,7 @@ const UpdateActivity = ({ activityData, onClose }) => {
|
|||||||
onClick={() => removeChecklistItem(index)}
|
onClick={() => removeChecklistItem(index)}
|
||||||
className="btn btn-xs btn-icon btn-text-secondary"
|
className="btn btn-xs btn-icon btn-text-secondary"
|
||||||
>
|
>
|
||||||
<i class="bx bxs-minus-circle text-danger"></i>
|
<i className="bx bxs-minus-circle text-danger"></i>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -223,7 +223,7 @@ const UpdateActivity = ({ activityData, onClose }) => {
|
|||||||
className="btn btn-xs btn-primary mt-2"
|
className="btn btn-xs btn-primary mt-2"
|
||||||
onClick={addChecklistItem}
|
onClick={addChecklistItem}
|
||||||
>
|
>
|
||||||
<i class="bx bx-plus-circle"></i>
|
<i className="bx bx-plus-circle"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ export const useEmployeeRoles = (employeeId)=>{
|
|||||||
try {
|
try {
|
||||||
RolesRepository.getEmployeeRoles(employeeid)
|
RolesRepository.getEmployeeRoles(employeeid)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setEmployeeRoles(response);
|
setEmployeeRoles(response.data);
|
||||||
cacheData("employeelist", response);
|
cacheData("employeelist", response.data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setError("Failed to fetch data.");
|
setError("Failed to fetch data.");
|
||||||
|
@ -458,30 +458,30 @@ const EmployeeList = () => {
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/employee/${item.id}`)
|
navigate(`/employee/${item.id}`)
|
||||||
}
|
}
|
||||||
className="dropdown-item"
|
className="dropdown-item py-1"
|
||||||
>
|
>
|
||||||
View
|
<i className="bx bx-detail bx-sm"></i> View
|
||||||
</button>
|
</button>
|
||||||
<Link
|
<Link
|
||||||
to={`/employee/manage/${item.id}`}
|
to={`/employee/manage/${item.id}`}
|
||||||
className="dropdown-item"
|
className="dropdown-item py-1"
|
||||||
>
|
>
|
||||||
Edit
|
<i class='bx bx-edit bx-sm'></i> Edit
|
||||||
</Link>
|
</Link>
|
||||||
<button
|
<button
|
||||||
className="dropdown-item"
|
className="dropdown-item py-1"
|
||||||
onClick={handleShow}
|
onClick={handleShow}
|
||||||
>
|
>
|
||||||
Suspend
|
<i class='bx bx-task-x bx-sm'></i> Suspend
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="dropdown-item"
|
className="dropdown-item py-1"
|
||||||
type="button"
|
type="button"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#managerole-modal"
|
data-bs-target="#managerole-modal"
|
||||||
onClick={() => handleConfigData(item.id)}
|
onClick={() => handleConfigData(item.id)}
|
||||||
>
|
>
|
||||||
Manage Role
|
<i class='bx bx-cog bx-sm'></i> Manage Role
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -41,31 +41,32 @@ const isTokenExpired = (token) => {
|
|||||||
// Function to validate and refresh the token if expired
|
// Function to validate and refresh the token if expired
|
||||||
export const validateToken = async () => {
|
export const validateToken = async () => {
|
||||||
const token = localStorage.getItem("jwtToken");
|
const token = localStorage.getItem("jwtToken");
|
||||||
|
const refreshTokenStored = localStorage.getItem("refreshToken");
|
||||||
|
// If refresh token is absent, cannot proceed
|
||||||
|
if (!refreshTokenStored) {
|
||||||
|
console.warn("No refresh token available. Redirecting to login.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If access token expired, try to refresh
|
||||||
if (isTokenExpired(token)) {
|
if (isTokenExpired(token)) {
|
||||||
const refreshed = await refreshToken();
|
return await attemptTokenRefresh(refreshTokenStored);
|
||||||
return refreshed;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to refresh the access token
|
// Attempt to refresh the access token
|
||||||
const refreshToken = async () => {
|
const attemptTokenRefresh = async (storedRefreshToken) => {
|
||||||
try {
|
try {
|
||||||
AuthRepository.refreshToken({
|
const response = await AuthRepository.refreshToken({
|
||||||
token: localStorage.getItem("jwtToken"),
|
token: localStorage.getItem("jwtToken"),
|
||||||
refreshToken: refreshToken,
|
refreshToken: storedRefreshToken,
|
||||||
})
|
});
|
||||||
.then((response) => {
|
|
||||||
localStorage.setItem("jwtToken", response.data.token);
|
|
||||||
localStorage.setItem("refreshToken", response.data.refreshToken);
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Token refresh failed:", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
// api
|
localStorage.setItem("jwtToken", response.data.token);
|
||||||
|
localStorage.setItem("refreshToken", response.data.refreshToken);
|
||||||
|
return true;
|
||||||
|
// api
|
||||||
// .post("/api/auth/refresh-token", {
|
// .post("/api/auth/refresh-token", {
|
||||||
// token: localStorage.getItem("jwtToken"),
|
// token: localStorage.getItem("jwtToken"),
|
||||||
// refreshToken: refreshToken,
|
// refreshToken: refreshToken,
|
||||||
@ -92,8 +93,8 @@ const refreshToken = async () => {
|
|||||||
// }
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Token refresh failed:", error);
|
console.error("Token refresh failed:", error);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProtectedRoute;
|
export default ProtectedRoute;
|
||||||
|
@ -48,7 +48,7 @@ axiosClient.interceptors.response.use(
|
|||||||
"Connection refused. Please ensure the server is running."
|
"Connection refused. Please ensure the server is running."
|
||||||
);
|
);
|
||||||
|
|
||||||
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("1 - error fetching refresh token :", error);
|
console.log("1 - error fetching refresh token :", error);
|
||||||
} else {
|
} else {
|
||||||
@ -59,7 +59,7 @@ axiosClient.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
} else if (error.code === "ERR_NETWORK") {
|
} else if (error.code === "ERR_NETWORK") {
|
||||||
console.error("Network error: Unable to reach the server.");
|
console.error("Network error: Unable to reach the server.");
|
||||||
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("2 - error fetching refresh token :", error);
|
console.log("2 - error fetching refresh token :", error);
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ axiosClient.interceptors.response.use(
|
|||||||
} else if (error.code === "ECONNABORTED") {
|
} else if (error.code === "ECONNABORTED") {
|
||||||
console.error("Request timed out.");
|
console.error("Request timed out.");
|
||||||
|
|
||||||
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("3 - error fetching refresh token :", error);
|
console.log("3 - error fetching refresh token :", error);
|
||||||
} else {
|
} else {
|
||||||
@ -77,7 +77,7 @@ axiosClient.interceptors.response.use(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (error.response) {
|
} else if (error.response) {
|
||||||
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 {
|
} else {
|
||||||
@ -97,10 +97,14 @@ axiosClient.interceptors.response.use(
|
|||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
// Make a request to refresh the access token
|
// Make a request to refresh the access token
|
||||||
const response = await axiosClient.post("/api/Auth/refresh-token", {
|
const response = await axiosClient
|
||||||
token: localStorage.getItem("jwtToken"),
|
.post("/api/Auth/refresh-token", {
|
||||||
refreshToken,
|
token: localStorage.getItem("jwtToken"),
|
||||||
});
|
refreshToken,
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("7 - error fetching refresh token :", error);
|
||||||
|
});
|
||||||
|
|
||||||
const { token, refreshToken: newRefreshToken } = response.data.data;
|
const { token, refreshToken: newRefreshToken } = response.data.data;
|
||||||
localStorage.setItem("jwtToken", token);
|
localStorage.setItem("jwtToken", token);
|
||||||
@ -121,7 +125,7 @@ axiosClient.interceptors.response.use(
|
|||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
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("6 - error fetching refresh token :", error);
|
console.log("6 - error fetching refresh token :", error);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ export const getDateDifferenceInDays = (startDate, endDate) => {
|
|||||||
export const formatDate = (date) => {
|
export const formatDate = (date) => {
|
||||||
if (!date) return ""; // Return an empty string if no date
|
if (!date) return ""; // Return an empty string if no date
|
||||||
const dateObj = new Date(date);
|
const dateObj = new Date(date);
|
||||||
return dateObj.toISOString().split("T")[0]; // Get the date in YYYY-MM-DD format
|
// return dateObj.toISOString().split("T")[0];
|
||||||
|
return dateObj.toLocaleDateString('en-CA'); // Get the date in YYYY-MM-DD format
|
||||||
};
|
};
|
||||||
|
|
||||||
export const convertShortTime = (dateString) => {
|
export const convertShortTime = (dateString) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user