feat: refactor role display with dynamic colors and capitalize
- Add helper function capitalizeFirstLetter for consistent formatting - Add helper function getRoleColor to determine tag color by role_level or role_name - Refactor role_name column render to use dynamic helpers - Replace 30+ lines of hardcoded conditions with 8 lines of clean code - Support any role name from database without code changes - Display role names with first letter capitalized - Color mapping: Level 1=purple, Level 2=blue, Level 3=cyan, Level 4=green - Add KeyOutlined icon import for change password feature
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
SearchOutlined,
|
||||
CheckOutlined,
|
||||
CloseOutlined,
|
||||
KeyOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../components/Global/ToastNotif';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
@@ -49,7 +50,7 @@ const getRoleColor = (role_name, role_level) => {
|
||||
return 'default';
|
||||
};
|
||||
|
||||
const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveDialog) => [
|
||||
const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveDialog, showChangePasswordModal) => [
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'user_id',
|
||||
@@ -135,7 +136,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveD
|
||||
title: 'Aksi',
|
||||
key: 'aksi',
|
||||
align: 'center',
|
||||
width: '15%',
|
||||
width: '18%',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button
|
||||
@@ -158,6 +159,12 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveD
|
||||
icon={<EditOutlined style={{ color: '#faad14' }} />}
|
||||
onClick={() => showEditModal(record)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
style={{ borderColor: '#722ed1' }}
|
||||
icon={<KeyOutlined style={{ color: '#722ed1' }} />}
|
||||
onClick={() => showChangePasswordModal(record)}
|
||||
/>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
@@ -255,6 +262,11 @@ const ListUser = memo(function ListUser(props) {
|
||||
});
|
||||
};
|
||||
|
||||
const showChangePasswordModal = (param) => {
|
||||
props.setSelectedUserForPassword(param);
|
||||
props.setShowChangePasswordModal(true);
|
||||
};
|
||||
|
||||
const handleApprove = async (user_id) => {
|
||||
const response = await approveUser(user_id);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -366,7 +378,8 @@ const ListUser = memo(function ListUser(props) {
|
||||
showPreviewModal,
|
||||
showEditModal,
|
||||
showDeleteDialog,
|
||||
showApproveDialog
|
||||
showApproveDialog,
|
||||
showChangePasswordModal
|
||||
)}
|
||||
triger={trigerFilter}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user