clear cache after update or new create employee. and added character limitation for address and email

This commit is contained in:
Pramod Mahajan 2025-04-19 22:10:26 +05:30
parent 8d4c9e4f39
commit 37b74270cd

View File

@ -23,8 +23,10 @@ const ManageEmployee = () => {
employee,
error,
loading: empLoading,
} = useEmployeeProfile(employeeId);
dispatch(changeMaster("Job Role"));
} = useEmployeeProfile( employeeId );
dispatch( changeMaster( "Job Role" ) );
const [disabledEmail, setDisabledEmail] = useState(false);
const { data: job_role, loading } = useMaster();
const [isloading, setLoading] = useState(false);
@ -39,7 +41,7 @@ const ManageEmployee = () => {
MiddleName: z.string().optional(),
LastName: z.string().min(1, { message: "Last Name is required" }),
Email: z
.string()
.string().max(225,"Email cannot exceed 255 characters")
.optional()
.refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
message: "Invalid email format",
@ -59,7 +61,7 @@ const ManageEmployee = () => {
CurrentAddress: z
.string()
.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
.string()
.min(1, { message: "Birth Date is required" })
@ -111,7 +113,7 @@ const ManageEmployee = () => {
PermanentAddress: z
.string()
.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
.string()
.min(1, { message: "Phone Number is required" })
@ -150,7 +152,8 @@ const ManageEmployee = () => {
mode: "onChange",
});
const AadharNumberValue = watch("AadharNumber") || "";
const AadharNumberValue = watch( "AadharNumber" ) || "";
const onSubmit = (data) => {
setLoading(true);
@ -181,8 +184,11 @@ const ManageEmployee = () => {
.then((response) => {
showToast("Employee details updated successfully.", "success");
clearCacheKey("employeeListByProject");
clearCacheKey("allEmployeeList");
setLoading(false);
clearCacheKey( "allEmployeeList" );
clearCacheKey("employeeProfile")
setLoading( false );
reset()
navigation("/employees");
})
.catch((error) => {
@ -324,7 +330,7 @@ const ManageEmployee = () => {
{...register("Email")}
className="form-control form-control-sm"
placeholder="example@domain.com"
aria-label=""
maxLength={255}
aria-describedby="Email"
disabled={!!currentEmployee?.email}
/>
@ -438,15 +444,16 @@ const ManageEmployee = () => {
placeholder="Current Address"
aria-label="Current Address"
aria-describedby="basic-icon-default-message2"
{...register("CurrentAddress")}
{...register( "CurrentAddress" )}
maxLength={500}
onChange={(e) => {
setCurrentAddressLength(e.target.value.length);
// let react-hook-form still handle it
register("CurrentAddress").onChange(e);
}}
></textarea>
<div className="text-end small">
{500 - currentAddressLength} characters left
<div className="text-end muted">
<small> {500 - currentAddressLength} characters left</small>
</div>
{errors.CurrentAddress && (
<div
@ -468,14 +475,15 @@ const ManageEmployee = () => {
placeholder="Permanent Address"
aria-label="Permanent Address"
aria-describedby="basic-icon-default-message2"
{...register("PermanentAddress")}
{...register( "PermanentAddress" )}
maxLength={500}
onChange={(e) => {
setPermanentAddressLength(e.target.value.length);
register("PermanentAddress").onChange(e);
}}
></textarea>
<div className="text-end small">
{500 - permanentAddressLength} characters left
<div className="text-end muted">
<small>{500 - permanentAddressLength} characters left</small>
</div>
{errors.PermanentAddress && (
<div