38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import { useQuery } from "@apollo/client";
|
|
import React, { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import AlertComponent from "../../components/alert/alert.component";
|
|
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
|
import { QUERY_BODYSHOP } from "../../graphql/bodyshop.queries";
|
|
import { setBodyshop } from "../../redux/user/user.actions";
|
|
//import "../../utils/RegisterSw";
|
|
import ManagePage from "./manage.page.component";
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
setBodyshop: (bs) => dispatch(setBodyshop(bs)),
|
|
});
|
|
|
|
function ManagePageContainer({ match, setBodyshop }) {
|
|
const { loading, error, data } = useQuery(QUERY_BODYSHOP, {
|
|
fetchPolicy: "network-only",
|
|
nextFetchPolicy: "network-only",
|
|
});
|
|
|
|
const { t } = useTranslation();
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
setBodyshop(data.bodyshops[0] || { notfound: true });
|
|
}
|
|
}, [data, setBodyshop]);
|
|
|
|
if (loading)
|
|
return <LoadingSpinner message={t("general.labels.loadingshop")} />;
|
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
|
|
|
return <ManagePage match={match} />;
|
|
}
|
|
|
|
export default connect(null, mapDispatchToProps)(ManagePageContainer);
|