fix warnings and notifications

This commit is contained in:
grimhilt
2023-08-07 16:08:23 +02:00
parent fc942db1a1
commit 14b4f766c0
21 changed files with 191 additions and 32561 deletions

View File

@@ -3,15 +3,24 @@ import API from '../services/api';
const AuthContext = createContext();
const getUserFromStorage = () => {
const user = localStorage.getItem('user');
if (user) {
return JSON.parse(user);
} else {
return;
}
};
const AuthProvider = ({ children }) => {
const [user, setUser] = useState(localStorage.getItem('user'));
const [user, setUser] = useState(getUserFromStorage());
return <AuthContext.Provider value={{ user, setUser }}>{children}</AuthContext.Provider>;
};
const logout = () => {
localStorage.removeItem('user');
window.location.href = '/auth';
window.location.href = '/login';
API.logout();
};

View File

@@ -9,9 +9,26 @@ export const Perm = {
EDIT_PLAYLIST: 4,
};
const GrantAccess = ({ roles, children }) => {
const checkPerm = (perm, user) => {
console.log(user);
switch (perm) {
case Perm.CREATE_ROLE:
return false;
case Perm.CREATE_PLAYLIST:
return user.roles.findIndex((role) => role.can_create_playlist) !== -1;
default:
return false;
}
};
const GrantAccess = ({ role, roles, children }) => {
const { user } = useAuth();
return roles.includes(user) ? children : null;
if (role && checkPerm(role, user)) {
return children;
} else if (roles && roles.includes(user)) {
return children;
}
return null;
};
export const LoginRequired = ({ children }) => {

View File

@@ -4,13 +4,13 @@ export const parseTime = (preparationTime) => {
res += hours > 0 ? `${hours}h` : '';
let min = Math.floor((preparationTime % 3600) / 60);
if (min > 0 && res != '') res += ' ';
if (min > 0 && res !== '') res += ' ';
res += min > 0 ? `${min}m` : '';
let sec = Math.floor((preparationTime % 3600) % 60);
if (sec > 0 && res != '') res += ' ';
if (sec > 0 && res !== '') res += ' ';
res += sec > 0 ? `${sec}s` : '';
if (res == '') res = '0s';
if (res === '') res = '0s';
return res;
};