onSubmit={async (values, actions) => {
const { birthdate, ...userData } = values;
let formattedBirthDate = formatDate(birthdate);
const updateUserUrl = `/api/users/update/${id}`;
try {
// send a request to the API to update the source
const res = await api.patch(
updateUserUrl,
{
...userData,
birthdate: formattedBirthDate,
},
{ headers: { "Auth-Token": authToken } }
);
if (res && res.data) {
mutate('api/users?page=1&limit=10',{ ...user, userData, birthdate: formattedBirthDate });
router.replace("/admin?page=1&limit=10");
toast.success("Updated successfully");
}
} catch (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
toast.error(error.response.data.message);
console.log("Error response data: ", error.response.data);
console.log("Error response status: ", error.response.status);
console.log(
"Error response headers: ,",
error.response.headers
);
} else {
console.log("Error entity error: ", error.message);
toast.error(error.message);
}
}
I am trying to mutate the table data to have an updated data but it won't work if the mutate URL is not correct. If the current data fetch is from page 2, then the mutate URL will be api/users?page=2&limit=10. How can I know if the current data is from page =2?