update page dashboard conditional for cards bank and transaction detail

This commit is contained in:
wayanrivan
2025-05-20 13:53:52 +07:00
parent faae04cea7
commit 189a545084
4 changed files with 152 additions and 120 deletions

View File

@ -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,