2018-08-09 10:18:12 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-08-09 11:34:23 +02:00
|
|
|
import Title from "../../components/layout/Title";
|
2018-08-09 12:09:50 +02:00
|
|
|
import {
|
|
|
|
|
fetchConfig,
|
|
|
|
|
getFetchConfigFailure,
|
2018-08-13 16:35:43 +02:00
|
|
|
isFetchConfigPending,
|
|
|
|
|
getConfig,
|
|
|
|
|
modifyConfig,
|
2018-08-16 10:55:39 +02:00
|
|
|
isModifyConfigPending,
|
|
|
|
|
getConfigUpdatePermission
|
2018-08-09 12:09:50 +02:00
|
|
|
} from "../modules/config";
|
|
|
|
|
import connect from "react-redux/es/connect/connect";
|
|
|
|
|
import ErrorPage from "../../components/ErrorPage";
|
2018-08-13 16:35:43 +02:00
|
|
|
import type { Config } from "../types/Config";
|
|
|
|
|
import ConfigForm from "../components/form/ConfigForm";
|
2018-08-09 12:09:50 +02:00
|
|
|
import Loading from "../../components/Loading";
|
2018-08-13 16:35:43 +02:00
|
|
|
import type { User } from "../../users/types/User";
|
|
|
|
|
import type { History } from "history";
|
2018-08-09 10:18:12 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-08-09 12:09:50 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
2018-08-13 16:35:43 +02:00
|
|
|
config: Config,
|
2018-08-16 10:55:39 +02:00
|
|
|
configUpdatePermission: boolean,
|
2018-08-13 16:35:43 +02:00
|
|
|
// dispatch functions
|
|
|
|
|
modifyConfig: (config: User, callback?: () => void) => void,
|
2018-08-09 10:18:12 +02:00
|
|
|
// context objects
|
2018-08-09 12:09:50 +02:00
|
|
|
t: string => string,
|
2018-08-13 16:35:43 +02:00
|
|
|
fetchConfig: void => void,
|
|
|
|
|
history: History
|
2018-08-09 10:18:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GlobalConfig extends React.Component<Props> {
|
2018-08-13 16:35:43 +02:00
|
|
|
configModified = (config: Config) => () => {
|
2018-08-16 10:55:39 +02:00
|
|
|
this.props.fetchConfig();
|
2018-08-13 16:35:43 +02:00
|
|
|
this.props.history.push(`/config`);
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-09 12:09:50 +02:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.fetchConfig();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 16:35:43 +02:00
|
|
|
modifyConfig = (config: Config) => {
|
2018-08-16 10:55:39 +02:00
|
|
|
console.log(config);
|
2018-08-13 16:35:43 +02:00
|
|
|
this.props.modifyConfig(config, this.configModified(config));
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-09 10:18:12 +02:00
|
|
|
render() {
|
2018-08-16 10:55:39 +02:00
|
|
|
const { t, error, loading, config, configUpdatePermission } = this.props;
|
2018-08-09 12:09:50 +02:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
|
|
|
|
title={t("global-config.error-title")}
|
|
|
|
|
subtitle={t("global-config.error-subtitle")}
|
|
|
|
|
error={error}
|
2018-08-16 10:55:39 +02:00
|
|
|
configUpdatePermission={configUpdatePermission}
|
2018-08-09 12:09:50 +02:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
2018-08-09 10:18:12 +02:00
|
|
|
|
2018-08-13 16:35:43 +02:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Title title={t("global-config.title")} />
|
|
|
|
|
<ConfigForm
|
|
|
|
|
submitForm={config => this.modifyConfig(config)}
|
|
|
|
|
config={config}
|
|
|
|
|
loading={loading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2018-08-09 10:18:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 12:09:50 +02:00
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchConfig: () => {
|
|
|
|
|
dispatch(fetchConfig());
|
2018-08-13 16:35:43 +02:00
|
|
|
},
|
|
|
|
|
modifyConfig: (config: Config, callback?: () => void) => {
|
|
|
|
|
dispatch(modifyConfig(config, callback));
|
2018-08-09 12:09:50 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
2018-08-13 16:35:43 +02:00
|
|
|
const loading = isFetchConfigPending(state) || isModifyConfigPending(state); //TODO: Button lädt so nicht, sondern gesamte Seite
|
2018-08-09 12:09:50 +02:00
|
|
|
const error = getFetchConfigFailure(state);
|
2018-08-13 16:35:43 +02:00
|
|
|
const config = getConfig(state);
|
2018-08-16 10:55:39 +02:00
|
|
|
const configUpdatePermission = getConfigUpdatePermission(state);
|
2018-08-09 12:09:50 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loading,
|
2018-08-13 16:35:43 +02:00
|
|
|
error,
|
2018-08-16 10:55:39 +02:00
|
|
|
config,
|
|
|
|
|
configUpdatePermission
|
2018-08-09 12:09:50 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(translate("config")(GlobalConfig));
|