Skip to content

Commit

Permalink
feat(frictions): handling default value
Browse files Browse the repository at this point in the history
  • Loading branch information
dkremniov-bc committed Jan 17, 2024
1 parent 4da4922 commit d09f317
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react'
import { FormattedMessage } from 'react-intl'
import ReactMarkdown from 'react-markdown'
import { useSelector } from 'react-redux'
import { connect, useSelector } from 'react-redux'
import { Field, getFormValues, reduxForm } from 'redux-form'

import { ExtraQuestionsType, NodeItem, NodeItemTypes, NodeTextType } from '@core/types'
Expand Down Expand Up @@ -523,6 +523,19 @@ const Success = ({
)
}

export default reduxForm<{}, Props>({
form: 'SelfClassification'
})(Success)
export default connect((_, ownProps: Props) => ({
initialValues: ownProps.nodes.reduce((acc, node) => {
if (node.type === 'SINGLE_SELECTION') {
return {
...acc,
[node.id]: node.children?.find((child) => child.checked)?.id
}
}

return acc
}, {})
}))(
reduxForm<{}, Props>({
form: 'SelfClassification'
})(Success)
)
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,6 @@ const SelfClassification = ({ close, position, total, userClickedOutside }: Moda
const showLoading = isLoading || isNotAsked
const hasSomeError = !isLoading && (showError || !!error)

// This is a hack to make default values return from BE to work.
// TODO: implement handing of default values instead
const modifiedExtraKYCResponse = extraKYCResponse
? {
...extraKYCResponse,
nodes: extraKYCResponse.nodes.map((node) => {
if (node.type === 'SINGLE_SELECTION') {
return node.children
? {
...node,
children: node?.children?.map((child) => {
return {
...child,
checked: false
}
})
}
: node
}

return node
})
}
: undefined

return (
<Flyout
position={position}
Expand All @@ -137,11 +112,11 @@ const SelfClassification = ({ close, position, total, userClickedOutside }: Moda
handler={handleClose}
/>
)}
{!isLoading && modifiedExtraKYCResponse && (
{!isLoading && extraKYCResponse && (
<>
<Header text='Self Classification Questionaire' onClickBack={handleClose} />
<SelfClassificationSuccess
{...modifiedExtraKYCResponse}
{...extraKYCResponse}
onSubmit={handleSubmit}
dataRef={dataRef}
/>
Expand Down

0 comments on commit d09f317

Please sign in to comment.