So basically I have a pop up it is currently closed on clicking the escape button i don’t want it i want if user click on the escape button it should not close how do i do that?
const [state, setState] = useState({
showEftConsent: false,
});
so this is a state which currently set to false but when login it first time it set to true and pop up is shown then when i click on escape button it set my state to false..
useEffect(() => {
setState({ ...state, showEftConsent: showEftConsent });
}, [showEftConsent]);
this is my useEffect which only run when showEftConsent value is changed
const handleEftClose = () => {
setState({ ...state, showEftConsent: false });
handleCloseWithoutDismiss();
};
this is a handleEftClose function which is triggered only when i press escape button so when i click escape button it closed so i don’t want it if i click escape button it should not closed it
{state.showEftConsent ? (
<EftConsentDialog
isOpen={state.showEftConsent}
showEftSuccessDialog={auth && auth.get("showEftSuccessDialog")}
handleClose={() => handleEftClose()}
disableBackdropClick={true}
{...props}
/>
) : null}
now the handleEftClose function passed to the prop of EftConsentDialog component
import React, { useContext } from 'react'
import ContentDialog from 'components/common/material.components/content.dialog/content.dialog'
import { Button, CircularProgress, Paper, Switch, Typography } from '@material-ui/core';
import { maskAccountNumber } from 'components/common/util/util'
import { GET_ACCOUNTS, GET_ACCOUNT_DETAIL, ENABLE_EFT_CONSENT } from 'view.updater/actions/accounts.actions';
import { checkExecutionStatus, IsMobileWidth, IsZoom150 } from 'components/common/util/util';
import { AppContext } from './container';
import { useState } from 'react';
import OtpInput from "react-otp-input";
import EftConsentSuccessDialog from './eft.consent.success.dialog';
const EftConsentDialog = (props) => {
const { isOpen, showEftSuccessDialog } = props;
const context = useContext(AppContext);
const execStatusGetAccounts = checkExecutionStatus(context, GET_ACCOUNTS);
const execStatusAccountDetail = checkExecutionStatus(context, GET_ACCOUNT_DETAIL);
const enableEftConsent = checkExecutionStatus(context, ENABLE_EFT_CONSENT)
const mobileWidth = IsMobileWidth()
const zoom150 = IsZoom150()
const [state, setState] = useState({
selectedAccounts: [],
pin: "",
enableStatus: false
})
const redirect = (route) => {
props.handleCloseWithoutDismiss();
props.push(route)
}
const onAccountChange = (accountNumber, id) => {
const accounts = [...state.selectedAccounts]
const findedAccountNumber = accounts && accounts.findIndex((data) => data.accountNumber === accountNumber)
if (findedAccountNumber !== -1) {
const index = accounts.indexOf(findedAccountNumber)
accounts.splice(index, 1)
}
else {
accounts.push({
accountNumber: accountNumber,
id: id
})
}
setState({ ...state, selectedAccounts: accounts })
}
const getEftConsent = () => {
const filteredEftConsent = props && props.accountDetails && props.accountDetails.filter((data, index) => {
return data.get("eftConsent") === null || data.get("eftConsent") === ""
})
return filteredEftConsent && filteredEftConsent.map((data, index) => {
return <Paper elevation={2} className='w-100 d-flex justify-content-between m-1 p-2' key={index} >
{
execStatusGetAccounts && execStatusGetAccounts.status === "PENDING" || execStatusAccountDetail && execStatusAccountDetail.status === "PENDING" ?
<div className='w-100 d-flex justify-content-center'>
<CircularProgress />
</div> :
<React.Fragment>
<div className='d-flex flex-column'>
<div className='fw-bold'> {data.get('accountTitle')}</div>
<div> {maskAccountNumber(data.get('accountNumber'))}</div>
</div>
<div><Switch
onChange={() => onAccountChange(data.get("accountNumber"), data.get("id"))}
checked={state.selectedAccounts.find((item) => item.accountNumber === data.get("accountNumber")) ? true : false}
/></div>
</React.Fragment>
}
</Paper>
})
}
const enableSelected = () => {
props.enableEftConsent()
}
const accounts = state.selectedAccounts && state.selectedAccounts.map((data, index) => {
return {
eftFlag: true,
accountNumber: data.accountNumber,
id: data.id
}
})
const accountsTemp = props.allAccounts && props.allAccounts.filter((data, index) => {
return !data.get("eftConsent")
}).map((data) => {
return data.get("number")
})
const onPinChange = (value) => {
if (value.length === 6) {
const eftAccounts = []
props.allAccounts && props.allAccounts.toJS() && props.allAccounts.toJS().forEach((data) => {
const findAccount = state.selectedAccounts && state.selectedAccounts.find((item) => item.accountNumber === data.number)
if(findAccount) {
eftAccounts.push({
eftFlag: true,
accountNumber: data.number,
id: data.id
})
}
else {
eftAccounts.push({
eftFlag: false,
accountNumber: data.number,
id: data.id
})
}
})
props.enableEftConsent({
accounts: eftAccounts,
pin: value,
isFirstTimeLogin: true
})
}
setState({ ...state, pin: value })
}
const closeEftSuccessDialog = () => {
if (state.selectedAccounts.length >= 1) {
state.selectedAccounts.forEach((data, index) => {
props.getAccountDetail(data.id)
})
}
props.handleClose()
props.resetEnableEftConsent()
// props.handleClose()
// console.log(state.selectedAccounts)
}
return (
<ContentDialog
onClose={props.handleClose}
hideCloseButton={true}
dialogIsOpen={isOpen}
disableBackdropClick={true}
notMaxHeight
>
{
showEftSuccessDialog ?
<EftConsentSuccessDialog
{...props}
closeEftSuccessDialog={closeEftSuccessDialog}
/> :
<div className="w-100" style={{ minHeight: 200 }}>
{
!state.enableStatus ?
<React.Fragment>
<div className="d-flex align-items-center p-2 justify-content-center flex-column ">
<div>
<Typography variant='h5' color='secondary' className='fw-bold'>Electronic Funds Transfers (EFT) empower you with digital transfers!</Typography>
</div>
<Typography className='pt-3 ' >
Some of your accounts don’t have EFT turned on. By activating EFT, you will be able to utilize all the banking services available through electronic fund transfers.
To activate, toggle any accounts.
</Typography>
</div>
<div className="d-flex flex-wrap p-2 pt-3 pb-3 w-100 align-items-center justify-content-center">
{
getEftConsent()
}
<Typography className='pt-3 '>
By my consent “Enable selected”, I agree that Soneri Bank Limited may activate all the banking services available through electronic fund transfers by using any payment instruments, channels or modes to execute all Debit transactions for my accounts in electronic form.
</Typography>
</div>
<div className='d-flex flex-column w-100'>
<div className='w-100'>
<Button fullWidth variant='text' disabled={execStatusGetAccounts && execStatusGetAccounts.status === "PENDING" || execStatusAccountDetail && execStatusAccountDetail.status === "PENDING" ? true : false} color='secondary' onClick={() => setState({ ...state, enableStatus: true })}>Update EFT Status</Button>
</div>
</div>
</React.Fragment> :
<div className='d-flex w-100 justify-content-center flex-column' style={{ maxHeight: 300 }}>
<div className='d-flex ps-2 align-items-center cursor-pointer' onClick={() => setState({ ...state, enableStatus: false })}>
<Typography color='secondary' className='pt-1' variant='h6'>
<i className='fa fa-angle-left'></i>
</Typography>
<Typography variant='h6' color='secondary' className='ps-2'>Back</Typography>
</div>
{/* {accounts.length === 0 ? 'account' : 'accounts' } ({accountsTemp.join(', ')}) */}
<Typography className='w-100 d-flex justify-content-center fw-bold' color='secondary' variant='h5' >You are updating EFT status for your account(s)</Typography>
<Typography className='w-100 text-center pt-2 fw-bold' variant='body2'>Proceed by inserting your 6-digits security PIN.</Typography>
<div className='w-100 d-flex justify-content-center pt-3'>
<OtpInput
isInputSecure={false}
//isDisabled={execStatus.status === "PENDING" ? true : false}
shouldAutoFocus={true}
onChange={onPinChange}
numInputs={6}
isInputNum={true}
value={state.pin}
separator={<span> </span>}
inputStyle={{
width: mobileWidth || zoom150 ? 20 : 40,
height: mobileWidth || zoom150 ? 20 : 40,
backgroundColor: "#EDEDEC",
border: "none",
borderRadius: 10,
fontFamily: "password"
}}
focusStyle={{
borderRadius: 10,
backgroundColor: "#ffffff",
outline: "none",
boxShadow:
"0px 3px 5px -1px rgba(0,0,0,0.2), 0px 5px 8px 0px rgba(0,0,0,0.14), 0px 1px 14px 0px rgba(0,0,0,0.12)",
}}
/>
{
enableEftConsent && enableEftConsent.status === "PENDING" ? <div className='ps-2'><CircularProgress /></div> : null
}
</div>
{enableEftConsent.status === "ERROR" ? (
<div className="text-danger d-flex justify-content-center font-italic pb-2">
<b>
{" "}
{enableEftConsent.errorDetail && typeof enableEftConsent.errorDetail === 'object'
? enableEftConsent.errorDetail.get("description")
: "Something isn’t working as it should, please try again"}
</b>
</div>
) : null}
</div>
}
</div>
}
</ContentDialog>
)
}
export default EftConsentDialog
this is my whole EftConsentDialog component and remember handleClose function is also called in the closeEftSuccessDialog in the EftConsentDialog component so i think we need a separate function which occurs on onKeyDown event
I tried to do it but it does not work