Skip to content

Commit

Permalink
feat: set custom info requirement live values
Browse files Browse the repository at this point in the history
  • Loading branch information
josepfo committed Jan 19, 2022
1 parent cb188ea commit 59fcc40
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 51 deletions.
12 changes: 6 additions & 6 deletions new-lamassu-admin/src/components/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export const Carousel = memo(({ photosData, slidePhoto }) => {
opacity: 1
}
}}
// navButtonsWrapperProps={{
// style: {
// background: 'linear-gradient(to right, black 10%, transparent 80%)',
// opacity: '0.4'
// }
// }}
navButtonsWrapperProps={{
style: {
background: 'linear-gradient(to right, black 10%, transparent 80%)',
opacity: '0.4'
}
}}
autoPlay={false}
indicators={false}
navButtonsAlwaysVisible={true}
Expand Down
8 changes: 2 additions & 6 deletions new-lamassu-admin/src/pages/Customers/CustomerProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,7 @@ const CustomerProfile = memo(() => {

const timezone = R.path(['config', 'locale_timezone'], configResponse)

const customInfoRequirementOptions =
activeCustomRequests?.customInfoRequests?.map(it => ({
value: it.id,
display: it.customRequest.name
})) ?? []
const customInfoRequirements = activeCustomRequests?.customInfoRequests

const classes = useStyles()

Expand Down Expand Up @@ -619,7 +615,7 @@ const CustomerProfile = memo(() => {
addPhoto={replacePhoto}
addCustomerData={editCustomer}
onClose={() => setWizard(null)}
customInfoRequirementOptions={customInfoRequirementOptions}
customInfoRequirements={customInfoRequirements}
/>
)}
</div>
Expand Down
44 changes: 26 additions & 18 deletions new-lamassu-admin/src/pages/Customers/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ const styles = {
margin: [[0, 4, 0, 2]],
borderBottom: `1px solid ${comet}`,
display: 'inline-block'
},
dropdownField: {
marginTop: 16,
minWidth: 155
}
}

Expand All @@ -78,7 +74,7 @@ const Wizard = ({
onClose,
save,
error,
customInfoRequirementOptions,
customInfoRequirements,
addCustomerData,
addPhoto
}) => {
Expand All @@ -97,6 +93,12 @@ const Wizard = ({
const isLastStep = step === LAST_STEP
const stepOptions = getStep(step, selectedValues)

const customInfoRequirementOptions =
customInfoRequirements?.map(it => ({
value: it.id,
display: it.customRequest.name
})) ?? []

const onContinue = async it => {
const newConfig = R.merge(config, stepOptions.schema.cast(it))
setSelectedValues(newConfig)
Expand Down Expand Up @@ -147,19 +149,25 @@ const Wizard = ({
onSubmit={onContinue}
initialValues={stepOptions.initialValues}
validationSchema={stepOptions.schema}>
<Form className={classes.form}>
<stepOptions.Component
selectedValues={selectedValues}
customInfoRequirementOptions={customInfoRequirementOptions}
{...stepOptions.props}
/>
<div className={classes.submit}>
{error && <ErrorMessage>Failed to save</ErrorMessage>}
<Button className={classes.button} type="submit">
{isLastStep ? 'Add Data' : 'Next'}
</Button>
</div>
</Form>
{({ values }) => (
<Form className={classes.form}>
<stepOptions.Component
selectedValues={selectedValues}
customInfoRequirementOptions={customInfoRequirementOptions}
customInfoRequirements={customInfoRequirements}
selectedCustomInfoRequirement={
values.customInfoRequirement ?? null
}
{...stepOptions.props}
/>
<div className={classes.submit}>
{error && <ErrorMessage>Failed to save</ErrorMessage>}
<Button className={classes.button} type="submit">
{isLastStep ? 'Add Data' : 'Next'}
</Button>
</div>
</Form>
)}
</Formik>
</Modal>
</>
Expand Down
74 changes: 53 additions & 21 deletions new-lamassu-admin/src/pages/Customers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { parsePhoneNumberFromString } from 'libphonenumber-js'
import * as R from 'ramda'
import * as Yup from 'yup'

import {
RadioGroup,
TextInput,
Autocomplete
} from 'src/components/inputs/formik'
import { RadioGroup, TextInput, Dropdown } from 'src/components/inputs/formik'
import { H4 } from 'src/components/typography'
import { errorColor } from 'src/styling/variables'
import { MANUAL } from 'src/utils/constants'
Expand Down Expand Up @@ -48,6 +44,10 @@ const useStyles = makeStyles({
'& > *:last-child': {
marginBottom: 24
}
},
dropdownField: {
marginTop: 16,
minWidth: 155
}
})

Expand Down Expand Up @@ -155,6 +155,14 @@ const entryTypeSchema = Yup.lazy(values => {
}
})

const customInfoRequirementSchema = Yup.lazy(values => {
if (R.isNil(values.customInfoRequirement)) {
return Yup.object().shape({
customInfoRequirement: Yup.string().required()
})
}
})

const customFileSchema = Yup.object().shape({
title: Yup.string().required(),
file: Yup.mixed().required()
Expand Down Expand Up @@ -222,11 +230,9 @@ const EntryType = ({ customInfoRequirementOptions }) => {
component={RadioGroup}
name="requirement"
options={
requirementOptions
// TODO: Enable once custom info requirement manual entry is finished
// !R.isEmpty(customInfoRequirementOptions)
// ? updateRequirementOptions(requirementOptions)
// : requirementOptions
!R.isEmpty(customInfoRequirementOptions)
? updateRequirementOptions(requirementOptions)
: requirementOptions
}
labelClassName={classes.label}
radioClassName={classes.radio}
Expand All @@ -238,7 +244,12 @@ const EntryType = ({ customInfoRequirementOptions }) => {
)
}

const ManualDataEntry = ({ selectedValues, customInfoRequirementOptions }) => {
const ManualDataEntry = ({
selectedValues,
customInfoRequirementOptions,
customInfoRequirements,
selectedCustomInfoRequirement
}) => {
const classes = useStyles()

const typeOfEntrySelected = selectedValues?.entryType
Expand Down Expand Up @@ -271,21 +282,39 @@ const ManualDataEntry = ({ selectedValues, customInfoRequirementOptions }) => {
requirementSelected === 'frontCamera'
: dataTypeSelected === 'file' || dataTypeSelected === 'image'

const customInfoRequirementType = R.view(
R.lensPath([0, 'customRequest', 'input', 'type']),
R.filter(it => it.id === selectedCustomInfoRequirement)(
customInfoRequirements
)
)

console.log(customInfoRequirementType)

return (
<>
<Box display="flex" alignItems="center">
<H4>{title}</H4>
</Box>
{isCustomInfoRequirement && (
<Autocomplete
fullWidth
label={`Available requests`}
className={classes.picker}
getOptionSelected={R.eqProps('code')}
labelProp={'display'}
options={customInfoRequirementOptions}
onChange={(evt, it) => {}}
/>
<div>
<Field
className={classes.dropdownField}
component={Dropdown}
label="Available requests"
name="customInfoRequirement"
options={customInfoRequirementOptions}
/>
{(customInfoRequirementType === 'text' ||
customInfoRequirementType === 'numerical') && (
<div>{console.log('')}</div>
)}
{customInfoRequirementType === 'choiceList' && (
<div>
<div>{console.log('')}</div>
</div>
)}
</div>
)}
<div className={classes.field}>
{!upload &&
Expand Down Expand Up @@ -421,6 +450,8 @@ const customerDataSchemas = {
})
}

const customInfoRequirementElements = {}

const requirementElements = {
idCardData: {
schema: customerDataSchemas.idCardData,
Expand Down Expand Up @@ -459,7 +490,8 @@ const requirementElements = {
saveType: 'customerDataUpload'
},
custom: {
// schema: customerDataSchemas.customInfoRequirement,
schema: customInfoRequirementSchema,
options: customInfoRequirementElements,
Component: ManualDataEntry,
initialValues: { customInfoRequirement: null },
saveType: 'customInfoRequirement'
Expand Down

0 comments on commit 59fcc40

Please sign in to comment.