skip search member
This commit is contained in:
@ -56,38 +56,48 @@ const DetailMember = () => {
|
||||
msg: 'Active',
|
||||
btn: 'Block PIN',
|
||||
canBlock: true,
|
||||
variant: 'destructive' as const
|
||||
canUnblock: false,
|
||||
variant: 'destructive' as const,
|
||||
showField: false
|
||||
};
|
||||
if (status === 'N')
|
||||
return {
|
||||
msg: 'Not Active',
|
||||
btn: 'PIN Not Active',
|
||||
canBlock: false,
|
||||
variant: 'secondary' as const
|
||||
canUnblock: false,
|
||||
variant: 'secondary' as const,
|
||||
showField: true
|
||||
};
|
||||
if (status === 'P')
|
||||
return {
|
||||
msg: 'Suspend PIN',
|
||||
btn: 'PIN Blocked',
|
||||
btn: 'Unblock PIN',
|
||||
canBlock: false,
|
||||
variant: 'secondary' as const
|
||||
canUnblock: true,
|
||||
variant: 'default' as const,
|
||||
showField: true
|
||||
};
|
||||
if (status === 'O')
|
||||
return {
|
||||
msg: 'Suspend OTP',
|
||||
btn: 'OTP Blocked',
|
||||
btn: 'Unblock OTP',
|
||||
canBlock: false,
|
||||
variant: 'secondary' as const
|
||||
canUnblock: true,
|
||||
variant: 'default' as const,
|
||||
showField: true
|
||||
};
|
||||
return {
|
||||
msg: 'Unknown Status',
|
||||
btn: 'Unknown',
|
||||
canBlock: false,
|
||||
variant: 'secondary' as const
|
||||
canUnblock: false,
|
||||
variant: 'secondary' as const,
|
||||
showField: true
|
||||
};
|
||||
};
|
||||
|
||||
const handleBlockPin = async () => {
|
||||
const handleUnblockPin = async () => {
|
||||
if (!selectedCustomerData?.id) {
|
||||
toast.error('Customer data not available');
|
||||
return;
|
||||
@ -97,10 +107,10 @@ const DetailMember = () => {
|
||||
setIsUpdating(true);
|
||||
await axios.put(`${BASE_URL_CUSTOMER}/customer/statuspin`, {
|
||||
customerid: selectedCustomerData.id,
|
||||
status: 'Block'
|
||||
status: 'UnBlock'
|
||||
});
|
||||
|
||||
toast.success('PIN successfully blocked');
|
||||
toast.success('PIN successfully unblocked');
|
||||
|
||||
handleEditDialog(false, null);
|
||||
|
||||
@ -109,7 +119,7 @@ const DetailMember = () => {
|
||||
}, 500);
|
||||
|
||||
} catch (error: any) {
|
||||
toast.error(error.message || 'Failed to block PIN');
|
||||
toast.error(error.message || 'Failed to unblock PIN');
|
||||
} finally {
|
||||
setIsUpdating(false);
|
||||
setConfirmDialog(false);
|
||||
@ -203,6 +213,10 @@ const DetailMember = () => {
|
||||
const generatePinStatusField = (label: string, status: string) => {
|
||||
const pinStatus = getPinStatus(status);
|
||||
|
||||
if (!pinStatus.showField) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
@ -211,17 +225,17 @@ const DetailMember = () => {
|
||||
</label>
|
||||
<div className="flex-1 flex items-center gap-3 p-3 border border-gray-300 rounded-md bg-gray-50">
|
||||
<span className="text-gray-900 flex-1">{pinStatus.msg}</span>
|
||||
{pinStatus.canBlock && (
|
||||
{pinStatus.canUnblock && (
|
||||
<Button
|
||||
variant={pinStatus.variant}
|
||||
size="sm"
|
||||
onClick={() => setConfirmDialog(true)}
|
||||
disabled={isUpdating}
|
||||
>
|
||||
{isUpdating ? 'Blocking...' : pinStatus.btn}
|
||||
{isUpdating ? 'Unblocking...' : pinStatus.btn}
|
||||
</Button>
|
||||
)}
|
||||
{!pinStatus.canBlock && (
|
||||
{!pinStatus.canUnblock && !pinStatus.canBlock && (
|
||||
<Button
|
||||
variant={pinStatus.variant}
|
||||
size="sm"
|
||||
@ -279,12 +293,12 @@ const DetailMember = () => {
|
||||
{generateInput('Address', 'address', selectedCustomerData.address, 'text', true)}
|
||||
|
||||
{/* Location Information */}
|
||||
{generateInput('Profession', 'profession', selectedCustomerData.profession)}
|
||||
{generateInput('Municipio', 'municipio_name', selectedCustomerData.municipio_name)}
|
||||
{generateInput('Posto', 'posto_adms_name', selectedCustomerData.posto_adms_name)}
|
||||
{generateInput('Suco', 'suco_name', selectedCustomerData.suco_name)}
|
||||
{generateInput('Aldeia', 'aldeia_name', selectedCustomerData.aldeia_name)}
|
||||
{generateInput('Nationality', 'nationality', selectedCustomerData.nationality, 'text', true)}
|
||||
{generateInput('Profession', 'profession', selectedCustomerData.profession)}
|
||||
{generateInput('Municipio', 'municipio_name', selectedCustomerData.municipio_name)}
|
||||
{generateInput('Posto', 'posto_adms_name', selectedCustomerData.posto_adms_name)}
|
||||
{generateInput('Suco', 'suco_name', selectedCustomerData.suco_name)}
|
||||
{generateInput('Aldeia', 'aldeia_name', selectedCustomerData.aldeia_name)}
|
||||
{generateInput('Nationality', 'nationality', selectedCustomerData.nationality, 'text', true)}
|
||||
{generateImage('Photo', 'photouser', selectedCustomerData.photouser)}
|
||||
<div className="bg-white space-y-6 col-span-1 md:col-span-2">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||
@ -324,7 +338,6 @@ const DetailMember = () => {
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||
{generatePinStatusField('PIN Status', selectedCustomerData.status || '')}
|
||||
{generateInput('Created Date', 'created_at', formatDate(selectedCustomerData.created_at))}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -343,8 +356,8 @@ const DetailMember = () => {
|
||||
<ConfirmDialog
|
||||
open={confirmDialog}
|
||||
onOpenChange={setConfirmDialog}
|
||||
content="Are you sure you want to block this customer's PIN? This action cannot be undone from this interface."
|
||||
onYes={handleBlockPin}
|
||||
content="Are you sure you want to unblock this customer's PIN?"
|
||||
onYes={handleUnblockPin}
|
||||
onNo={() => setConfirmDialog(false)}
|
||||
/>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user