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:
2025-10-10 15:44:46 +07:00
parent 59c90c3519
commit c3b5ec2121

View File

@@ -8,6 +8,7 @@ import {
SearchOutlined, SearchOutlined,
CheckOutlined, CheckOutlined,
CloseOutlined, CloseOutlined,
KeyOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../components/Global/ToastNotif'; import { NotifAlert, NotifOk, NotifConfirmDialog } from '../../../components/Global/ToastNotif';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
@@ -49,7 +50,7 @@ const getRoleColor = (role_name, role_level) => {
return 'default'; return 'default';
}; };
const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveDialog) => [ const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveDialog, showChangePasswordModal) => [
{ {
title: 'ID', title: 'ID',
dataIndex: 'user_id', dataIndex: 'user_id',
@@ -135,7 +136,7 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveD
title: 'Aksi', title: 'Aksi',
key: 'aksi', key: 'aksi',
align: 'center', align: 'center',
width: '15%', width: '18%',
render: (_, record) => ( render: (_, record) => (
<Space> <Space>
<Button <Button
@@ -158,6 +159,12 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog, showApproveD
icon={<EditOutlined style={{ color: '#faad14' }} />} icon={<EditOutlined style={{ color: '#faad14' }} />}
onClick={() => showEditModal(record)} onClick={() => showEditModal(record)}
/> />
<Button
type="text"
style={{ borderColor: '#722ed1' }}
icon={<KeyOutlined style={{ color: '#722ed1' }} />}
onClick={() => showChangePasswordModal(record)}
/>
<Button <Button
type="text" type="text"
danger 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 handleApprove = async (user_id) => {
const response = await approveUser(user_id); const response = await approveUser(user_id);
if (response.statusCode == 200) { if (response.statusCode == 200) {
@@ -366,7 +378,8 @@ const ListUser = memo(function ListUser(props) {
showPreviewModal, showPreviewModal,
showEditModal, showEditModal,
showDeleteDialog, showDeleteDialog,
showApproveDialog showApproveDialog,
showChangePasswordModal
)} )}
triger={trigerFilter} triger={trigerFilter}
/> />