Improve changing active shop profile methods to avoid multiple queries.
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -39,7 +39,7 @@ export default function ProfileShopsComponent({
|
||||
),
|
||||
},
|
||||
];
|
||||
console.log("🚀 ~ file: profile-shops.component.jsx:45 ~ data", data);
|
||||
|
||||
const filteredData =
|
||||
search === ""
|
||||
? data
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ export default function ShopUsersAuthEdit({ association }) {
|
||||
</div>
|
||||
)}
|
||||
{!visible && (
|
||||
<div style={{ cursor: "pointer" }} onClick={() => setVisible(true)}>
|
||||
<div
|
||||
style={{ cursor: "pointer" }} //onClick={() => setVisible(true)}
|
||||
>
|
||||
{association.authlevel || t("general.labels.na")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user