diff --git a/new-lamassu-admin/src/pages/Customers/CustomerData.js b/new-lamassu-admin/src/pages/Customers/CustomerData.js
index a5346a0e..3f792db3 100644
--- a/new-lamassu-admin/src/pages/Customers/CustomerData.js
+++ b/new-lamassu-admin/src/pages/Customers/CustomerData.js
@@ -26,7 +26,11 @@ import { URI } from 'src/utils/apollo'
import styles from './CustomerData.styles.js'
import { EditableCard } from './components'
-import { customerDataElements, customerDataschemas } from './helper.js'
+import {
+ customerDataElements,
+ customerDataSchemas,
+ formatDates
+} from './helper.js'
const useStyles = makeStyles(styles)
@@ -64,7 +68,8 @@ const CustomerData = ({
editCustomer,
deleteEditedData,
updateCustomRequest,
- authorizeCustomRequest
+ authorizeCustomRequest,
+ updateCustomEntry
}) => {
const classes = useStyles()
const [listView, setListView] = useState(false)
@@ -96,7 +101,7 @@ const CustomerData = ({
const getVisibleCards = _.filter(elem => elem.isAvailable)
const initialValues = {
- idScan: {
+ idCardData: {
firstName: R.path(['firstName'])(idData) ?? '',
lastName: R.path(['lastName'])(idData) ?? '',
documentNumber: R.path(['documentNumber'])(idData) ?? '',
@@ -124,19 +129,9 @@ const CustomerData = ({
}
}
- const formatDates = values => {
- _.map(
- elem =>
- (values[elem] = format('yyyyMMdd')(
- parse(new Date(), 'yyyy-MM-dd', values[elem])
- ))
- )(['dateOfBirth', 'expirationDate'])
- return values
- }
-
const cards = [
{
- fields: customerDataElements.idScanElements,
+ fields: customerDataElements.idCardData,
title: 'ID Scan',
titleIcon: ,
state: R.path(['idCardDataOverride'])(customer),
@@ -148,8 +143,8 @@ const CustomerData = ({
editCustomer({
idCardData: _.merge(idData, formatDates(values))
}),
- validationSchema: customerDataschemas.idScan,
- initialValues: initialValues.idScan,
+ validationSchema: customerDataSchemas.idCardData,
+ initialValues: initialValues.idCardData,
isAvailable: !_.isNil(idData)
},
{
@@ -179,7 +174,7 @@ const CustomerData = ({
isAvailable: !_.isNil(sanctions)
},
{
- fields: customerDataElements.frontCameraElements,
+ fields: customerDataElements.frontCamera,
title: 'Front facing camera',
titleIcon: ,
state: R.path(['frontCameraOverride'])(customer),
@@ -201,12 +196,12 @@ const CustomerData = ({
/>
) : null,
hasImage: true,
- validationSchema: customerDataschemas.frontCamera,
+ validationSchema: customerDataSchemas.frontCamera,
initialValues: initialValues.frontCamera,
isAvailable: !_.isNil(customer.frontCameraPath)
},
{
- fields: customerDataElements.idCardPhotoElements,
+ fields: customerDataElements.idCardPhoto,
title: 'ID card image',
titleIcon: ,
state: R.path(['idCardPhotoOverride'])(customer),
@@ -226,20 +221,20 @@ const CustomerData = ({
/>
) : null,
hasImage: true,
- validationSchema: customerDataschemas.idCardPhoto,
+ validationSchema: customerDataSchemas.idCardPhoto,
initialValues: initialValues.idCardPhoto,
isAvailable: !_.isNil(customer.idCardPhotoPath)
},
{
- fields: customerDataElements.usSsnElements,
+ fields: customerDataElements.usSsn,
title: 'US SSN',
titleIcon: ,
state: R.path(['usSsnOverride'])(customer),
authorize: () => updateCustomer({ usSsnOverride: OVERRIDE_AUTHORIZED }),
reject: () => updateCustomer({ usSsnOverride: OVERRIDE_REJECTED }),
- save: values => editCustomer({ usSsn: values.usSsn }),
+ save: values => editCustomer(values),
deleteEditedData: () => deleteEditedData({ usSsn: null }),
- validationSchema: customerDataschemas.usSsn,
+ validationSchema: customerDataSchemas.usSsn,
initialValues: initialValues.usSsn,
isAvailable: !_.isNil(customer.usSsn)
}
@@ -308,7 +303,12 @@ const CustomerData = ({
],
title: it.label,
titleIcon: ,
- save: () => {},
+ save: values => {
+ updateCustomEntry({
+ fieldId: it.id,
+ value: values[it.label]
+ })
+ },
deleteEditedData: () => {},
validationSchema: Yup.object().shape({
[it.label]: Yup.string()
diff --git a/new-lamassu-admin/src/pages/Customers/CustomerProfile.js b/new-lamassu-admin/src/pages/Customers/CustomerProfile.js
index d83960d3..71b24ba2 100644
--- a/new-lamassu-admin/src/pages/Customers/CustomerProfile.js
+++ b/new-lamassu-admin/src/pages/Customers/CustomerProfile.js
@@ -242,6 +242,12 @@ const SET_CUSTOM_ENTRY = gql`
}
`
+const EDIT_CUSTOM_ENTRY = gql`
+ mutation saveCustomField($customerId: ID!, $fieldId: ID!, $value: String!) {
+ saveCustomField(customerId: $customerId, fieldId: $fieldId, value: $value)
+ }
+`
+
const GET_ACTIVE_CUSTOM_REQUESTS = gql`
query customInfoRequests($onlyEnabled: Boolean) {
customInfoRequests(onlyEnabled: $onlyEnabled) {
@@ -280,6 +286,10 @@ const CustomerProfile = memo(() => {
onCompleted: () => getCustomer()
})
+ const [editCustomEntry] = useMutation(EDIT_CUSTOM_ENTRY, {
+ onCompleted: () => getCustomer()
+ })
+
const [replaceCustomerPhoto] = useMutation(REPLACE_CUSTOMER_PHOTO, {
onCompleted: () => getCustomer()
})
@@ -330,6 +340,16 @@ const CustomerProfile = memo(() => {
setWizard(null)
}
+ const updateCustomEntry = it => {
+ editCustomEntry({
+ variables: {
+ customerId,
+ fieldId: it.fieldId,
+ value: it.value
+ }
+ })
+ }
+
const updateCustomer = it =>
setCustomer({
variables: {
@@ -338,7 +358,7 @@ const CustomerProfile = memo(() => {
}
})
- const replacePhoto = it =>
+ const replacePhoto = it => {
replaceCustomerPhoto({
variables: {
customerId,
@@ -346,14 +366,18 @@ const CustomerProfile = memo(() => {
photoType: it.photoType
}
})
+ setWizard(null)
+ }
- const editCustomer = it =>
+ const editCustomer = it => {
editCustomerData({
variables: {
customerId,
customerEdit: it
}
})
+ setWizard(null)
+ }
const deleteEditedData = it =>
deleteCustomerEditedData({
@@ -421,7 +445,7 @@ const CustomerProfile = memo(() => {
const timezone = R.path(['config', 'locale_timezone'], configResponse)
- const customRequirementOptions =
+ const customInfoRequirementOptions =
activeCustomRequests?.customInfoRequests?.map(it => ({
value: it.id,
display: it.customRequest.name
@@ -564,7 +588,8 @@ const CustomerProfile = memo(() => {
editCustomer={editCustomer}
deleteEditedData={deleteEditedData}
updateCustomRequest={setCustomerCustomInfoRequest}
- authorizeCustomRequest={authorizeCustomRequest}>
+ authorizeCustomRequest={authorizeCustomRequest}
+ updateCustomEntry={updateCustomEntry}>
)}
{isNotes && (
@@ -590,7 +615,7 @@ const CustomerProfile = memo(() => {
addPhoto={replacePhoto}
addCustomerData={editCustomer}
onClose={() => setWizard(null)}
- customRequirementOptions={customRequirementOptions}
+ customInfoRequirementOptions={customInfoRequirementOptions}
/>
)}
diff --git a/new-lamassu-admin/src/pages/Customers/Wizard.js b/new-lamassu-admin/src/pages/Customers/Wizard.js
index 16db1647..f257e23f 100644
--- a/new-lamassu-admin/src/pages/Customers/Wizard.js
+++ b/new-lamassu-admin/src/pages/Customers/Wizard.js
@@ -1,5 +1,5 @@
import { makeStyles } from '@material-ui/core'
-import { Form, Formik, Field } from 'formik'
+import { Form, Formik } from 'formik'
import * as R from 'ramda'
import React, { useState, Fragment } from 'react'
@@ -7,10 +7,16 @@ import ErrorMessage from 'src/components/ErrorMessage'
import Modal from 'src/components/Modal'
import Stepper from 'src/components/Stepper'
import { Button } from 'src/components/buttons'
-import { Dropdown } from 'src/components/inputs/formik'
import { comet } from 'src/styling/variables'
-import { entryType, customElements } from './helper'
+import {
+ entryType,
+ customElements,
+ requirementElements,
+ formatDates,
+ REQUIREMENT,
+ ID_CARD_DATA
+} from './helper'
const LAST_STEP = 2
@@ -52,11 +58,17 @@ const styles = {
const useStyles = makeStyles(styles)
const getStep = (step, selectedValues) => {
+ const elements =
+ selectedValues?.entryType === REQUIREMENT &&
+ !R.isNil(selectedValues?.requirement)
+ ? requirementElements[selectedValues?.requirement]
+ : customElements[selectedValues?.dataType]
+
switch (step) {
case 1:
return entryType
case 2:
- return customElements[selectedValues?.dataType]
+ return elements
default:
return Fragment
}
@@ -66,7 +78,7 @@ const Wizard = ({
onClose,
save,
error,
- customRequirementOptions,
+ customInfoRequirementOptions,
addCustomerData,
addPhoto
}) => {
@@ -78,7 +90,10 @@ const Wizard = ({
step: 1
})
- const isCustom = values => values?.requirement === 'custom'
+ const isIdCardData = values => values?.requirement === ID_CARD_DATA
+ const formatCustomerData = (it, newConfig) =>
+ isIdCardData(newConfig) ? { [newConfig.requirement]: formatDates(it) } : it
+
const isLastStep = step === LAST_STEP
const stepOptions = getStep(step, selectedValues)
@@ -87,7 +102,23 @@ const Wizard = ({
setSelectedValues(newConfig)
if (isLastStep) {
- return save(newConfig)
+ switch (stepOptions.saveType) {
+ case 'customerData':
+ return addCustomerData(formatCustomerData(it, newConfig))
+ case 'customerDataUpload':
+ return addPhoto({
+ newPhoto: R.head(R.values(it)),
+ photoType: R.head(R.keys(it))
+ })
+ case 'customEntry':
+ return save(newConfig)
+ case 'customInfoRequirement':
+ return
+ // case 'customerEntryUpload':
+ // break
+ default:
+ break
+ }
}
setState({
@@ -120,22 +151,9 @@ const Wizard = ({