diff --git a/client/src/components/profile-shops/profile-shops.container.jsx b/client/src/components/profile-shops/profile-shops.container.jsx index ffd195629..c5564b5ae 100644 --- a/client/src/components/profile-shops/profile-shops.container.jsx +++ b/client/src/components/profile-shops/profile-shops.container.jsx @@ -1,29 +1,34 @@ +import { useMutation, useQuery } from "@apollo/client"; import React from "react"; -import { useQuery, useMutation } from "@apollo/client"; +import { logImEXEvent } from "../../firebase/firebase.utils"; import { QUERY_ALL_ASSOCIATIONS, UPDATE_ASSOCIATION, } from "../../graphql/associations.queries"; import AlertComponent from "../alert/alert.component"; import ProfileShopsComponent from "./profile-shops.component"; -import { logImEXEvent } from "../../firebase/firebase.utils"; export default function ProfileShopsContainer() { - const { loading, error, data, refetch } = useQuery(QUERY_ALL_ASSOCIATIONS); + const { loading, error, data } = useQuery(QUERY_ALL_ASSOCIATIONS); const [updateAssocation] = useMutation(UPDATE_ASSOCIATION); - const updateActiveShop = (activeShopId) => { + const updateActiveShop = async (activeShopId) => { logImEXEvent("profile_change_active_shop"); - data.associations.forEach((record) => { - updateAssocation({ - variables: { - assocId: record.id, - assocActive: record.id === activeShopId ? true : false, - }, - }); - }); - refetch(); + await Promise.all( + data.associations.map(async (record) => { + await updateAssocation({ + variables: { + assocId: record.id, + assocActive: record.id === activeShopId ? true : false, + }, + }); + }) + ); + + //Force window refresh. + + window.location.reload(); }; if (error) return ; diff --git a/client/src/components/shop-users/shop-users.component.jsx b/client/src/components/shop-users/shop-users.component.jsx index 4d5af6b82..0556e0886 100644 --- a/client/src/components/shop-users/shop-users.component.jsx +++ b/client/src/components/shop-users/shop-users.component.jsx @@ -1,15 +1,32 @@ +import { useQuery } from "@apollo/client"; import { Button, Table } from "antd"; import React from "react"; -import { useQuery } from "@apollo/client"; import { useTranslation } from "react-i18next"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; import { QUERY_SHOP_ASSOCIATIONS } from "../../graphql/user.queries"; +import { selectBodyshop } from "../../redux/user/user.selectors"; import AlertComponent from "../alert/alert.component"; import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component"; import ShopUsersAuthEdit from "../shop-users-auth-edit/shop-users-auth-edit.component"; -export default function ShopInfoUsersComponent() { +const mapStateToProps = createStructuredSelector({ + //currentUser: selectCurrentUser + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect( + mapStateToProps, + mapDispatchToProps +)(ShopInfoUsersComponent); + +export function ShopInfoUsersComponent({ bodyshop }) { const { t } = useTranslation(); - const { loading, error, data } = useQuery(QUERY_SHOP_ASSOCIATIONS); + const { loading, error, data } = useQuery(QUERY_SHOP_ASSOCIATIONS, { + variables: { shopid: bodyshop.id }, + }); const columns = [ { title: t("user.fields.email"), diff --git a/client/src/graphql/user.queries.js b/client/src/graphql/user.queries.js index d3c6d2472..797a4da52 100644 --- a/client/src/graphql/user.queries.js +++ b/client/src/graphql/user.queries.js @@ -1,8 +1,8 @@ import { gql } from "@apollo/client"; export const QUERY_SHOP_ASSOCIATIONS = gql` - query QUERY_SHOP_ASSOCIATIONS { - associations { + query QUERY_SHOP_ASSOCIATIONS($shopid: uuid!) { + associations(where: { shopid: { _eq: $shopid } }) { id authlevel shopid diff --git a/hasura/migrations/1619194947063_update_permission_user_public_table_associations/down.yaml b/hasura/migrations/1619194947063_update_permission_user_public_table_associations/down.yaml new file mode 100644 index 000000000..fcae8dd99 --- /dev/null +++ b/hasura/migrations/1619194947063_update_permission_user_public_table_associations/down.yaml @@ -0,0 +1,30 @@ +- args: + role: user + table: + name: associations + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - active + - authlevel + - id + - shopid + - useremail + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: associations + schema: public + type: create_select_permission diff --git a/hasura/migrations/1619194947063_update_permission_user_public_table_associations/up.yaml b/hasura/migrations/1619194947063_update_permission_user_public_table_associations/up.yaml new file mode 100644 index 000000000..ee45bef73 --- /dev/null +++ b/hasura/migrations/1619194947063_update_permission_user_public_table_associations/up.yaml @@ -0,0 +1,27 @@ +- args: + role: user + table: + name: associations + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - active + - authlevel + - id + - shopid + - useremail + computed_fields: [] + filter: + bodyshop: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: associations + schema: public + type: create_select_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index 874cb182b..f97c8c6a9 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -206,12 +206,9 @@ tables: filter: bodyshop: associations: - _and: - - user: - authid: - _eq: X-Hasura-User-Id - - active: - _eq: true + user: + authid: + _eq: X-Hasura-User-Id update_permissions: - role: user permission: