diff --git a/src/createReservation.tsx b/src/createReservation.tsx index b454eea..7da0d83 100644 --- a/src/createReservation.tsx +++ b/src/createReservation.tsx @@ -6,7 +6,7 @@ import StoreSelect from './storeSelect'; import ProductTable from './productTable'; interface CreateReservationProps { - // createReservation: Function + createReservation: Function } const Form = styled.form` @@ -30,7 +30,7 @@ const Button = styled.button` width: 200px; `; -const CreateReservation = React.memo(({ /* createReservation */ }: CreateReservationProps) => { +const CreateReservation = React.memo(({ createReservation }: CreateReservationProps) => { const [reservationProducts, setReservationProducts] = React.useState<{ [key: string]: number }>({}); const [storeId, setStoreId] = React.useState(''); const onChangeQuantity = React.useCallback((productId: string, quantity: string) => { @@ -42,7 +42,14 @@ const CreateReservation = React.memo(({ /* createReservation */ }: CreateReserva const onSubmit = React.useCallback((e) => { e.preventDefault(); - + createReservation({ + variables: { + reservationProducts: Object.keys(reservationProducts).map(productId => ({ + productId, + quantity: reservationProducts[productId] + })) + } + }); }, [reservationProducts]); return ( @@ -55,4 +62,8 @@ const CreateReservation = React.memo(({ /* createReservation */ }: CreateReserva ); }); -export default CreateReservation; + +export default compose( + graphql(mutations.createReservation, { name: 'createReservation' }) +)(CreateReservation); + diff --git a/src/mutations.graphql b/src/mutations.graphql index e69de29..3643ec2 100644 --- a/src/mutations.graphql +++ b/src/mutations.graphql @@ -0,0 +1,11 @@ +input ReservationProductInput { + productId: ID + quantity: Int +} + +mutation createReservation($reservationProducts: [ReservationProductInput]) { + createReservation(input: { reservationProducts: $reservationProducts }) { + date + id + } +} \ No newline at end of file diff --git a/src/productTable.tsx b/src/productTable.tsx index 396c393..4822871 100644 --- a/src/productTable.tsx +++ b/src/productTable.tsx @@ -60,7 +60,9 @@ const ProductTable = React.memo(({ onChangeQuantity, storeId }: ProductTableProp {description} € {price.toFixed(2)} - + + + }) }