Update associations issues.
This commit is contained in:
@@ -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} />;
|
||||
|
||||
Reference in New Issue
Block a user