update handle reject & is_active

This commit is contained in:
2025-10-16 11:30:00 +07:00
parent 77a89489cd
commit 172e14e77d
3 changed files with 84 additions and 27 deletions

View File

@@ -169,6 +169,22 @@ const rejectUser = async (user_id) => {
}; };
}; };
const toggleActiveUser = async (user_id, is_active) => {
const response = await SendRequest({
method: 'put',
prefix: `user/${user_id}`,
params: {
is_active: is_active
},
});
// Return full response with statusCode
return {
statusCode: response.statusCode || 200,
data: response.data,
message: response.message
};
};
const changePassword = async (user_id, new_password) => { const changePassword = async (user_id, new_password) => {
const response = await SendRequest({ const response = await SendRequest({
method: 'put', method: 'put',
@@ -188,4 +204,4 @@ const changePassword = async (user_id, new_password) => {
}; };
}; };
export { getAllUser, getUserById, createUser, updateUser, deleteUser, approveUser, rejectUser, changePassword }; export { getAllUser, getUserById, createUser, updateUser, deleteUser, approveUser, rejectUser, toggleActiveUser, changePassword };

View File

@@ -219,6 +219,8 @@ const DetailUser = (props) => {
if (FormData.user_email !== originalEmail) { if (FormData.user_email !== originalEmail) {
payload.user_email = FormData.user_email; payload.user_email = FormData.user_email;
} }
// Add is_active for update mode
payload.is_active = FormData.is_active;
} else { } else {
// For create mode: always send email // For create mode: always send email
payload.user_email = FormData.user_email; payload.user_email = FormData.user_email;
@@ -233,11 +235,11 @@ const DetailUser = (props) => {
if (!FormData.user_id) { if (!FormData.user_id) {
payload.user_name = FormData.user_name; // Username only for create payload.user_name = FormData.user_name; // Username only for create
payload.user_password = FormData.password; // Backend expects 'user_password' payload.user_password = FormData.password; // Backend expects 'user_password'
// Don't send confirmPassword, is_sa, is_active for create // Don't send confirmPassword, is_sa for create
} }
// For update mode: // For update mode:
// - Don't send 'user_name' (username is immutable) // - Don't send 'user_name' (username is immutable)
// - Don't send 'is_active' (backend validation schema doesn't allow it) // - is_active is now sent for update mode
// - Only send email if it has changed // - Only send email if it has changed
try { try {

View File

@@ -115,18 +115,10 @@ const columns = (
align: 'center', align: 'center',
render: (_, record) => { render: (_, record) => {
// is_approve: 0 = Rejected, 1 = Pending, 2 = Approved // is_approve: 0 = Rejected, 1 = Pending, 2 = Approved
if (record.is_approve === 1) { if (record.is_approve === 1 || record.is_approve === '1') {
// Pending - show both Approve and Reject buttons // Pending - show both Approve and Reject buttons
return ( return (
<Space size="small"> <Space size="small" direction="vertical">
<Button
danger
size="small"
icon={<CloseOutlined />}
onClick={() => showRejectDialog(record)}
>
Reject
</Button>
<Button <Button
type="primary" type="primary"
size="small" size="small"
@@ -135,35 +127,38 @@ const columns = (
style={{ style={{
backgroundColor: '#52c41a', backgroundColor: '#52c41a',
borderColor: '#52c41a', borderColor: '#52c41a',
width: '100%',
}} }}
> >
Approve Approve
</Button> </Button>
<Button
danger
size="small"
icon={<CloseOutlined />}
onClick={() => showRejectDialog(record)}
style={{ width: '100%' }}
>
Reject
</Button>
</Space> </Space>
); );
} else if (record.is_approve === 0) { } else if (record.is_approve === 0 || record.is_approve === '0') {
// Rejected // Rejected
return ( return (
<Tag color={'red'} key={'status'}> <Tag color={'red'} key={'status'}>
Rejected Rejected
</Tag> </Tag>
); );
} else if (record.is_approve === 2) { } else if (record.is_approve === 2 || record.is_approve === '2' || record.is_approve === true) {
// Approved - check active/inactive status // Approved
if (record.is_active === true || record.is_active === 1) {
return ( return (
<Tag color={'green'} key={'status'}> <Tag color={'green'} key={'status'}>
Active Approved
</Tag> </Tag>
); );
} }
return ( // Default fallback (for false/null which means pending in old system)
<Tag color={'default'} key={'status'}>
Inactive
</Tag>
);
}
// Default fallback
return ( return (
<Tag color={'orange'} key={'status'}> <Tag color={'orange'} key={'status'}>
Pending Pending
@@ -171,6 +166,31 @@ const columns = (
); );
}, },
}, },
{
title: 'Status Active',
dataIndex: 'is_active',
key: 'is_active',
width: '10%',
align: 'center',
render: (_, record) => {
// Only show active status if user is approved
if (record.is_approve === 2 || record.is_approve === '2' || record.is_approve === true) {
if (record.is_active === true || record.is_active === 1) {
return (
<Tag color={'green'} key={'active'}>
Active
</Tag>
);
}
return (
<Tag color={'default'} key={'inactive'}>
Inactive
</Tag>
);
}
return <span>-</span>;
},
},
{ {
title: 'Aksi', title: 'Aksi',
key: 'aksi', key: 'aksi',
@@ -325,6 +345,24 @@ const ListUser = memo(function ListUser(props) {
} }
}; };
const handleReject = async (user_id) => {
const response = await rejectUser(user_id);
if (response.statusCode == 200) {
NotifAlert({
icon: 'success',
title: 'Berhasil',
message: 'User berhasil direject.',
});
doFilter();
} else {
NotifOk({
icon: 'error',
title: 'Gagal',
message: 'Gagal Reject User',
});
}
};
const handleDelete = async (user_id, user_fullname) => { const handleDelete = async (user_id, user_fullname) => {
const response = await deleteUser(user_id); const response = await deleteUser(user_id);
@@ -418,7 +456,8 @@ const ListUser = memo(function ListUser(props) {
showPreviewModal, showPreviewModal,
showEditModal, showEditModal,
showDeleteDialog, showDeleteDialog,
showApproveDialog showApproveDialog,
showRejectDialog
)} )}
triger={trigerFilter} triger={trigerFilter}
/> />