fix(ui): wait for org to be available then fetch org settings just once
parent
020f895013
commit
a2f1a5073d
|
@ -1,34 +1,56 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
import {PureComponent} from 'react'
|
import {FunctionComponent, useEffect, useState} from 'react'
|
||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
|
import {get} from 'lodash'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import {CLOUD} from 'src/shared/constants'
|
import {CLOUD} from 'src/shared/constants'
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import {AppState, Organization} from 'src/types'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import {getOrgSettings as getOrgSettingsAction} from 'src/cloud/actions/orgsettings'
|
import {getOrgSettings as getOrgSettingsAction} from 'src/cloud/actions/orgsettings'
|
||||||
|
|
||||||
|
interface PassedInProps {
|
||||||
|
children: React.ReactElement<any>
|
||||||
|
}
|
||||||
|
interface StateProps {
|
||||||
|
org: Organization
|
||||||
|
}
|
||||||
interface DispatchProps {
|
interface DispatchProps {
|
||||||
getOrgSettings: typeof getOrgSettingsAction
|
getOrgSettings: typeof getOrgSettingsAction
|
||||||
}
|
}
|
||||||
|
|
||||||
class OrgSettings extends PureComponent<DispatchProps> {
|
type Props = StateProps & DispatchProps & PassedInProps
|
||||||
public componentDidMount() {
|
|
||||||
if (CLOUD) {
|
|
||||||
this.props.getOrgSettings()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
const OrgSettings: FunctionComponent<Props> = ({
|
||||||
return this.props.children
|
org,
|
||||||
}
|
getOrgSettings,
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
const [hasFetchedOrgSettings, setHasFetchedOrgSettings] = useState<boolean>(
|
||||||
|
false
|
||||||
|
)
|
||||||
|
useEffect(() => {
|
||||||
|
if (CLOUD && org && !hasFetchedOrgSettings) {
|
||||||
|
setHasFetchedOrgSettings(true)
|
||||||
|
getOrgSettings()
|
||||||
|
}
|
||||||
|
}, [org])
|
||||||
|
|
||||||
|
return children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mstp = (state: AppState): StateProps => ({
|
||||||
|
org: get(state, 'resources.orgs.org', null),
|
||||||
|
})
|
||||||
|
|
||||||
const mdtp: DispatchProps = {
|
const mdtp: DispatchProps = {
|
||||||
getOrgSettings: getOrgSettingsAction,
|
getOrgSettings: getOrgSettingsAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect<{}, DispatchProps, {}>(
|
export default connect<StateProps, DispatchProps, PassedInProps>(
|
||||||
null,
|
mstp,
|
||||||
mdtp
|
mdtp
|
||||||
)(OrgSettings)
|
)(OrgSettings)
|
||||||
|
|
Loading…
Reference in New Issue