Optimized to avoid unnecessary API calls
This commit is contained in:
parent
8676ff24a5
commit
10ee3796d3
@ -28,6 +28,7 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
|
|||||||
employee,
|
employee,
|
||||||
error,
|
error,
|
||||||
loading: empLoading,
|
loading: empLoading,
|
||||||
|
refetch
|
||||||
} = useEmployeeProfile(employeeId);
|
} = useEmployeeProfile(employeeId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -129,7 +130,12 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
|
|||||||
.min(1, { message: "Phone Number is required" })
|
.min(1, { message: "Phone Number is required" })
|
||||||
.regex(mobileNumberRegex, { message: "Invalid phone number " }),
|
.regex(mobileNumberRegex, { message: "Invalid phone number " }),
|
||||||
jobRoleId: z.string().min(1, { message: "Role is required" }),
|
jobRoleId: z.string().min(1, { message: "Role is required" }),
|
||||||
});
|
} );
|
||||||
|
|
||||||
|
useEffect( () =>
|
||||||
|
{
|
||||||
|
refetch()
|
||||||
|
},[])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
|
@ -403,7 +403,7 @@ export const useCreateJobRole = (onSuccessCallback) => {
|
|||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
showToast("JobRole added successfully.", "success");
|
showToast("JobRole added successfully.", "success");
|
||||||
|
|
||||||
queryClient.invalidateQueries(["masterData", "Job Role"]);
|
queryClient.invalidateQueries({queryKey:["masterData", "Job Role"]});
|
||||||
|
|
||||||
if (onSuccessCallback) onSuccessCallback(data);
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
},
|
},
|
||||||
@ -427,7 +427,7 @@ export const useCreateApplicationRole = (onSuccessCallback) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries( [ "masterData", "Application Role" ] )
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Application Role" ]} )
|
||||||
showToast( "Application Role added successfully", "success" );
|
showToast( "Application Role added successfully", "success" );
|
||||||
if(onSuccessCallback) onSuccessCallback(data)
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
},
|
},
|
||||||
@ -476,7 +476,7 @@ export const useCreateActivity = (onSuccessCallback) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries( [ "masterData", "Activity" ] )
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Activity" ]} )
|
||||||
showToast( "Activity added successfully", "success" );
|
showToast( "Activity added successfully", "success" );
|
||||||
if(onSuccessCallback) onSuccessCallback(data)
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
},
|
},
|
||||||
@ -526,7 +526,7 @@ export const useCreateWorkCategory = (onSuccessCallback) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries( [ "masterData", "Work Category" ] )
|
queryClient.invalidateQueries({queryKey: [ "masterData", "Work Category" ]} )
|
||||||
showToast( "Work Category added successfully", "success" );
|
showToast( "Work Category added successfully", "success" );
|
||||||
if(onSuccessCallback) onSuccessCallback(data)
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
},
|
},
|
||||||
@ -577,7 +577,7 @@ export const useCreateContactCategory = (onSuccessCallback) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries( [ "masterData", "Contact Category" ] )
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Category" ]} )
|
||||||
showToast( "Contact Category added successfully", "success" );
|
showToast( "Contact Category added successfully", "success" );
|
||||||
if(onSuccessCallback) onSuccessCallback(data)
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
},
|
},
|
||||||
@ -628,7 +628,7 @@ export const useCreateContactTag = (onSuccessCallback) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries( [ "masterData", "Contact Tag" ] )
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Tag" ]} )
|
||||||
showToast( "Contact Tag added successfully", "success" );
|
showToast( "Contact Tag added successfully", "success" );
|
||||||
if(onSuccessCallback) onSuccessCallback(data)
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
},
|
},
|
||||||
|
@ -156,6 +156,7 @@ export const useEmployeeProfile = ( employeeId ) =>
|
|||||||
data = null,
|
data = null,
|
||||||
isLoading: loading,
|
isLoading: loading,
|
||||||
error,
|
error,
|
||||||
|
refetch
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['employeeProfile', employeeId],
|
queryKey: ['employeeProfile', employeeId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@ -170,6 +171,7 @@ export const useEmployeeProfile = ( employeeId ) =>
|
|||||||
employee: data,
|
employee: data,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
|
refetch
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user