mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
add modification of config
This commit is contained in:
@@ -4,28 +4,46 @@ import Title from "../../components/layout/Title";
|
|||||||
import {
|
import {
|
||||||
fetchConfig,
|
fetchConfig,
|
||||||
getFetchConfigFailure,
|
getFetchConfigFailure,
|
||||||
isFetchConfigPending
|
isFetchConfigPending,
|
||||||
|
getConfig,
|
||||||
|
modifyConfig,
|
||||||
|
isModifyConfigPending
|
||||||
} from "../modules/config";
|
} from "../modules/config";
|
||||||
import connect from "react-redux/es/connect/connect";
|
import connect from "react-redux/es/connect/connect";
|
||||||
import ErrorPage from "../../components/ErrorPage";
|
import ErrorPage from "../../components/ErrorPage";
|
||||||
|
import type { Config } from "../types/Config";
|
||||||
|
import ConfigForm from "../components/form/ConfigForm";
|
||||||
import Loading from "../../components/Loading";
|
import Loading from "../../components/Loading";
|
||||||
|
import type { User } from "../../users/types/User";
|
||||||
|
import type { History } from "history";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
error: Error,
|
error: Error,
|
||||||
|
config: Config,
|
||||||
|
// dispatch functions
|
||||||
|
modifyConfig: (config: User, callback?: () => void) => void,
|
||||||
// context objects
|
// context objects
|
||||||
t: string => string,
|
t: string => string,
|
||||||
fetchConfig: void => void
|
fetchConfig: void => void,
|
||||||
|
history: History
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlobalConfig extends React.Component<Props> {
|
class GlobalConfig extends React.Component<Props> {
|
||||||
|
configModified = (config: Config) => () => {
|
||||||
|
this.props.history.push(`/config`);
|
||||||
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchConfig();
|
this.props.fetchConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifyConfig = (config: Config) => {
|
||||||
|
this.props.modifyConfig(config, this.configModified(config));
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t, error, loading } = this.props;
|
const { t, error, loading, config } = this.props;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
@@ -36,12 +54,20 @@ class GlobalConfig extends React.Component<Props> {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Title title={t("global-config.title")} />;
|
return (
|
||||||
|
<div>
|
||||||
|
<Title title={t("global-config.title")} />
|
||||||
|
<ConfigForm
|
||||||
|
submitForm={config => this.modifyConfig(config)}
|
||||||
|
config={config}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,17 +75,22 @@ const mapDispatchToProps = dispatch => {
|
|||||||
return {
|
return {
|
||||||
fetchConfig: () => {
|
fetchConfig: () => {
|
||||||
dispatch(fetchConfig());
|
dispatch(fetchConfig());
|
||||||
|
},
|
||||||
|
modifyConfig: (config: Config, callback?: () => void) => {
|
||||||
|
dispatch(modifyConfig(config, callback));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const loading = isFetchConfigPending(state);
|
const loading = isFetchConfigPending(state) || isModifyConfigPending(state); //TODO: Button lädt so nicht, sondern gesamte Seite
|
||||||
const error = getFetchConfigFailure(state);
|
const error = getFetchConfigFailure(state);
|
||||||
|
const config = getConfig(state);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading,
|
loading,
|
||||||
error
|
error,
|
||||||
|
config
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user