update remove fetch roles to optimize performance

This commit is contained in:
Wikzyy
2025-04-21 11:38:57 +07:00
parent 86910ca7a9
commit bc88364058

View File

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