add reset pin and suspend
This commit is contained in:
@ -7,7 +7,10 @@ import UploadFileIcon from "@mui/icons-material/UploadFile";
|
||||
import Divider from '@mui/material/Divider';
|
||||
import { initialMember } from "./Columns";
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import ConfirmDialog from '@/components/confirm';
|
||||
import { toast } from 'sonner';
|
||||
const BASE_URL_MASTER_DATA = apiConfig.service_master_data;
|
||||
const BASE_URL_CUSTOMER = apiConfig.service_customer;
|
||||
|
||||
const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStats, handleReject, page }: any) => {
|
||||
const [formData, setFormData] = useState(initialData || initialMember);
|
||||
@ -259,7 +262,7 @@ const CustomerDialog = ({ open, handleClose, handleSubmit, initialData, viewStat
|
||||
<TextField disabled={viewOnly} fullWidth margin="dense" label="Bank Account" name="bank_account" value={formData.bank_account} onChange={handleChange} />
|
||||
<TextField disabled={viewOnly} fullWidth margin="dense" label="iBank Number" name="ibank_number" value={formData.ibank_number} onChange={handleChange} />
|
||||
<Divider className="pt-7"/>
|
||||
{getAdmAccess(page)}
|
||||
{getAdmAccess(page, formData)}
|
||||
{
|
||||
page === 'kyc' ? (
|
||||
<>
|
||||
@ -324,7 +327,39 @@ function fileTextFile(label: string, value: any, name: string, handleChange: any
|
||||
)
|
||||
}
|
||||
|
||||
function getAdmAccess(page: string) {
|
||||
function getAdmAccess(page: string, data: any) {
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const [dialogType, setDialogType] = useState('');
|
||||
const handleYes = async () => {
|
||||
try {
|
||||
if (dialogType === "update status") {
|
||||
let statusNext = getPinStatus(data.status).res;
|
||||
if (statusNext) await axios.put(`${BASE_URL_CUSTOMER}/customer/statuspin`, { customerid: data.id, status: statusNext })
|
||||
else toast.error("Handle Active/Suspend only")
|
||||
toast.success("Success Update Status")
|
||||
}
|
||||
if (dialogType === "reset pin") {
|
||||
if (data.id) await axios.post(`${BASE_URL_CUSTOMER}/customer/resetpin`, { customerid: data.id })
|
||||
else throw({ message: 'data.id not found' })
|
||||
toast.success("Pin will send to customer MSISDN")
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.error(error.message)
|
||||
} finally {
|
||||
setDialogOpen(false)
|
||||
}
|
||||
}
|
||||
|
||||
function buttonStatus() {
|
||||
setDialogType('update status')
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
function buttonResetPin() {
|
||||
setDialogType('reset pin')
|
||||
setDialogOpen(true)
|
||||
}
|
||||
|
||||
if (page !== "kyc") {
|
||||
return (
|
||||
<Box p={3} boxShadow={3} borderRadius={2} bgcolor="white">
|
||||
@ -332,12 +367,12 @@ function getAdmAccess(page: string) {
|
||||
<Grid container spacing={3}>
|
||||
<Grid item xs={6} container direction="column" spacing={2}>
|
||||
<Grid item>
|
||||
<Typography variant="body2">Unblock PIN</Typography>
|
||||
<Button variant="contained" color="primary">Unblock PIN</Button>
|
||||
<Typography variant="body2">Pin Status : {getPinStatus(data.status).msg}</Typography>
|
||||
<Button onClick={() => buttonStatus()} variant="contained" color="primary">{getPinStatus(data.status).btn}</Button>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Typography variant="body2">Reset PIN</Typography>
|
||||
<Button variant="contained" color="primary">Reset PIN</Button>
|
||||
<Button onClick={() => buttonResetPin()} variant="contained" color="primary">Reset PIN</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid item xs={6} container direction="column" spacing={2}>
|
||||
@ -351,9 +386,45 @@ function getAdmAccess(page: string) {
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<ConfirmDialog
|
||||
open={dialogOpen}
|
||||
onClose={() => setDialogOpen(false)}
|
||||
title="Confirm Action"
|
||||
content={`Are you sure you want to ${dialogType}?`}
|
||||
onYes={handleYes}
|
||||
onNo={() => setDialogOpen(false)}
|
||||
/>
|
||||
</Box>
|
||||
)
|
||||
} else {
|
||||
return ('')
|
||||
}
|
||||
}
|
||||
|
||||
function getPinStatus(status: string) {
|
||||
if (status === "Y") return {
|
||||
msg: 'Active',
|
||||
btn: 'Block PIN',
|
||||
res: 'Block'
|
||||
};
|
||||
if (status === "N") return {
|
||||
msg: 'Not Active',
|
||||
btn: 'Activate PIN',
|
||||
res: null
|
||||
};
|
||||
if (status === "P") return {
|
||||
msg: 'Suspend PIN',
|
||||
btn: 'Unblock PIN',
|
||||
res: 'UnBlock'
|
||||
};
|
||||
if (status === "O") return {
|
||||
msg: 'Suspend OTP',
|
||||
btn: 'Unblock OTP',
|
||||
res: null
|
||||
};
|
||||
return {
|
||||
msg: "None",
|
||||
btn: 'No status found',
|
||||
res: null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user