mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
handle error and loading state
This commit is contained in:
@@ -1,18 +1,69 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import Title from "../../components/layout/Title";
|
||||
import {
|
||||
fetchConfig,
|
||||
getFetchConfigFailure,
|
||||
isFetchConfigPending
|
||||
} from "../modules/config";
|
||||
import connect from "react-redux/es/connect/connect";
|
||||
import ErrorPage from "../../components/ErrorPage";
|
||||
import Loading from "../../components/Loading";
|
||||
|
||||
type Props = {
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
|
||||
// context objects
|
||||
t: string => string
|
||||
t: string => string,
|
||||
fetchConfig: void => void
|
||||
};
|
||||
|
||||
class GlobalConfig extends React.Component<Props> {
|
||||
render() {
|
||||
const { t } = this.props;
|
||||
componentDidMount() {
|
||||
this.props.fetchConfig();
|
||||
}
|
||||
|
||||
return <Title title={t("config.title")} />;
|
||||
render() {
|
||||
const { t, error, loading } = this.props;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("global-config.error-title")}
|
||||
subtitle={t("global-config.error-subtitle")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return <Title title={t("global-config.title")} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("config")(GlobalConfig);
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchConfig: () => {
|
||||
dispatch(fetchConfig());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const loading = isFetchConfigPending(state);
|
||||
const error = getFetchConfigFailure(state);
|
||||
|
||||
return {
|
||||
loading,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("config")(GlobalConfig));
|
||||
|
||||
Reference in New Issue
Block a user