update page dashboard conditional for cards bank and transaction detail
This commit is contained in:
@ -43,24 +43,6 @@ const AuthProvider = ({ children }: PropsWithChildren) => {
|
||||
const [auth, setAuth] = useState<AuthModel | undefined>(authHelper.getAuth());
|
||||
const [currentUser, setCurrentUser] = useState<UserModel | undefined>();
|
||||
|
||||
const verify = async () => {
|
||||
if (auth) {
|
||||
try {
|
||||
const { data: user } = await getUser();
|
||||
const createCacheUser = {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
username: user.username,
|
||||
role_name: auth.role_name
|
||||
};
|
||||
localStorage.setItem('user', JSON.stringify(createCacheUser));
|
||||
} catch {
|
||||
saveAuth(undefined);
|
||||
setCurrentUser(undefined);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const saveAuth = (auth: AuthModel | undefined) => {
|
||||
setAuth(auth);
|
||||
if (auth) {
|
||||
@ -73,11 +55,20 @@ const AuthProvider = ({ children }: PropsWithChildren) => {
|
||||
const login = async (username: string, password: string) => {
|
||||
try {
|
||||
const { data: auth } = await axios
|
||||
.post(LOGIN_URL, { username, password }) // , { headers: { 'Access-Control-Allow-Origin': "*" }}
|
||||
.post(LOGIN_URL, { username, password })
|
||||
.then((response) => response.data);
|
||||
|
||||
saveAuth({ ...auth.token, id: auth.user.id, role_name: auth.role_name, user: auth.user });
|
||||
const enhancedAuth: AuthModel = {
|
||||
...auth.token,
|
||||
id: auth.user.id,
|
||||
role_name: auth.role_name,
|
||||
user: auth.user,
|
||||
statusbalance: auth.role.status_balance
|
||||
};
|
||||
|
||||
saveAuth(enhancedAuth);
|
||||
setCurrentUser(auth.user);
|
||||
|
||||
const createActivity = {
|
||||
module: 'Login',
|
||||
description: `Login`,
|
||||
@ -108,6 +99,33 @@ const AuthProvider = ({ children }: PropsWithChildren) => {
|
||||
return { data: _axios };
|
||||
};
|
||||
|
||||
const verify = async () => {
|
||||
if (auth) {
|
||||
try {
|
||||
const { data: user } = await getUser();
|
||||
|
||||
// Perbarui auth yang sekarang dengan statusbalance
|
||||
saveAuth({
|
||||
...auth,
|
||||
statusbalance: user.role.status_balance
|
||||
});
|
||||
|
||||
const createCacheUser = {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
username: user.username,
|
||||
role_name: auth.role_name,
|
||||
statusbalance: user.role.status_balance
|
||||
};
|
||||
|
||||
localStorage.setItem('user', JSON.stringify(createCacheUser));
|
||||
} catch {
|
||||
saveAuth(undefined);
|
||||
setCurrentUser(undefined);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
const createActivity = {
|
||||
module: 'Logout',
|
||||
@ -130,7 +148,6 @@ const AuthProvider = ({ children }: PropsWithChildren) => {
|
||||
currentUser,
|
||||
setCurrentUser,
|
||||
login,
|
||||
// register,
|
||||
requestPasswordResetLink,
|
||||
changePassword,
|
||||
getUser,
|
||||
|
||||
Reference in New Issue
Block a user