Update associations issues.

This commit is contained in:
Patrick Fic
2021-04-23 09:46:34 -07:00
parent 8688582bec
commit 75b1c080d6
6 changed files with 100 additions and 24 deletions

View File

@@ -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 <AlertComponent type="error" message={error.message} />;

View File

@@ -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"),

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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: