1- import React , { useEffect , useState } from 'react' ;
1+ import React , { useEffect , useState , useMemo } from 'react' ;
22import { Link } from 'react-router-dom' ;
33import { useTranslation } from 'react-i18next' ;
44import { useAuth } from '../contexts/AuthContext' ;
55import Layout from '../components/Layout' ;
66import { LoadingSpinner , PageHeader } from '../components/shared' ;
77import { usersAPI } from '../api' ;
8+ import { getQuickActionsByRole } from '../config/quickActions' ;
89import {
9- QrCode ,
10- ClipboardList ,
11- Gift ,
12- Calendar ,
13- ArrowLeftRight ,
14- Target ,
15- CreditCard ,
16- CheckCircle ,
17- UserPlus ,
18- Users ,
19- BarChart3 ,
20- Tag ,
21- CalendarCog ,
2210 Coins ,
2311 ShieldCheck ,
2412 User ,
@@ -49,6 +37,16 @@ const DashboardPage = () => {
4937 fetchUserData ( ) ;
5038 } , [ updateUser ] ) ;
5139
40+ // Memoize quick actions based on role
41+ const quickActions = useMemo (
42+ ( ) => getQuickActionsByRole ( activeRole ) ,
43+ [ activeRole ]
44+ ) ;
45+
46+ const getRoleDisplayName = ( role ) => {
47+ return t ( `nav:roles.${ role } ` , { defaultValue : role } ) ;
48+ } ;
49+
5250 if ( loading ) {
5351 return (
5452 < Layout >
@@ -57,42 +55,6 @@ const DashboardPage = () => {
5755 ) ;
5856 }
5957
60- // Role-specific quick actions
61- const getQuickActions = ( ) => {
62- const baseActions = [
63- { to : '/my-qr' , icon : < QrCode size = { 24 } /> , text : t ( 'dashboard:quickActions.myQr' ) } ,
64- { to : '/transactions' , icon : < ClipboardList size = { 24 } /> , text : t ( 'dashboard:quickActions.myTransactions' ) } ,
65- { to : '/promotions' , icon : < Gift size = { 24 } /> , text : t ( 'dashboard:quickActions.promotions' ) } ,
66- { to : '/events' , icon : < Calendar size = { 24 } /> , text : t ( 'dashboard:quickActions.events' ) } ,
67- { to : '/transfer' , icon : < ArrowLeftRight size = { 24 } /> , text : t ( 'dashboard:quickActions.transfer' ) } ,
68- { to : '/redeem' , icon : < Target size = { 24 } /> , text : t ( 'dashboard:quickActions.redeem' ) } ,
69- ] ;
70-
71- const cashierActions = [
72- { to : '/cashier/transaction' , icon : < CreditCard size = { 24 } /> , text : t ( 'dashboard:quickActions.createTransaction' ) } ,
73- { to : '/cashier/redemption' , icon : < CheckCircle size = { 24 } /> , text : t ( 'dashboard:quickActions.processRedemption' ) } ,
74- { to : '/register' , icon : < UserPlus size = { 24 } /> , text : t ( 'dashboard:quickActions.registerUser' ) } ,
75- ] ;
76-
77- const managerActions = [
78- { to : '/users' , icon : < Users size = { 24 } /> , text : t ( 'dashboard:quickActions.manageUsers' ) } ,
79- { to : '/transactions/all' , icon : < BarChart3 size = { 24 } /> , text : t ( 'dashboard:quickActions.allTransactions' ) } ,
80- { to : '/promotions/manage' , icon : < Tag size = { 24 } /> , text : t ( 'dashboard:quickActions.managePromotions' ) } ,
81- { to : '/events/manage' , icon : < CalendarCog size = { 24 } /> , text : t ( 'dashboard:quickActions.manageEvents' ) } ,
82- ] ;
83-
84- if ( activeRole === 'superuser' || activeRole === 'manager' ) {
85- return [ ...baseActions , ...cashierActions , ...managerActions ] ;
86- } else if ( activeRole === 'cashier' ) {
87- return [ ...baseActions , ...cashierActions ] ;
88- }
89- return baseActions ;
90- } ;
91-
92- const getRoleDisplayName = ( role ) => {
93- return t ( `nav:roles.${ role } ` , { defaultValue : role } ) ;
94- } ;
95-
9658 return (
9759 < Layout >
9860 < div className = "dashboard-page" >
@@ -141,10 +103,10 @@ const DashboardPage = () => {
141103 < div className = "dashboard-quick-actions" >
142104 < h2 > { t ( 'dashboard:quickActions.title' ) } </ h2 >
143105 < div className = "quick-actions-grid" >
144- { getQuickActions ( ) . map ( ( action , index ) => (
145- < Link key = { index } to = { action . to } className = "quick-action-card" >
146- < span className = "action-icon" > { action . icon } </ span >
147- < span className = "action-text" > { action . text } </ span >
106+ { quickActions . map ( ( { to , Icon , i18nKey } ) => (
107+ < Link key = { to } to = { to } className = "quick-action-card" >
108+ < span className = "action-icon" > < Icon size = { 24 } /> </ span >
109+ < span className = "action-text" > { t ( i18nKey ) } </ span >
148110 </ Link >
149111 ) ) }
150112 </ div >
0 commit comments