update remove fetch roles to optimize performance
This commit is contained in:
@ -26,16 +26,8 @@ type CountType = 'sum' | 'count';
|
||||
type ChartType = 'line' | 'bar';
|
||||
type ChartLegend = 'true' | 'false';
|
||||
|
||||
type RoleType = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
const API_URL_DASHBOARD = apiConfig.service_dashboard;
|
||||
|
||||
const DashboardHomePage = () => {
|
||||
const selectYear = get5LastYear();
|
||||
const { GetData } = useCallApi();
|
||||
const [initialYear, setInitialYear] = useState<string>('');
|
||||
const [selectedYear, setSelectedYear] = useState<string>('');
|
||||
const [count, setCount] = useState<CountType>('sum');
|
||||
@ -45,31 +37,9 @@ const DashboardHomePage = () => {
|
||||
from: new Date(),
|
||||
to: new Date()
|
||||
});
|
||||
const [roles, setRoles] = useState<RoleType[]>([]);
|
||||
const parsedUser = getAuth()?.user;
|
||||
const idCustomer = parsedUser?.customer?.id;
|
||||
const roleCustomer = parsedUser.idRole;
|
||||
const currentRole = roles.find((role) => role.id === roleCustomer)?.name?.toLowerCase();
|
||||
console.log(currentRole);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchRoles(sorting: any) {
|
||||
try {
|
||||
const response = await GetData(`${API_URL_DASHBOARD}/user_role/list`, {
|
||||
limit: 100,
|
||||
page: 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
|
||||
});
|
||||
setRoles(response?.data.list);
|
||||
} catch (error) {
|
||||
console.error('Error fetching roles', error);
|
||||
}
|
||||
}
|
||||
|
||||
fetchRoles([{ id: 'name', desc: false }]);
|
||||
}, []);
|
||||
const currentRole = getAuth()?.role_name;
|
||||
const idCustomer = getAuth()?.user.customer?.id;
|
||||
// console.log(currentRole);
|
||||
|
||||
// Menyusun tanggal awal dan akhir berdasarkan selectedYear
|
||||
useEffect(() => {
|
||||
@ -182,7 +152,7 @@ const DashboardHomePage = () => {
|
||||
</Helmet>
|
||||
<Container>
|
||||
{/* Account Balance Cards */}
|
||||
{currentRole === 'escrow' || currentRole === 'master agent' ? (
|
||||
{currentRole === 'Escrow' || currentRole === 'Master Agent' ? (
|
||||
<div className="grid gap-5 lg:gap-7.5 mb-14 mt-7">
|
||||
<BalanceCard id={idCustomer} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user