Resolve no shop access.
This commit is contained in:
@@ -7,12 +7,17 @@ import { setBodyshop } from "../../redux/user/user.actions";
|
||||
import ManagePage from "./manage.page.component";
|
||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import NoShop from "../../components/no-shop/no-shop.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop });
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setBodyshop: (bs) => dispatch(setBodyshop(bs)),
|
||||
});
|
||||
|
||||
function ManagePageContainer({ match, setBodyshop }) {
|
||||
function ManagePageContainer({ match, setBodyshop, bodyshop }) {
|
||||
const { loading, error, data } = useQuery(QUERY_BODYSHOP, {
|
||||
fetchPolicy: "network-only",
|
||||
});
|
||||
@@ -20,13 +25,19 @@ function ManagePageContainer({ match, setBodyshop }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (data) setBodyshop(data.bodyshops[0]);
|
||||
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" />;
|
||||
|
||||
if (bodyshop && bodyshop.notfound) return <NoShop />;
|
||||
|
||||
return <ManagePage match={match} />;
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(ManagePageContainer);
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(ManagePageContainer);
|
||||
|
||||
Reference in New Issue
Block a user