add sidebar update in action
This commit is contained in:
@@ -29,6 +29,7 @@ const RegisterAction = ({ rowId, mutate, mutateParentTable }) => {
|
|||||||
}
|
}
|
||||||
await requestServer(`${REGISTER_COMPLAINTS_LIST}/${rowId}`, "post", {
|
await requestServer(`${REGISTER_COMPLAINTS_LIST}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ const ReferContent = ({ rowId, mutate, setOpenReferDialog }) => {
|
|||||||
formData.append("refer_description", data.description);
|
formData.append("refer_description", data.description);
|
||||||
await requestServer(`${REFER_FAST_REACT}/${rowId}`, "post", {
|
await requestServer(`${REFER_FAST_REACT}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const EditController = ({ rowId, mutate, setOpenEditDialog }) => {
|
|||||||
|
|
||||||
await requestServer(`${UPDATE_FAST_REACT}/${rowId}`, "post", {
|
await requestServer(`${UPDATE_FAST_REACT}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const ConfirmContent = ({ rowId, mutate, setOpenConfirmDialog }) => {
|
|||||||
formData.append("verify", 1);
|
formData.append("verify", 1);
|
||||||
requestServer(`${VERIFY_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
|
requestServer(`${VERIFY_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const RejectContent = ({ rowId, mutate, setOpenRejectDialog }) => {
|
|||||||
formData.append("verify", 2);
|
formData.append("verify", 2);
|
||||||
requestServer(`${REJECT_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
|
requestServer(`${REJECT_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const RestoreContent = ({ rowId, mutate, setOpenRestoreDialog }) => {
|
|||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
requestServer(`${RESTORE_FAST_REACT}/${rowId}`, "post")
|
requestServer(`${RESTORE_FAST_REACT}/${rowId}`, "post", { hasSidebarUpdate: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenRestoreDialog(false);
|
setOpenRestoreDialog(false);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const OperatorCreateForm = ({ open, setOpen, mutate }) => {
|
|||||||
}
|
}
|
||||||
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ const CompleteItem = ({ subItem, itemInfo, setSubmitCompleteForm, mutate, setOpe
|
|||||||
|
|
||||||
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -69,14 +69,11 @@ const EditController = ({ rowId, mutate, setOpenEditDialog, openEditDialog, row
|
|||||||
for (const [key, value] of Object.entries(result)) {
|
for (const [key, value] of Object.entries(result)) {
|
||||||
formData.append(key, value);
|
formData.append(key, value);
|
||||||
}
|
}
|
||||||
await requestServer(
|
await requestServer(`${UPDATE_ROAD_ITEMS}/${rowId}`, "post", {
|
||||||
`${UPDATE_ROAD_ITEMS}/${rowId}`,
|
data: formData,
|
||||||
"post",
|
notificationSuccess: true,
|
||||||
{
|
hasSidebarUpdate: true,
|
||||||
data: formData,
|
})
|
||||||
},
|
|
||||||
{ notificationSuccess: true }
|
|
||||||
)
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenEditDialog(false);
|
setOpenEditDialog(false);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const ConfirmContent = ({ rowId, mutate, setOpenConfirmDialog }) => {
|
|||||||
formData.append("verify", 1);
|
formData.append("verify", 1);
|
||||||
requestServer(`${VERIFY_BY_SUPERVISOR}/${rowId}`, "post", {
|
requestServer(`${VERIFY_BY_SUPERVISOR}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
|
|||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
requestServer(`${DELETE_BY_SUPERVISOR}/${rowId}`, "post")
|
requestServer(`${DELETE_BY_SUPERVISOR}/${rowId}`, "post", {
|
||||||
|
hasSidebarUpdate: true,
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenDeleteDialog(false);
|
setOpenDeleteDialog(false);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const RejectContent = ({ rowId, mutate, setOpenRejectDialog }) => {
|
|||||||
formData.append("verify", 2);
|
formData.append("verify", 2);
|
||||||
await requestServer(`${REJECT_BY_SUPERVISOR}/${rowId}`, "post", {
|
await requestServer(`${REJECT_BY_SUPERVISOR}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ const RestoreContent = ({ rowId, mutate, setOpenRestoreDialog }) => {
|
|||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
requestServer(`${RESTORE_BY_SUPERVISOR}/${rowId}`, "post")
|
requestServer(`${RESTORE_BY_SUPERVISOR}/${rowId}`, "post", {
|
||||||
|
hasSidebarUpdate: true,
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenRestoreDialog(false);
|
setOpenRestoreDialog(false);
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ const CreateFormContent = ({ setOpen, mutate }) => {
|
|||||||
formData.append("point", startPoint);
|
formData.append("point", startPoint);
|
||||||
await requestServer(FIRST_STEP_STORE, "post", {
|
await requestServer(FIRST_STEP_STORE, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const StepThreeContent = ({ setOpen, mutate, rowId }) => {
|
|||||||
formData.append("action_picture", data.action_picture);
|
formData.append("action_picture", data.action_picture);
|
||||||
await requestServer(`${THIRD_STEP_STORE}/${rowId}`, "post", {
|
await requestServer(`${THIRD_STEP_STORE}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ const StepTwoContent = ({ setOpenStepTwoDialog, mutate, rowId }) => {
|
|||||||
data.judiciary_document.map((item, index) => formData.append(`judiciary_document[${index}]`, item));
|
data.judiciary_document.map((item, index) => formData.append(`judiciary_document[${index}]`, item));
|
||||||
await requestServer(`${SECOND_STEP_STORE}/${rowId}`, "post", {
|
await requestServer(`${SECOND_STEP_STORE}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
|
hasSidebarUpdate: true,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
mutate();
|
mutate();
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
|
|||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
requestServer(`${DELETE_SAFETY_AND_PRIVACY}/${rowId}`, "delete")
|
requestServer(`${DELETE_SAFETY_AND_PRIVACY}/${rowId}`, "delete", {
|
||||||
|
hasSidebarUpdate: true,
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenDeleteDialog(false);
|
setOpenDeleteDialog(false);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { errorResponse } from "@/core/utils/errorResponse";
|
|||||||
import { successRequest } from "@/core/utils/successRequest";
|
import { successRequest } from "@/core/utils/successRequest";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useAuth } from "../contexts/auth";
|
import { useAuth } from "../contexts/auth";
|
||||||
|
import { useSidebarBadge } from "./useSidebarBadge";
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
data: {},
|
data: {},
|
||||||
@@ -11,13 +12,22 @@ const defaultOptions = {
|
|||||||
notificationShow: true,
|
notificationShow: true,
|
||||||
notificationSuccess: false,
|
notificationSuccess: false,
|
||||||
notificationFailed: true,
|
notificationFailed: true,
|
||||||
|
hasSidebarUpdate: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const useRequest = (initOptions) => {
|
const useRequest = (initOptions) => {
|
||||||
|
const { mutate: sidebarUpdate } = useSidebarBadge();
|
||||||
const { logout } = useAuth();
|
const { logout } = useAuth();
|
||||||
|
|
||||||
const _options = Object.assign({}, defaultOptions, initOptions);
|
const _options = Object.assign({}, defaultOptions, initOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs an HTTP request.
|
||||||
|
* @param {string} url - The URL to send the request to.
|
||||||
|
* @param {'get' | 'post' | 'put' | 'delete'} [method='get'] - HTTP method.
|
||||||
|
* @param {object} [options] - Additional request options.
|
||||||
|
* @returns {Promise<AxiosResponse>} - Axios response.
|
||||||
|
*/
|
||||||
return async (url = "", method = "get", options) => {
|
return async (url = "", method = "get", options) => {
|
||||||
const mergedOptions = Object.assign({}, _options, options);
|
const mergedOptions = Object.assign({}, _options, options);
|
||||||
try {
|
try {
|
||||||
@@ -28,6 +38,9 @@ const useRequest = (initOptions) => {
|
|||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
...mergedOptions.requestOptions,
|
...mergedOptions.requestOptions,
|
||||||
});
|
});
|
||||||
|
if (mergedOptions.hasSidebarUpdate) {
|
||||||
|
if (method === "post" || method === "put" || method === "delete") sidebarUpdate();
|
||||||
|
}
|
||||||
successRequest(mergedOptions.notificationShow && mergedOptions.notificationSuccess, "request_data");
|
successRequest(mergedOptions.notificationShow && mergedOptions.notificationSuccess, "request_data");
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import { GET_SIDEBAR_BADGE_ROUTE } from "@/core/utils/routes";
|
import { GET_SIDEBAR_BADGE_ROUTE } from "@/core/utils/routes";
|
||||||
|
import axios from "axios";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import useRequest from "./useRequest";
|
|
||||||
|
|
||||||
export const useSidebarBadge = () => {
|
export const useSidebarBadge = () => {
|
||||||
const request = useRequest();
|
|
||||||
|
|
||||||
const fetcher = async (url) => {
|
const fetcher = async (url) => {
|
||||||
try {
|
try {
|
||||||
const response = await request(url);
|
const response = await axios({ url, method: "get", withCredentials: true });
|
||||||
return response.data.data;
|
return response.data.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return useSWR(GET_SIDEBAR_BADGE_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 10000 });
|
return useSWR(GET_SIDEBAR_BADGE_ROUTE, fetcher, { keepPreviousData: true, dedupingInterval: 30000 });
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user