done 3
This commit is contained in:
parent
9c91ac9867
commit
fa3f31133a
|
@ -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<string>('');
|
||||
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);
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
input ReservationProductInput {
|
||||
productId: ID
|
||||
quantity: Int
|
||||
}
|
||||
|
||||
mutation createReservation($reservationProducts: [ReservationProductInput]) {
|
||||
createReservation(input: { reservationProducts: $reservationProducts }) {
|
||||
date
|
||||
id
|
||||
}
|
||||
}
|
|
@ -60,7 +60,9 @@ const ProductTable = React.memo(({ onChangeQuantity, storeId }: ProductTableProp
|
|||
<Description>{description}</Description>
|
||||
</td>
|
||||
<PriceTd>€ {price.toFixed(2)}</PriceTd>
|
||||
|
||||
<QuantityTd>
|
||||
<QuantitySelect id={id} onChange={onChangeQuantity} />
|
||||
</QuantityTd>
|
||||
</Tr>
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue