refs #5655 useRole and useUserConfig independents
gitea/salix-front/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2023-05-11 14:51:12 +02:00
parent c4f40fbb59
commit e254a1e721
3 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,4 @@
import { useState } from './useState'; import { useState } from './useState';
import { useUserConfig } from './useUserConfig';
import axios from 'axios'; import axios from 'axios';
export function useRole() { export function useRole() {
@ -7,7 +6,6 @@ export function useRole() {
async function fetch() { async function fetch() {
const { data } = await axios.get('VnUsers/acl'); const { data } = await axios.get('VnUsers/acl');
const userConfig = await useUserConfig().fetch();
const roles = data.roles.map((userRoles) => userRoles.role.name); const roles = data.roles.map((userRoles) => userRoles.role.name);
const userData = { const userData = {
@ -15,7 +13,6 @@ export function useRole() {
name: data.user.name, name: data.user.name,
nickname: data.user.nickname, nickname: data.user.nickname,
lang: data.user.lang || 'es', lang: data.user.lang || 'es',
darkMode: userConfig.darkMode,
}; };
state.setUser(userData); state.setUser(userData);
state.setRoles(roles); state.setRoles(roles);

View File

@ -1,5 +1,7 @@
import { useState } from './useState'; import { useState } from './useState';
import { useRole } from './useRole'; import { useRole } from './useRole';
import { useUserConfig } from './useUserConfig';
export function useSession() { export function useSession() {
function getToken() { function getToken() {
@ -36,11 +38,10 @@ export function useSession() {
} }
async function login(token, keepLogin) { async function login(token, keepLogin) {
const { fetch } = useRole();
setToken({ token, keepLogin }); setToken({ token, keepLogin });
await fetch(); await useRole().fetch();
await useUserConfig().fetch();
} }
function isLoggedIn() { function isLoggedIn() {

View File

@ -1,10 +1,14 @@
import axios from 'axios'; import axios from 'axios';
import { useState } from './useState';
export function useUserConfig() { export function useUserConfig() {
const state = useState();
async function fetch() { async function fetch() {
const { data } = await axios.get('UserConfigs/getUserConfig'); const { data } = await axios.get('UserConfigs/getUserConfig');
return data; const user = state.getUser().value;
user.darkMode = data.darkMode;
state.setUser(user);
} }
return { return {