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 ChartType = 'line' | 'bar';
|
||||||
type ChartLegend = 'true' | 'false';
|
type ChartLegend = 'true' | 'false';
|
||||||
|
|
||||||
type RoleType = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const API_URL_DASHBOARD = apiConfig.service_dashboard;
|
|
||||||
|
|
||||||
const DashboardHomePage = () => {
|
const DashboardHomePage = () => {
|
||||||
const selectYear = get5LastYear();
|
const selectYear = get5LastYear();
|
||||||
const { GetData } = useCallApi();
|
|
||||||
const [initialYear, setInitialYear] = useState<string>('');
|
const [initialYear, setInitialYear] = useState<string>('');
|
||||||
const [selectedYear, setSelectedYear] = useState<string>('');
|
const [selectedYear, setSelectedYear] = useState<string>('');
|
||||||
const [count, setCount] = useState<CountType>('sum');
|
const [count, setCount] = useState<CountType>('sum');
|
||||||
@ -45,31 +37,9 @@ const DashboardHomePage = () => {
|
|||||||
from: new Date(),
|
from: new Date(),
|
||||||
to: new Date()
|
to: new Date()
|
||||||
});
|
});
|
||||||
const [roles, setRoles] = useState<RoleType[]>([]);
|
const currentRole = getAuth()?.role_name;
|
||||||
const parsedUser = getAuth()?.user;
|
const idCustomer = getAuth()?.user.customer?.id;
|
||||||
const idCustomer = parsedUser?.customer?.id;
|
// console.log(currentRole);
|
||||||
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 }]);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Menyusun tanggal awal dan akhir berdasarkan selectedYear
|
// Menyusun tanggal awal dan akhir berdasarkan selectedYear
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -182,7 +152,7 @@ const DashboardHomePage = () => {
|
|||||||
</Helmet>
|
</Helmet>
|
||||||
<Container>
|
<Container>
|
||||||
{/* Account Balance Cards */}
|
{/* 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">
|
<div className="grid gap-5 lg:gap-7.5 mb-14 mt-7">
|
||||||
<BalanceCard id={idCustomer} />
|
<BalanceCard id={idCustomer} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user