revamp template
This commit is contained in:
57
src/actions/GlobalActions.ts
Normal file
57
src/actions/GlobalActions.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import axios from 'axios';
|
||||
import type { ActionResponseTypes } from 'src/types/GlobalTypes';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useCallApi } from '@/hooks';
|
||||
|
||||
interface SaveLogsParams {
|
||||
module: string;
|
||||
description: string;
|
||||
action: string;
|
||||
}
|
||||
|
||||
const API_URL = apiConfig.service_user;
|
||||
|
||||
const getCurrentTimeJakarta = () => {
|
||||
const jakartaTime = new Date().toLocaleString('id-ID', {
|
||||
timeZone: 'Asia/Jakarta',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
});
|
||||
|
||||
const [date, time] = jakartaTime.split(' ');
|
||||
const [day, month, year] = date.split('/');
|
||||
|
||||
return `${year}-${month}-${day} ${time}`;
|
||||
};
|
||||
|
||||
export async function doSaveLogActivity(payload: SaveLogsParams): Promise<ActionResponseTypes> {
|
||||
try {
|
||||
const token = JSON.parse(localStorage.getItem('brillian-bri-tl-auth-v1=9.1.1') || '{}');
|
||||
|
||||
const dtParams = {
|
||||
...payload,
|
||||
id_user: token.id,
|
||||
refresh_token: token.refresh_token,
|
||||
url: window.location.href,
|
||||
data_body: getCurrentTimeJakarta(),
|
||||
application: 'credit'
|
||||
};
|
||||
|
||||
const response = await axios.post(`${API_URL}/user_activity/create`, dtParams);
|
||||
|
||||
if (response.status !== 200 || !response.data.status) {
|
||||
throw new Error(response.data.message ?? 'Failed to save log');
|
||||
}
|
||||
|
||||
console.log('Success Create logs with params =>', dtParams);
|
||||
|
||||
return { status: true, message: 'Success logs users' };
|
||||
} catch (error: any) {
|
||||
console.error('Error saving log:', error.message);
|
||||
return { status: false, message: error.message };
|
||||
}
|
||||
}
|
||||
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