recode and add editor config file
This commit is contained in:
@@ -1,113 +1,113 @@
|
||||
import axios from "axios";
|
||||
import { useCallback, useContext, useReducer, useState } from "react";
|
||||
import { ReloadDataTableContext } from "../contexts/ReloadDatatableContext";
|
||||
import {useCallback, useContext, useReducer, useState} from "react";
|
||||
import {ReloadDataTableContext} from "../contexts/ReloadDatatableContext";
|
||||
import useUser from "./useUser";
|
||||
import Notifications from "@/core/components/notifications";
|
||||
import useDirection from "./useDirection";
|
||||
import { useTranslations } from "next-intl";
|
||||
import {useTranslations} from "next-intl";
|
||||
|
||||
const initialValues = {
|
||||
url: "",
|
||||
rowID: "",
|
||||
values: {},
|
||||
url: "",
|
||||
rowID: "",
|
||||
values: {},
|
||||
};
|
||||
|
||||
const reducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case "CONFIRM_DATA":
|
||||
return {
|
||||
...state,
|
||||
url: action.url,
|
||||
rowID: action.rowID,
|
||||
};
|
||||
case "REJECT_DATA":
|
||||
return {
|
||||
...state,
|
||||
url: action.url,
|
||||
rowID: action.rowID,
|
||||
values: {},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
switch (action.type) {
|
||||
case "CONFIRM_DATA":
|
||||
return {
|
||||
...state,
|
||||
url: action.url,
|
||||
rowID: action.rowID,
|
||||
};
|
||||
case "REJECT_DATA":
|
||||
return {
|
||||
...state,
|
||||
url: action.url,
|
||||
rowID: action.rowID,
|
||||
values: {},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
const useDataTable = () => {
|
||||
const { setReloadDataTable } = useContext(ReloadDataTableContext);
|
||||
const [state, dispatch] = useReducer(reducer, initialValues);
|
||||
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||
const [rowId, setRowId] = useState(null);
|
||||
const { directionApp } = useDirection();
|
||||
const t = useTranslations();
|
||||
const {setReloadDataTable} = useContext(ReloadDataTableContext);
|
||||
const [state, dispatch] = useReducer(reducer, initialValues);
|
||||
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||
const [rowId, setRowId] = useState(null);
|
||||
const {directionApp} = useDirection();
|
||||
const t = useTranslations();
|
||||
|
||||
const { token } = useUser();
|
||||
const {token} = useUser();
|
||||
|
||||
const confirmData = useCallback(async (url, rowID, values) => {
|
||||
dispatch({ type: "CONFIRM_DATA", url: url, rowID: rowID, values: values });
|
||||
axios
|
||||
.post(`${url}/${rowID}`, values, {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((response) => {
|
||||
setReloadDataTable(true);
|
||||
Notifications(directionApp, response, t);
|
||||
})
|
||||
.catch((error) => {
|
||||
Notifications(directionApp, error.response, t);
|
||||
});
|
||||
}, []);
|
||||
const confirmData = useCallback(async (url, rowID, values) => {
|
||||
dispatch({type: "CONFIRM_DATA", url: url, rowID: rowID, values: values});
|
||||
axios
|
||||
.post(`${url}/${rowID}`, values, {
|
||||
headers: {authorization: `Bearer ${token}`},
|
||||
})
|
||||
.then((response) => {
|
||||
setReloadDataTable(true);
|
||||
Notifications(directionApp, response, t);
|
||||
})
|
||||
.catch((error) => {
|
||||
Notifications(directionApp, error.response, t);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const rejectData = useCallback(async (url, rowID, values) => {
|
||||
dispatch({ type: "REJECT_DATA", url: url, rowID: rowID, values: values });
|
||||
axios
|
||||
.post(`${url}/${rowID}`, values, {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((response) => {
|
||||
setReloadDataTable(true);
|
||||
Notifications(directionApp, response, t);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
Notifications(directionApp, error.response, t);
|
||||
});
|
||||
}, []);
|
||||
const rejectData = useCallback(async (url, rowID, values) => {
|
||||
dispatch({type: "REJECT_DATA", url: url, rowID: rowID, values: values});
|
||||
axios
|
||||
.post(`${url}/${rowID}`, values, {
|
||||
headers: {authorization: `Bearer ${token}`},
|
||||
})
|
||||
.then((response) => {
|
||||
setReloadDataTable(true);
|
||||
Notifications(directionApp, response, t);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
Notifications(directionApp, error.response, t);
|
||||
});
|
||||
}, []);
|
||||
|
||||
//Confirm Data
|
||||
const handleOpenConfirmDialog = (row) => {
|
||||
setRowId(row.getValue("id"));
|
||||
setOpenConfirmDialog(true);
|
||||
};
|
||||
//Confirm Data
|
||||
const handleOpenConfirmDialog = (row) => {
|
||||
setRowId(row.getValue("id"));
|
||||
setOpenConfirmDialog(true);
|
||||
};
|
||||
|
||||
const handleCloseConfirmDialog = () => {
|
||||
setOpenConfirmDialog(false);
|
||||
};
|
||||
//End Confirm Data
|
||||
const handleCloseConfirmDialog = () => {
|
||||
setOpenConfirmDialog(false);
|
||||
};
|
||||
//End Confirm Data
|
||||
|
||||
// Reject Data
|
||||
const handleOpenRejectDialog = (row) => {
|
||||
setRowId(row.getValue("id"));
|
||||
setOpenRejectDialog(true);
|
||||
};
|
||||
// Reject Data
|
||||
const handleOpenRejectDialog = (row) => {
|
||||
setRowId(row.getValue("id"));
|
||||
setOpenRejectDialog(true);
|
||||
};
|
||||
|
||||
const handleCloseRejectDialog = () => {
|
||||
setOpenRejectDialog(false);
|
||||
};
|
||||
// End Reject Data
|
||||
const handleCloseRejectDialog = () => {
|
||||
setOpenRejectDialog(false);
|
||||
};
|
||||
// End Reject Data
|
||||
|
||||
const contextValue = {
|
||||
handleOpenConfirmDialog,
|
||||
handleCloseConfirmDialog,
|
||||
handleOpenRejectDialog,
|
||||
handleCloseRejectDialog,
|
||||
rowId,
|
||||
openConfirmDialog,
|
||||
openRejectDialog,
|
||||
rejectData,
|
||||
confirmData,
|
||||
};
|
||||
return contextValue;
|
||||
const contextValue = {
|
||||
handleOpenConfirmDialog,
|
||||
handleCloseConfirmDialog,
|
||||
handleOpenRejectDialog,
|
||||
handleCloseRejectDialog,
|
||||
rowId,
|
||||
openConfirmDialog,
|
||||
openRejectDialog,
|
||||
rejectData,
|
||||
confirmData,
|
||||
};
|
||||
return contextValue;
|
||||
};
|
||||
|
||||
export default useDataTable;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { LanguageContext } from "../contexts/language";
|
||||
import {useContext} from "react";
|
||||
import {LanguageContext} from "../contexts/language";
|
||||
|
||||
const useDirection = () => {
|
||||
const { directionApp } = useContext(LanguageContext);
|
||||
const {directionApp} = useContext(LanguageContext);
|
||||
|
||||
return { directionApp };
|
||||
return {directionApp};
|
||||
};
|
||||
|
||||
export default useDirection;
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { useContext } from "react";
|
||||
import { LanguageContext } from "../contexts/language";
|
||||
import {useContext} from "react";
|
||||
import {LanguageContext} from "../contexts/language";
|
||||
import useUser from "./useUser";
|
||||
|
||||
const useLanguage = () => {
|
||||
const { isAuth, changeUserLanguage } = useUser();
|
||||
const {
|
||||
languageApp,
|
||||
setLanguageApp,
|
||||
languageIsReady,
|
||||
setLanguageIsReady,
|
||||
languageList,
|
||||
} = useContext(LanguageContext);
|
||||
const {isAuth, changeUserLanguage} = useUser();
|
||||
const {
|
||||
languageApp,
|
||||
setLanguageApp,
|
||||
languageIsReady,
|
||||
setLanguageIsReady,
|
||||
languageList,
|
||||
} = useContext(LanguageContext);
|
||||
|
||||
const changeLanguage = (lang) => {
|
||||
if (lang == languageApp) return;
|
||||
const changeLanguage = (lang) => {
|
||||
if (lang == languageApp) return;
|
||||
|
||||
setLanguageIsReady(false);
|
||||
setLanguageApp(lang);
|
||||
if (isAuth) {
|
||||
changeUserLanguage(lang);
|
||||
}
|
||||
};
|
||||
setLanguageIsReady(false);
|
||||
setLanguageApp(lang);
|
||||
if (isAuth) {
|
||||
changeUserLanguage(lang);
|
||||
}
|
||||
};
|
||||
|
||||
return { languageApp, changeLanguage, languageIsReady, languageList };
|
||||
return {languageApp, changeLanguage, languageIsReady, languageList};
|
||||
};
|
||||
|
||||
export default useLanguage;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { LoadingContext } from "../contexts/loading";
|
||||
import {useContext} from "react";
|
||||
import {LoadingContext} from "../contexts/loading";
|
||||
|
||||
const useLoading = () => {
|
||||
const { setLoadingPage } = useContext(LoadingContext);
|
||||
const {setLoadingPage} = useContext(LoadingContext);
|
||||
|
||||
return { setLoadingPage };
|
||||
return {setLoadingPage};
|
||||
};
|
||||
|
||||
export default useLoading;
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
import { useContext } from "react";
|
||||
import { UserContext } from "../contexts/user";
|
||||
import {useContext} from "react";
|
||||
import {UserContext} from "../contexts/user";
|
||||
|
||||
const useUser = () => {
|
||||
const {
|
||||
isAuth,
|
||||
userChangedLanguage,
|
||||
token,
|
||||
user,
|
||||
getUser,
|
||||
clearUser,
|
||||
changeUser,
|
||||
changeAuthState,
|
||||
changeLanguageState,
|
||||
clearToken,
|
||||
setToken,
|
||||
} = useContext(UserContext);
|
||||
const {
|
||||
isAuth,
|
||||
userChangedLanguage,
|
||||
token,
|
||||
user,
|
||||
getUser,
|
||||
clearUser,
|
||||
changeUser,
|
||||
changeAuthState,
|
||||
changeLanguageState,
|
||||
clearToken,
|
||||
setToken,
|
||||
} = useContext(UserContext);
|
||||
|
||||
return {
|
||||
isAuth,
|
||||
userChangedLanguage,
|
||||
token,
|
||||
user,
|
||||
getUser,
|
||||
clearUser,
|
||||
changeUser,
|
||||
changeAuthState,
|
||||
changeLanguageState,
|
||||
clearToken,
|
||||
setToken,
|
||||
};
|
||||
return {
|
||||
isAuth,
|
||||
userChangedLanguage,
|
||||
token,
|
||||
user,
|
||||
getUser,
|
||||
clearUser,
|
||||
changeUser,
|
||||
changeAuthState,
|
||||
changeLanguageState,
|
||||
clearToken,
|
||||
setToken,
|
||||
};
|
||||
};
|
||||
|
||||
export default useUser;
|
||||
|
||||
Reference in New Issue
Block a user