{isRadioGroupActive() && (
Threshold
)}
{isThresholdCurrencyEnabled && (
<>
{props.currency}
>
)}
{isTransactionAmountEnabled && (
<>
transactions
>
)}
{isThresholdDaysEnabled && (
<>
in
days
>
)}
{isConsecutiveDaysEnabled && (
<>
consecutive days
>
)}
>
)
}
const type = currency => ({
schema: typeSchema,
options: typeOptions,
Component: Type,
props: { currency },
initialValues: {
triggerType: '',
threshold: { threshold: '', thresholdDays: '' }
}
})
const requirementSchema = Yup.object()
.shape({
requirement: Yup.object({
requirement: Yup.string().required(),
suspensionDays: Yup.number().when('requirement', {
is: value => value === 'suspend',
then: Yup.number()
.nullable()
.transform(transformNumber),
otherwise: Yup.number()
.nullable()
.transform(() => null)
}),
customInfoRequestId: Yup.string().when('requirement', {
is: value => value === 'custom',
then: Yup.string(),
otherwise: Yup.string()
.nullable()
.transform(() => '')
})
}).required()
})
.test(({ requirement }, context) => {
const requirementValidator = (requirement, type) => {
switch (type) {
case 'suspend':
return requirement.requirement === type
? requirement.suspensionDays > 0
: true
case 'custom':
return requirement.requirement === type
? !R.isNil(requirement.customInfoRequestId)
: true
default:
return true
}
}
if (requirement && !requirementValidator(requirement, 'suspend'))
return context.createError({
path: 'requirement',
message: 'Suspension days must be greater than 0'
})
if (requirement && !requirementValidator(requirement, 'custom'))
return context.createError({
path: 'requirement',
message: 'You must select an item'
})
})
const requirementOptions = [
{ display: 'SMS verification', code: 'sms' },
{ display: 'ID card image', code: 'idCardPhoto' },
{ display: 'ID data', code: 'idCardData' },
{ display: 'Customer camera', code: 'facephoto' },
{ display: 'Sanctions', code: 'sanctions' },
{ display: 'US SSN', code: 'usSsn' },
// { display: 'Super user', code: 'superuser' },
{ display: 'Suspend', code: 'suspend' },
{ display: 'Block', code: 'block' }
]
const hasRequirementError = (errors, touched, values) =>
!!errors.requirement &&
!!touched.requirement?.suspensionDays &&
(!values.requirement?.suspensionDays ||
values.requirement?.suspensionDays < 0)
const hasCustomRequirementError = (errors, touched, values) =>
!!errors.requirement &&
!!touched.requirement?.customInfoRequestId &&
(!values.requirement?.customInfoRequestId ||
!R.isNil(values.requirement?.customInfoRequestId))
const Requirement = ({ customInfoRequests }) => {
const classes = useStyles()
const {
touched,
errors,
values,
handleChange,
setTouched
} = useFormikContext()
const isSuspend = values?.requirement?.requirement === 'suspend'
const isCustom = values?.requirement?.requirement === 'custom'
const makeCustomReqOptions = () =>
customInfoRequests.map(it => ({
value: it.id,
display: it.customRequest.name
}))
const enableCustomRequirement = customInfoRequests?.length > 0
const customInfoOption = {
display: 'Custom information requirement',
code: 'custom'
}
const options = enableCustomRequirement
? [...requirementOptions, customInfoOption]
: [...requirementOptions]
const titleClass = {
[classes.error]:
(!!errors.requirement && !isSuspend && !isCustom) ||
(isSuspend && hasRequirementError(errors, touched, values)) ||
(isCustom && hasCustomRequirementError(errors, touched, values))
}
return (
<>