Skip to content

Commit

Permalink
Sosynpl: [premieroctet#169] Fix Address component value
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaauvray committed Aug 22, 2024
1 parent d2e4adb commit 1f11cb8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion studio-test/src/dependencies/custom-components/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsyncSelect } from 'chakra-react-select'
import React, {useState} from 'react'
import React, {useEffect, useState} from 'react'
import axios from 'axios'
import {debounce} from 'lodash'
import lodash from 'lodash'
Expand All @@ -13,6 +13,12 @@ const Address = ({children, onChange, value, isCityOnly, ...props}: {children: R
props.setComponentAttribute(props.id, props.attribute)
}

useEffect(() => {
if (props.setComponentValue) {
props.setComponentValue(props.id, address)
}
}, [address])

const addressToOption = addr => {
return addr ?
({value: addr, label : isCityOnly ? addr.city : `${addr.address}, ${addr.zip_code} ${addr.city}`})
Expand Down
4 changes: 2 additions & 2 deletions studio-test/src/dependencies/hoc/withDynamicInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ const withDynamicInput = Component => {
</InputGroup>
)
:
(<Component {...props} onChange={onChange} />)
(<Component {...props} setComponentValue={setComponentValue} onChange={onChange} />)
}

return displayEye ?
withDisplayEye(Component)
:
<Component {...props} dataSource={dataSource} onChange={onChange}/>
<Component {...props} dataSource={dataSource} setComponentValue={setComponentValue} onChange={onChange}/>
}

return Internal
Expand Down
8 changes: 7 additions & 1 deletion studio/src/dependencies/custom-components/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsyncSelect } from 'chakra-react-select'
import React, {useState} from 'react'
import React, {useEffect, useState} from 'react'
import axios from 'axios'
import {debounce} from 'lodash'
import lodash from 'lodash'
Expand All @@ -13,6 +13,12 @@ const Address = ({children, onChange, value, isCityOnly, ...props}: {children: R
props.setComponentAttribute(props.id, props.attribute)
}

useEffect(() => {
if (props.setComponentValue) {
props.setComponentValue(props.id, address)
}
}, [address])

const addressToOption = addr => {
return addr ?
({value: addr, label : isCityOnly ? addr.city : `${addr.address}, ${addr.zip_code} ${addr.city}`})
Expand Down
4 changes: 2 additions & 2 deletions studio/src/dependencies/hoc/withDynamicInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ const withDynamicInput = Component => {
</InputGroup>
)
:
(<Component {...props} onChange={onChange} />)
(<Component {...props} setComponentValue={setComponentValue} onChange={onChange} />)
}

return displayEye ?
withDisplayEye(Component)
:
<Component {...props} dataSource={dataSource} onChange={onChange}/>
<Component {...props} dataSource={dataSource} setComponentValue={setComponentValue} onChange={onChange}/>
}

return Internal
Expand Down

0 comments on commit 1f11cb8

Please sign in to comment.