Update associations issues.
This commit is contained in:
@@ -1,29 +1,34 @@
|
|||||||
|
import { useMutation, useQuery } from "@apollo/client";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useQuery, useMutation } from "@apollo/client";
|
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||||
import {
|
import {
|
||||||
QUERY_ALL_ASSOCIATIONS,
|
QUERY_ALL_ASSOCIATIONS,
|
||||||
UPDATE_ASSOCIATION,
|
UPDATE_ASSOCIATION,
|
||||||
} from "../../graphql/associations.queries";
|
} from "../../graphql/associations.queries";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
import ProfileShopsComponent from "./profile-shops.component";
|
import ProfileShopsComponent from "./profile-shops.component";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
|
||||||
|
|
||||||
export default function ProfileShopsContainer() {
|
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 [updateAssocation] = useMutation(UPDATE_ASSOCIATION);
|
||||||
|
|
||||||
const updateActiveShop = (activeShopId) => {
|
const updateActiveShop = async (activeShopId) => {
|
||||||
logImEXEvent("profile_change_active_shop");
|
logImEXEvent("profile_change_active_shop");
|
||||||
|
|
||||||
data.associations.forEach((record) => {
|
await Promise.all(
|
||||||
updateAssocation({
|
data.associations.map(async (record) => {
|
||||||
variables: {
|
await updateAssocation({
|
||||||
assocId: record.id,
|
variables: {
|
||||||
assocActive: record.id === activeShopId ? true : false,
|
assocId: record.id,
|
||||||
},
|
assocActive: record.id === activeShopId ? true : false,
|
||||||
});
|
},
|
||||||
});
|
});
|
||||||
refetch();
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
//Force window refresh.
|
||||||
|
|
||||||
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error) return <AlertComponent type="error" message={error.message} />;
|
if (error) return <AlertComponent type="error" message={error.message} />;
|
||||||
|
|||||||
@@ -1,15 +1,32 @@
|
|||||||
|
import { useQuery } from "@apollo/client";
|
||||||
import { Button, Table } from "antd";
|
import { Button, Table } from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useQuery } from "@apollo/client";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { createStructuredSelector } from "reselect";
|
||||||
import { QUERY_SHOP_ASSOCIATIONS } from "../../graphql/user.queries";
|
import { QUERY_SHOP_ASSOCIATIONS } from "../../graphql/user.queries";
|
||||||
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";
|
||||||
import ShopUsersAuthEdit from "../shop-users-auth-edit/shop-users-auth-edit.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 { t } = useTranslation();
|
||||||
const { loading, error, data } = useQuery(QUERY_SHOP_ASSOCIATIONS);
|
const { loading, error, data } = useQuery(QUERY_SHOP_ASSOCIATIONS, {
|
||||||
|
variables: { shopid: bodyshop.id },
|
||||||
|
});
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: t("user.fields.email"),
|
title: t("user.fields.email"),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { gql } from "@apollo/client";
|
import { gql } from "@apollo/client";
|
||||||
|
|
||||||
export const QUERY_SHOP_ASSOCIATIONS = gql`
|
export const QUERY_SHOP_ASSOCIATIONS = gql`
|
||||||
query QUERY_SHOP_ASSOCIATIONS {
|
query QUERY_SHOP_ASSOCIATIONS($shopid: uuid!) {
|
||||||
associations {
|
associations(where: { shopid: { _eq: $shopid } }) {
|
||||||
id
|
id
|
||||||
authlevel
|
authlevel
|
||||||
shopid
|
shopid
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -206,12 +206,9 @@ tables:
|
|||||||
filter:
|
filter:
|
||||||
bodyshop:
|
bodyshop:
|
||||||
associations:
|
associations:
|
||||||
_and:
|
user:
|
||||||
- user:
|
authid:
|
||||||
authid:
|
_eq: X-Hasura-User-Id
|
||||||
_eq: X-Hasura-User-Id
|
|
||||||
- active:
|
|
||||||
_eq: true
|
|
||||||
update_permissions:
|
update_permissions:
|
||||||
- role: user
|
- role: user
|
||||||
permission:
|
permission:
|
||||||
|
|||||||
Reference in New Issue
Block a user