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} />;