Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set custom info requirement live values #1057

Open
wants to merge 2 commits into
base: future-stuff-old-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -472,11 +472,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 @@ -661,7 +657,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}
selectedCustomInfoRequirementLive={
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
89 changes: 68 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 All @@ -178,6 +186,20 @@ const updateRequirementOptions = it => [
...it
]

const getCustomInfoRequirementType = R.view(
R.lensPath(['customRequest', 'input', 'type'])
)

const buildCustomInfoRequirementElements = customInfoRequirements => {
R.forEach(it => {
switch (getCustomInfoRequirementType(it)) {
case 'numerical' || 'text':
default:
break
}
}, customInfoRequirements)
}

const EntryType = ({ customInfoRequirementOptions }) => {
const classes = useStyles()
const { values } = useFormikContext()
Expand Down Expand Up @@ -222,11 +244,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 +258,12 @@ const EntryType = ({ customInfoRequirementOptions }) => {
)
}

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

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

const customInfoRequirementType = getCustomInfoRequirementType(
R.head(
R.filter(it => it.id === selectedCustomInfoRequirementLive)(
customInfoRequirements
)
)
)

const customInfoRequirementElements = !R.isNil(customInfoRequirements)
? buildCustomInfoRequirementElements(customInfoRequirements)
: []
console.log(customInfoRequirementElements, customInfoRequirements)

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>
Comment on lines +331 to +333
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers?

)}
</div>
)}
<div className={classes.field}>
{!upload &&
Expand Down Expand Up @@ -459,7 +506,7 @@ const requirementElements = {
saveType: 'customerDataUpload'
},
custom: {
// schema: customerDataSchemas.customInfoRequirement,
schema: customInfoRequirementSchema,
Component: ManualDataEntry,
initialValues: { customInfoRequirement: null },
saveType: 'customInfoRequirement'
Expand Down