diff --git a/client/src/components/production-list-table/production-list-table-view-select.component.jsx b/client/src/components/production-list-table/production-list-table-view-select.component.jsx index a89aca21d..044c75994 100644 --- a/client/src/components/production-list-table/production-list-table-view-select.component.jsx +++ b/client/src/components/production-list-table/production-list-table-view-select.component.jsx @@ -55,6 +55,7 @@ export function ProductionListTable({ const assoc = bodyshop.associations.find( (a) => a.useremail === currentUser.email ); + if (assoc) { await updateDefaultProdView({ variables: { assocId: assoc.id, view: value }, diff --git a/client/src/components/profile-shops/profile-shops.component.jsx b/client/src/components/profile-shops/profile-shops.component.jsx index a668d1a40..9360ed7ad 100644 --- a/client/src/components/profile-shops/profile-shops.component.jsx +++ b/client/src/components/profile-shops/profile-shops.component.jsx @@ -39,7 +39,7 @@ export default function ProfileShopsComponent({ ), }, ]; - console.log("🚀 ~ file: profile-shops.component.jsx:45 ~ data", data); + const filteredData = search === "" ? data diff --git a/client/src/components/profile-shops/profile-shops.container.jsx b/client/src/components/profile-shops/profile-shops.container.jsx index 4b3eaafe1..41bcf010f 100644 --- a/client/src/components/profile-shops/profile-shops.container.jsx +++ b/client/src/components/profile-shops/profile-shops.container.jsx @@ -3,7 +3,7 @@ import React from "react"; import { logImEXEvent } from "../../firebase/firebase.utils"; import { QUERY_ALL_ASSOCIATIONS, - UPDATE_ASSOCIATION, + UPDATE_ACTIVE_ASSOCIATION, } from "../../graphql/associations.queries"; import AlertComponent from "../alert/alert.component"; import ProfileShopsComponent from "./profile-shops.component"; @@ -13,9 +13,13 @@ import { getToken } from "firebase/messaging"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; -import { selectBodyshop } from "../../redux/user/user.selectors"; +import { + selectBodyshop, + selectCurrentUser, +} from "../../redux/user/user.selectors"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, + currentUser: selectCurrentUser, }); const mapDispatchToProps = (dispatch) => ({ //setUserLanguage: language => dispatch(setUserLanguage(language)) @@ -25,14 +29,18 @@ export default connect( mapDispatchToProps )(ProfileShopsContainer); -export function ProfileShopsContainer({ bodyshop }) { +export function ProfileShopsContainer({ bodyshop, currentUser }) { const { loading, error, data } = useQuery(QUERY_ALL_ASSOCIATIONS, { fetchPolicy: "network-only", nextFetchPolicy: "network-only", + variables: { + email: currentUser.email, + }, + skip: !currentUser, }); - const [updateAssocation] = useMutation(UPDATE_ASSOCIATION); + const [updateActiveAssociation] = useMutation(UPDATE_ACTIVE_ASSOCIATION); - const updateActiveShop = async (activeShopId) => { + const updateActiveShop = async (newActiveAssocId) => { logImEXEvent("profile_change_active_shop"); try { @@ -46,16 +54,12 @@ export function ProfileShopsContainer({ bodyshop }) { } catch (error) { console.log("No FCM token. Skipping unsubscribe."); } - await Promise.all( - data.associations.map(async (record) => { - await updateAssocation({ - variables: { - assocId: record.id, - assocActive: record.id === activeShopId ? true : false, - }, - }); - }) - ); + + await updateActiveAssociation({ + variables: { + newActiveAssocId: newActiveAssocId, + }, + }); //Force window refresh. diff --git a/client/src/components/shop-users-auth-edit/shop-users-auth-edit.component.jsx b/client/src/components/shop-users-auth-edit/shop-users-auth-edit.component.jsx index 548d2276e..d99387fe7 100644 --- a/client/src/components/shop-users-auth-edit/shop-users-auth-edit.component.jsx +++ b/client/src/components/shop-users-auth-edit/shop-users-auth-edit.component.jsx @@ -42,7 +42,9 @@ export default function ShopUsersAuthEdit({ association }) { )} {!visible && ( -