feat: allow for edited customer photos to be previewed
This commit is contained in:
parent
a29f3fc13c
commit
e3fe2bc04e
2 changed files with 65 additions and 30 deletions
|
|
@ -77,6 +77,8 @@ const CustomerData = ({
|
||||||
}) => {
|
}) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [listView, setListView] = useState(false)
|
const [listView, setListView] = useState(false)
|
||||||
|
const [previewPhoto, setPreviewPhoto] = useState(null)
|
||||||
|
const [previewCard, setPreviewCard] = useState(null)
|
||||||
|
|
||||||
const idData = R.path(['idCardData'])(customer)
|
const idData = R.path(['idCardData'])(customer)
|
||||||
const rawExpirationDate = R.path(['expirationDate'])(idData)
|
const rawExpirationDate = R.path(['expirationDate'])(idData)
|
||||||
|
|
@ -213,9 +215,6 @@ const CustomerData = ({
|
||||||
{
|
{
|
||||||
title: 'Name',
|
title: 'Name',
|
||||||
titleIcon: <EditIcon className={classes.editIcon} />,
|
titleIcon: <EditIcon className={classes.editIcon} />,
|
||||||
authorize: () => {},
|
|
||||||
reject: () => {},
|
|
||||||
save: () => {},
|
|
||||||
isAvailable: false,
|
isAvailable: false,
|
||||||
editable: true
|
editable: true
|
||||||
},
|
},
|
||||||
|
|
@ -226,7 +225,7 @@ const CustomerData = ({
|
||||||
authorize: () =>
|
authorize: () =>
|
||||||
updateCustomer({ sanctionsOverride: OVERRIDE_AUTHORIZED }),
|
updateCustomer({ sanctionsOverride: OVERRIDE_AUTHORIZED }),
|
||||||
reject: () => updateCustomer({ sanctionsOverride: OVERRIDE_REJECTED }),
|
reject: () => updateCustomer({ sanctionsOverride: OVERRIDE_REJECTED }),
|
||||||
children: <Info3>{sanctionsDisplay}</Info3>,
|
children: () => <Info3>{sanctionsDisplay}</Info3>,
|
||||||
isAvailable: !R.isNil(sanctions),
|
isAvailable: !R.isNil(sanctions),
|
||||||
editable: true
|
editable: true
|
||||||
},
|
},
|
||||||
|
|
@ -238,20 +237,33 @@ const CustomerData = ({
|
||||||
authorize: () =>
|
authorize: () =>
|
||||||
updateCustomer({ frontCameraOverride: OVERRIDE_AUTHORIZED }),
|
updateCustomer({ frontCameraOverride: OVERRIDE_AUTHORIZED }),
|
||||||
reject: () => updateCustomer({ frontCameraOverride: OVERRIDE_REJECTED }),
|
reject: () => updateCustomer({ frontCameraOverride: OVERRIDE_REJECTED }),
|
||||||
save: values =>
|
save: values => {
|
||||||
replacePhoto({
|
setPreviewPhoto(null)
|
||||||
|
return replacePhoto({
|
||||||
newPhoto: values.frontCamera,
|
newPhoto: values.frontCamera,
|
||||||
photoType: 'frontCamera'
|
photoType: 'frontCamera'
|
||||||
}),
|
})
|
||||||
|
},
|
||||||
|
cancel: () => setPreviewPhoto(null),
|
||||||
deleteEditedData: () => deleteEditedData({ frontCamera: null }),
|
deleteEditedData: () => deleteEditedData({ frontCamera: null }),
|
||||||
children: customer.frontCameraPath ? (
|
children: values => {
|
||||||
|
if (values.frontCamera !== previewPhoto) {
|
||||||
|
setPreviewPhoto(values.frontCamera)
|
||||||
|
}
|
||||||
|
|
||||||
|
return customer.frontCameraPath ? (
|
||||||
<Photo
|
<Photo
|
||||||
show={customer.frontCameraPath}
|
show={customer.frontCameraPath}
|
||||||
src={`${URI}/front-camera-photo/${R.path(['frontCameraPath'])(
|
src={
|
||||||
|
!R.isNil(previewPhoto)
|
||||||
|
? URL.createObjectURL(previewPhoto)
|
||||||
|
: `${URI}/front-camera-photo/${R.path(['frontCameraPath'])(
|
||||||
customer
|
customer
|
||||||
)}`}
|
)}`
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : null,
|
) : null
|
||||||
|
},
|
||||||
hasImage: true,
|
hasImage: true,
|
||||||
validationSchema: customerDataSchemas.frontCamera,
|
validationSchema: customerDataSchemas.frontCamera,
|
||||||
initialValues: initialValues.frontCamera,
|
initialValues: initialValues.frontCamera,
|
||||||
|
|
@ -266,18 +278,33 @@ const CustomerData = ({
|
||||||
authorize: () =>
|
authorize: () =>
|
||||||
updateCustomer({ idCardPhotoOverride: OVERRIDE_AUTHORIZED }),
|
updateCustomer({ idCardPhotoOverride: OVERRIDE_AUTHORIZED }),
|
||||||
reject: () => updateCustomer({ idCardPhotoOverride: OVERRIDE_REJECTED }),
|
reject: () => updateCustomer({ idCardPhotoOverride: OVERRIDE_REJECTED }),
|
||||||
save: values =>
|
save: values => {
|
||||||
replacePhoto({
|
setPreviewCard(null)
|
||||||
|
return replacePhoto({
|
||||||
newPhoto: values.idCardPhoto,
|
newPhoto: values.idCardPhoto,
|
||||||
photoType: 'idCardPhoto'
|
photoType: 'idCardPhoto'
|
||||||
}),
|
})
|
||||||
|
},
|
||||||
|
cancel: () => setPreviewCard(null),
|
||||||
deleteEditedData: () => deleteEditedData({ idCardPhoto: null }),
|
deleteEditedData: () => deleteEditedData({ idCardPhoto: null }),
|
||||||
children: customer.idCardPhotoPath ? (
|
children: values => {
|
||||||
|
if (values.idCardPhoto !== previewCard) {
|
||||||
|
setPreviewCard(values.idCardPhoto)
|
||||||
|
}
|
||||||
|
|
||||||
|
return customer.idCardPhotoPath ? (
|
||||||
<Photo
|
<Photo
|
||||||
show={customer.idCardPhotoPath}
|
show={customer.idCardPhotoPath}
|
||||||
src={`${URI}/id-card-photo/${R.path(['idCardPhotoPath'])(customer)}`}
|
src={
|
||||||
|
!R.isNil(previewCard)
|
||||||
|
? URL.createObjectURL(previewCard)
|
||||||
|
: `${URI}/id-card-photo/${R.path(['idCardPhotoPath'])(
|
||||||
|
customer
|
||||||
|
)}`
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
) : null,
|
) : null
|
||||||
|
},
|
||||||
hasImage: true,
|
hasImage: true,
|
||||||
validationSchema: customerDataSchemas.idCardPhoto,
|
validationSchema: customerDataSchemas.idCardPhoto,
|
||||||
initialValues: initialValues.idCardPhoto,
|
initialValues: initialValues.idCardPhoto,
|
||||||
|
|
@ -292,6 +319,7 @@ const CustomerData = ({
|
||||||
authorize: () => updateCustomer({ usSsnOverride: OVERRIDE_AUTHORIZED }),
|
authorize: () => updateCustomer({ usSsnOverride: OVERRIDE_AUTHORIZED }),
|
||||||
reject: () => updateCustomer({ usSsnOverride: OVERRIDE_REJECTED }),
|
reject: () => updateCustomer({ usSsnOverride: OVERRIDE_REJECTED }),
|
||||||
save: values => editCustomer(values),
|
save: values => editCustomer(values),
|
||||||
|
children: () => {},
|
||||||
deleteEditedData: () => deleteEditedData({ usSsn: null }),
|
deleteEditedData: () => deleteEditedData({ usSsn: null }),
|
||||||
validationSchema: customerDataSchemas.usSsn,
|
validationSchema: customerDataSchemas.usSsn,
|
||||||
initialValues: initialValues.usSsn,
|
initialValues: initialValues.usSsn,
|
||||||
|
|
@ -427,6 +455,7 @@ const CustomerData = ({
|
||||||
titleIcon,
|
titleIcon,
|
||||||
fields,
|
fields,
|
||||||
save,
|
save,
|
||||||
|
cancel,
|
||||||
deleteEditedData,
|
deleteEditedData,
|
||||||
retrieveAdditionalData,
|
retrieveAdditionalData,
|
||||||
children,
|
children,
|
||||||
|
|
@ -453,6 +482,7 @@ const CustomerData = ({
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
save={save}
|
save={save}
|
||||||
|
cancel={cancel}
|
||||||
deleteEditedData={deleteEditedData}
|
deleteEditedData={deleteEditedData}
|
||||||
retrieveAdditionalData={retrieveAdditionalData}
|
retrieveAdditionalData={retrieveAdditionalData}
|
||||||
editable={editable}></EditableCard>
|
editable={editable}></EditableCard>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import { Form, Formik, Field as FormikField } from 'formik'
|
import { Form, Formik, Field as FormikField } from 'formik'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import { useState, React } from 'react'
|
import { useState, React, useRef } from 'react'
|
||||||
|
|
||||||
import ErrorMessage from 'src/components/ErrorMessage'
|
import ErrorMessage from 'src/components/ErrorMessage'
|
||||||
import PromptWhenDirty from 'src/components/PromptWhenDirty'
|
import PromptWhenDirty from 'src/components/PromptWhenDirty'
|
||||||
|
|
@ -132,14 +132,15 @@ const ReadOnlyField = ({ field, value, ...props }) => {
|
||||||
|
|
||||||
const EditableCard = ({
|
const EditableCard = ({
|
||||||
fields,
|
fields,
|
||||||
save,
|
save = () => {},
|
||||||
authorize,
|
cancel = () => {},
|
||||||
|
authorize = () => {},
|
||||||
hasImage,
|
hasImage,
|
||||||
reject,
|
reject = () => {},
|
||||||
state,
|
state,
|
||||||
title,
|
title,
|
||||||
titleIcon,
|
titleIcon,
|
||||||
children,
|
children = () => {},
|
||||||
validationSchema,
|
validationSchema,
|
||||||
initialValues,
|
initialValues,
|
||||||
deleteEditedData,
|
deleteEditedData,
|
||||||
|
|
@ -149,6 +150,8 @@ const EditableCard = ({
|
||||||
}) => {
|
}) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
|
|
||||||
|
const formRef = useRef()
|
||||||
|
|
||||||
const [editing, setEditing] = useState(false)
|
const [editing, setEditing] = useState(false)
|
||||||
const [input, setInput] = useState(null)
|
const [input, setInput] = useState(null)
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
|
|
@ -187,8 +190,9 @@ const EditableCard = ({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{children}
|
{children(formRef.current?.values ?? {})}
|
||||||
<Formik
|
<Formik
|
||||||
|
innerRef={formRef}
|
||||||
validateOnBlur={false}
|
validateOnBlur={false}
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
|
|
@ -359,6 +363,7 @@ const EditableCard = ({
|
||||||
color="secondary"
|
color="secondary"
|
||||||
Icon={CancelReversedIcon}
|
Icon={CancelReversedIcon}
|
||||||
InverseIcon={CancelReversedIcon}
|
InverseIcon={CancelReversedIcon}
|
||||||
|
onClick={() => cancel()}
|
||||||
type="reset">
|
type="reset">
|
||||||
Cancel
|
Cancel
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue