2023-05-11 06:55:34 +00:00
|
|
|
import axios from 'axios';
|
2023-05-11 12:51:12 +00:00
|
|
|
import { useState } from './useState';
|
2023-12-13 13:19:42 +00:00
|
|
|
import useNotify from './useNotify';
|
2023-05-11 06:55:34 +00:00
|
|
|
|
|
|
|
export function useUserConfig() {
|
2023-05-11 12:51:12 +00:00
|
|
|
const state = useState();
|
2023-12-13 13:19:42 +00:00
|
|
|
const { notify } = useNotify();
|
2023-05-11 06:55:34 +00:00
|
|
|
|
|
|
|
async function fetch() {
|
2023-12-13 13:19:42 +00:00
|
|
|
try {
|
|
|
|
const { data } = await axios.get('UserConfigs/getUserConfig');
|
|
|
|
const user = state.getUser().value;
|
|
|
|
user.darkMode = data.darkMode;
|
|
|
|
user.companyFk = data.companyFk;
|
2024-01-26 19:36:27 +00:00
|
|
|
user.warehouseFk = data.warehouseFk;
|
2023-12-13 13:19:42 +00:00
|
|
|
state.setUser(user);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
} catch (error) {
|
2024-01-03 06:47:38 +00:00
|
|
|
notify('errors.userConfig', 'negative');
|
2023-12-13 13:19:42 +00:00
|
|
|
console.error('Error fetching user config:', error);
|
|
|
|
}
|
2023-05-11 06:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fetch,
|
|
|
|
};
|
|
|
|
}
|