Files
bodyshop/client/src/components/profile-shops/profile-shops.container.jsx
2021-02-24 08:48:55 -08:00

38 lines
1.1 KiB
JavaScript

import React from "react";
import { useQuery, useMutation } from "@apollo/client";
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 [updateAssocation] = useMutation(UPDATE_ASSOCIATION);
const updateActiveShop = (activeShopId) => {
logImEXEvent("profile_change_active_shop");
data.associations.forEach((record) => {
updateAssocation({
variables: {
assocId: record.id,
assocActive: record.id === activeShopId ? true : false,
},
});
});
refetch();
};
if (error) return <AlertComponent type="error" message={error.message} />;
return (
<ProfileShopsComponent
loading={loading}
data={data ? data.associations : null}
updateActiveShop={updateActiveShop}
/>
);
}