Change shop association.
This commit is contained in:
@@ -1,15 +1,27 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useQuery } from "react-apollo";
|
import { useQuery, useMutation } from "react-apollo";
|
||||||
import { QUERY_ALL_ASSOCIATIONS } from "../../graphql/associations.queries";
|
import {
|
||||||
|
QUERY_ALL_ASSOCIATIONS,
|
||||||
|
UPDATE_ASSOCIATION
|
||||||
|
} from "../../graphql/associations.queries";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
import ProfileShopsComponent from "./profile-shops.component";
|
import ProfileShopsComponent from "./profile-shops.component";
|
||||||
|
|
||||||
export default function ProfileShopsContainer() {
|
export default function ProfileShopsContainer() {
|
||||||
|
|
||||||
const { loading, error, data, refetch } = useQuery(QUERY_ALL_ASSOCIATIONS);
|
const { loading, error, data, refetch } = useQuery(QUERY_ALL_ASSOCIATIONS);
|
||||||
|
const [updateAssocation] = useMutation(UPDATE_ASSOCIATION);
|
||||||
|
|
||||||
const updateActiveShop = activeShopId => {
|
const updateActiveShop = activeShopId => {
|
||||||
console.log("activeShopId", activeShopId);
|
console.log("activeShopId", activeShopId);
|
||||||
|
|
||||||
|
data.associations.map(record => {
|
||||||
|
updateAssocation({
|
||||||
|
variables: {
|
||||||
|
assocId: record.id,
|
||||||
|
assocActive: record.id === activeShopId ? true : false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
refetch();
|
refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user