add loan request/change structure and documentary/ making middle ware for user type/update breadcrumb

This commit is contained in:
2023-08-19 13:38:51 +03:30
parent dd239ac46c
commit fd1a6bcf2e
18 changed files with 382 additions and 156 deletions

View File

@@ -6,8 +6,11 @@ import useUser from "@/lib/app/hooks/useUser";
import {errorRequest, errorResponse, errorSetting} from "@/core/utils/errorHandler";
const defaultOptions = {
auth: false,
data: {},
requestOptions: {},
requestOptions: {
headers: {}
},
notification: true,
pending: true,
success: {
@@ -23,11 +26,19 @@ const defaultOptions = {
}
const useRequest = (initOptions) => {
const t = useTranslations()
const {clearToken} = useUser()
const {token, clearToken} = useUser()
let _options = {...defaultOptions, ...initOptions}
function requestServer(url = '', method = 'get', options) {
_options = {..._options, ...options}
if (_options.auth) _options = {
..._options,
requestOptions: {
..._options.requestOptions,
headers: {..._options.requestOptions.headers, authorization: `Bearer ${token}`}
}
}
return new Promise((resolve, reject) => {
if (_options.notification && _options.failed.notification.show && _options.pending) PendingNotification(t)
axios({