Skip to content

Commit

Permalink
fix: reset changedSettings after press save
Browse files Browse the repository at this point in the history
  • Loading branch information
a110605 committed Apr 29, 2024
1 parent 9ecd35d commit 0fb2e4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/routes/setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Setting extends React.Component {
const { confirmedNavigation, changedSettings } = this.state
const isDirty = Object.keys(changedSettings).length > 0

if (nextLocation.pathname !== '/settings' && isDirty && !confirmedNavigation) {
if (isDirty && !confirmedNavigation) {
this.showModal(nextLocation)
return false // disallow navigation
}
Expand Down Expand Up @@ -72,6 +72,13 @@ class Setting extends React.Component {
}
}

resetChangedSettings = () => {
this.setState({
...this.state,
changedSettings: {},
})
}

render() {
const { setting, dispatch, loading } = this.props
const { modalVisible, changedSettings } = this.state
Expand All @@ -87,6 +94,7 @@ class Setting extends React.Component {
payload,
})
},
resetChangedSettings: this.resetChangedSettings,
onInputChange: this.onInputChange,
}

Expand Down
5 changes: 4 additions & 1 deletion src/routes/setting/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ const form = ({
loading,
onSubmit,
onInputChange,
resetChangedSettings,
}) => {
const handleOnSubmit = () => {
const fields = getFieldsValue()
Object.keys(fields).forEach(key => { fields[key] = fields[key].toString() })
onSubmit(fields)
resetChangedSettings()
}
const parseSettingRules = (setting) => {
const definition = setting.definition
Expand Down Expand Up @@ -147,7 +149,7 @@ const form = ({
))

return (
<Spin spinning={saving || loading}>
<Spin spinning={saving || loading} style={{ height: '100vh' }}>
<Form className={styles.setting}>
{settings}
</Form>
Expand All @@ -174,6 +176,7 @@ form.propTypes = {
saving: PropTypes.bool,
loading: PropTypes.bool,
onInputChange: PropTypes.func,
resetChangedSettings: PropTypes.func,
}

export default Form.create()(form)
4 changes: 0 additions & 4 deletions src/routes/setting/setting.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@
border: 1px solid #f15354;
}
}

:global .ant-spin-nested-loading{
height: 100vh;
}

0 comments on commit 0fb2e4e

Please sign in to comment.