revamp template
This commit is contained in:
37
src/actions/NavbarMenuActions.ts
Normal file
37
src/actions/NavbarMenuActions.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import axios from 'axios';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { ActionMenuReponseTypes, RoleList } from '@/types/GlobalTypes';
|
||||
const API_URL = apiConfig.service_user;
|
||||
|
||||
export async function doGetNavbarMenu(): Promise<ActionMenuReponseTypes> {
|
||||
try {
|
||||
const storedToken = localStorage.getItem('brillian-bri-tl-auth-v1=9.1.1');
|
||||
const token = storedToken ? JSON.parse(storedToken) : null;
|
||||
|
||||
if (!token) {
|
||||
throw new Error('No authentication token found');
|
||||
}
|
||||
|
||||
const response = await axios.put(`${API_URL}/renew_token/${token.refresh_token}/credit`);
|
||||
if (response.status !== 200 || !response.data.status) {
|
||||
throw new Error(response.data.message ?? 'Failed to fetch navbar menu');
|
||||
}
|
||||
|
||||
return {
|
||||
status: true,
|
||||
message: 'Successfully retrieved navbar menu',
|
||||
data: {
|
||||
role_name: response.data.data.role_name,
|
||||
roles_list: response.data.data.roles_list,
|
||||
token: response.data.data.token
|
||||
}
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching navbar menu:', error.message);
|
||||
return {
|
||||
status: false,
|
||||
message: error.message,
|
||||
data: null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user