// By JCH, 20211121
// Using the ApolloClient Hook to create our own custom Hook

import { gql, useMutation } from "@apollo/client";

const setOrderInfoAPI = gql`
  mutation setOrderInfo($orderInfo: orderInfoInput) {
    setOrderInfo(orderInfo: $orderInfo)
  }
`;

// custom hook for mutation
const useSetOrder = () => {
  // Hook for update
  const setOrder = (orderInfo) => {
    // call the hook
    updateOrderData({ variables: { orderInfo: orderInfo } });
  };

  // Apollo useMutation Hook
  const [updateOrderData, { results }] = useMutation(setOrderInfoAPI);
  return [{ results }, setOrder];
};

export { useSetOrder };
