fix: allow for custom info requests to be allowed or blocked
fix: improve custom info requests backend fix: add custom info requests to trigger overrides
This commit is contained in:
parent
08bcf03a1e
commit
87a3b718db
11 changed files with 167 additions and 88 deletions
|
|
@ -324,7 +324,6 @@ const CustomerData = ({
|
|||
]
|
||||
|
||||
R.forEach(it => {
|
||||
console.log('it', it)
|
||||
customRequirements.push({
|
||||
fields: [
|
||||
{
|
||||
|
|
@ -336,12 +335,13 @@ const CustomerData = ({
|
|||
],
|
||||
title: it.customInfoRequest.customRequest.name,
|
||||
titleIcon: <CardIcon className={classes.cardIcon} />,
|
||||
state: R.path(['override'])(it),
|
||||
authorize: () =>
|
||||
authorizeCustomRequest({
|
||||
variables: {
|
||||
customerId: it.customerId,
|
||||
infoRequestId: it.customInfoRequest.id,
|
||||
isAuthorized: true
|
||||
override: OVERRIDE_AUTHORIZED
|
||||
}
|
||||
}),
|
||||
reject: () =>
|
||||
|
|
@ -349,7 +349,7 @@ const CustomerData = ({
|
|||
variables: {
|
||||
customerId: it.customerId,
|
||||
infoRequestId: it.customInfoRequest.id,
|
||||
isAuthorized: false
|
||||
override: OVERRIDE_REJECTED
|
||||
}
|
||||
}),
|
||||
save: values => {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,9 @@ const GET_CUSTOMER = gql`
|
|||
}
|
||||
customInfoRequests {
|
||||
customerId
|
||||
approved
|
||||
override
|
||||
overrideBy
|
||||
overrideAt
|
||||
customerData
|
||||
customInfoRequest {
|
||||
id
|
||||
|
|
@ -180,12 +182,12 @@ const SET_AUTHORIZED_REQUEST = gql`
|
|||
mutation setAuthorizedCustomRequest(
|
||||
$customerId: ID!
|
||||
$infoRequestId: ID!
|
||||
$isAuthorized: Boolean!
|
||||
$override: String!
|
||||
) {
|
||||
setAuthorizedCustomRequest(
|
||||
customerId: $customerId
|
||||
infoRequestId: $infoRequestId
|
||||
isAuthorized: $isAuthorized
|
||||
override: $override
|
||||
)
|
||||
}
|
||||
`
|
||||
|
|
|
|||
|
|
@ -53,12 +53,12 @@ const SET_AUTHORIZED_REQUEST = gql`
|
|||
mutation setAuthorizedCustomRequest(
|
||||
$customerId: ID!
|
||||
$infoRequestId: ID!
|
||||
$isAuthorized: Boolean!
|
||||
$override: String!
|
||||
) {
|
||||
setAuthorizedCustomRequest(
|
||||
customerId: $customerId
|
||||
infoRequestId: $infoRequestId
|
||||
isAuthorized: $isAuthorized
|
||||
override: $override
|
||||
)
|
||||
}
|
||||
`
|
||||
|
|
|
|||
|
|
@ -28,13 +28,34 @@ const GET_INFO = gql`
|
|||
}
|
||||
`
|
||||
|
||||
const GET_CUSTOM_REQUESTS = gql`
|
||||
query customInfoRequests {
|
||||
customInfoRequests {
|
||||
id
|
||||
customRequest
|
||||
enabled
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const AdvancedTriggersSettings = memo(() => {
|
||||
const SCREEN_KEY = namespaces.TRIGGERS
|
||||
const [error, setError] = useState(null)
|
||||
const [isEditingDefault, setEditingDefault] = useState(false)
|
||||
const [isEditingOverrides, setEditingOverrides] = useState(false)
|
||||
|
||||
const { data } = useQuery(GET_INFO)
|
||||
const { data, loading: configLoading } = useQuery(GET_INFO)
|
||||
const { data: customInfoReqData, loading: customInfoLoading } = useQuery(
|
||||
GET_CUSTOM_REQUESTS
|
||||
)
|
||||
|
||||
const customInfoRequests =
|
||||
R.path(['customInfoRequests'])(customInfoReqData) ?? []
|
||||
const enabledCustomInfoRequests = R.filter(R.propEq('enabled', true))(
|
||||
customInfoRequests
|
||||
)
|
||||
|
||||
const loading = configLoading || customInfoLoading
|
||||
|
||||
const [saveConfig] = useMutation(SAVE_CONFIG, {
|
||||
refetchQueries: () => ['getData'],
|
||||
|
|
@ -67,42 +88,47 @@ const AdvancedTriggersSettings = memo(() => {
|
|||
const onEditingOverrides = (it, editing) => setEditingOverrides(editing)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Section>
|
||||
<EditableTable
|
||||
title="Default requirement settings"
|
||||
error={error?.message}
|
||||
titleLg
|
||||
name="triggersConfig"
|
||||
enableEdit
|
||||
initialValues={requirementsDefaults}
|
||||
save={saveDefaults}
|
||||
validationSchema={defaultSchema}
|
||||
data={R.of(requirementsDefaults)}
|
||||
elements={getDefaultSettings()}
|
||||
setEditing={onEditingDefault}
|
||||
forceDisable={isEditingOverrides}
|
||||
/>
|
||||
</Section>
|
||||
<Section>
|
||||
<EditableTable
|
||||
error={error?.message}
|
||||
title="Overrides"
|
||||
titleLg
|
||||
name="overrides"
|
||||
enableDelete
|
||||
enableEdit
|
||||
enableCreate
|
||||
initialValues={overridesDefaults}
|
||||
save={saveOverrides}
|
||||
validationSchema={getOverridesSchema(requirementsOverrides)}
|
||||
data={requirementsOverrides}
|
||||
elements={getOverrides()}
|
||||
setEditing={onEditingOverrides}
|
||||
forceDisable={isEditingDefault}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
!loading && (
|
||||
<>
|
||||
<Section>
|
||||
<EditableTable
|
||||
title="Default requirement settings"
|
||||
error={error?.message}
|
||||
titleLg
|
||||
name="triggersConfig"
|
||||
enableEdit
|
||||
initialValues={requirementsDefaults}
|
||||
save={saveDefaults}
|
||||
validationSchema={defaultSchema}
|
||||
data={R.of(requirementsDefaults)}
|
||||
elements={getDefaultSettings()}
|
||||
setEditing={onEditingDefault}
|
||||
forceDisable={isEditingOverrides}
|
||||
/>
|
||||
</Section>
|
||||
<Section>
|
||||
<EditableTable
|
||||
error={error?.message}
|
||||
title="Overrides"
|
||||
titleLg
|
||||
name="overrides"
|
||||
enableDelete
|
||||
enableEdit
|
||||
enableCreate
|
||||
initialValues={overridesDefaults}
|
||||
save={saveOverrides}
|
||||
validationSchema={getOverridesSchema(
|
||||
requirementsOverrides,
|
||||
enabledCustomInfoRequests
|
||||
)}
|
||||
data={requirementsOverrides}
|
||||
elements={getOverrides(enabledCustomInfoRequests)}
|
||||
setEditing={onEditingOverrides}
|
||||
forceDisable={isEditingDefault}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,29 @@ import * as Yup from 'yup'
|
|||
import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
|
||||
import { getView } from 'src/pages/Triggers/helper'
|
||||
|
||||
const advancedRequirementOptions = [
|
||||
{ display: 'Sanctions', code: 'sanctions' },
|
||||
{ display: 'ID card image', code: 'idCardPhoto' },
|
||||
{ display: 'ID data', code: 'idCardData' },
|
||||
{ display: 'Customer camera', code: 'facephoto' },
|
||||
{ display: 'US SSN', code: 'usSsn' }
|
||||
]
|
||||
const buildAdvancedRequirementOptions = customInfoRequests => {
|
||||
const base = [
|
||||
{ display: 'Sanctions', code: 'sanctions' },
|
||||
{ display: 'ID card image', code: 'idCardPhoto' },
|
||||
{ display: 'ID data', code: 'idCardData' },
|
||||
{ display: 'Customer camera', code: 'facephoto' },
|
||||
{ display: 'US SSN', code: 'usSsn' }
|
||||
]
|
||||
|
||||
const displayRequirement = code => {
|
||||
const custom = R.map(it => ({
|
||||
display: it.customRequest.name,
|
||||
code: it.id
|
||||
}))(customInfoRequests)
|
||||
|
||||
return R.concat(base, custom)
|
||||
}
|
||||
|
||||
const displayRequirement = (code, customInfoRequests) => {
|
||||
return R.prop(
|
||||
'display',
|
||||
R.find(R.propEq('code', code))(advancedRequirementOptions)
|
||||
R.find(R.propEq('code', code))(
|
||||
buildAdvancedRequirementOptions(customInfoRequests)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +40,7 @@ const defaultSchema = Yup.object().shape({
|
|||
.required()
|
||||
})
|
||||
|
||||
const getOverridesSchema = values => {
|
||||
const getOverridesSchema = (values, customInfoRequests) => {
|
||||
return Yup.object().shape({
|
||||
id: Yup.string()
|
||||
.label('Requirement')
|
||||
|
|
@ -40,7 +51,8 @@ const getOverridesSchema = values => {
|
|||
if (R.find(R.propEq('requirement', requirement))(values)) {
|
||||
return this.createError({
|
||||
message: `Requirement ${displayRequirement(
|
||||
requirement
|
||||
requirement,
|
||||
customInfoRequests
|
||||
)} already overriden`
|
||||
})
|
||||
}
|
||||
|
|
@ -84,17 +96,20 @@ const getDefaultSettings = () => {
|
|||
]
|
||||
}
|
||||
|
||||
const getOverrides = () => {
|
||||
const getOverrides = customInfoRequests => {
|
||||
return [
|
||||
{
|
||||
name: 'requirement',
|
||||
header: 'Requirement',
|
||||
width: 196,
|
||||
size: 'sm',
|
||||
view: getView(advancedRequirementOptions, 'display'),
|
||||
view: getView(
|
||||
buildAdvancedRequirementOptions(customInfoRequests),
|
||||
'display'
|
||||
),
|
||||
input: Autocomplete,
|
||||
inputProps: {
|
||||
options: advancedRequirementOptions,
|
||||
options: buildAdvancedRequirementOptions(customInfoRequests),
|
||||
labelProp: 'display',
|
||||
valueProp: 'code'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue