From ba9e91d0c8dc41a1dd6a261740ee2f074356a26d Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 5 Feb 2020 08:52:12 -0800 Subject: [PATCH] Change shop association. --- .../profile-shops/profile-shops.container.jsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/client/src/components/profile-shops/profile-shops.container.jsx b/client/src/components/profile-shops/profile-shops.container.jsx index bc85033d6..cb08bb3a3 100644 --- a/client/src/components/profile-shops/profile-shops.container.jsx +++ b/client/src/components/profile-shops/profile-shops.container.jsx @@ -1,15 +1,27 @@ import React from "react"; -import { useQuery } from "react-apollo"; -import { QUERY_ALL_ASSOCIATIONS } from "../../graphql/associations.queries"; +import { useQuery, useMutation } from "react-apollo"; +import { + QUERY_ALL_ASSOCIATIONS, + UPDATE_ASSOCIATION +} from "../../graphql/associations.queries"; import AlertComponent from "../alert/alert.component"; import ProfileShopsComponent from "./profile-shops.component"; export default function ProfileShopsContainer() { - const { loading, error, data, refetch } = useQuery(QUERY_ALL_ASSOCIATIONS); + const [updateAssocation] = useMutation(UPDATE_ASSOCIATION); const updateActiveShop = activeShopId => { console.log("activeShopId", activeShopId); + + data.associations.map(record => { + updateAssocation({ + variables: { + assocId: record.id, + assocActive: record.id === activeShopId ? true : false + } + }); + }); refetch(); };