done 3
This commit is contained in:
parent
9c91ac9867
commit
fa3f31133a
|
@ -6,7 +6,7 @@ import StoreSelect from './storeSelect';
|
||||||
import ProductTable from './productTable';
|
import ProductTable from './productTable';
|
||||||
|
|
||||||
interface CreateReservationProps {
|
interface CreateReservationProps {
|
||||||
// createReservation: Function
|
createReservation: Function
|
||||||
}
|
}
|
||||||
|
|
||||||
const Form = styled.form`
|
const Form = styled.form`
|
||||||
|
@ -30,7 +30,7 @@ const Button = styled.button`
|
||||||
width: 200px;
|
width: 200px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const CreateReservation = React.memo(({ /* createReservation */ }: CreateReservationProps) => {
|
const CreateReservation = React.memo(({ createReservation }: CreateReservationProps) => {
|
||||||
const [reservationProducts, setReservationProducts] = React.useState<{ [key: string]: number }>({});
|
const [reservationProducts, setReservationProducts] = React.useState<{ [key: string]: number }>({});
|
||||||
const [storeId, setStoreId] = React.useState<string>('');
|
const [storeId, setStoreId] = React.useState<string>('');
|
||||||
const onChangeQuantity = React.useCallback((productId: string, quantity: string) => {
|
const onChangeQuantity = React.useCallback((productId: string, quantity: string) => {
|
||||||
|
@ -42,7 +42,14 @@ const CreateReservation = React.memo(({ /* createReservation */ }: CreateReserva
|
||||||
|
|
||||||
const onSubmit = React.useCallback((e) => {
|
const onSubmit = React.useCallback((e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
createReservation({
|
||||||
|
variables: {
|
||||||
|
reservationProducts: Object.keys(reservationProducts).map(productId => ({
|
||||||
|
productId,
|
||||||
|
quantity: reservationProducts[productId]
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
});
|
||||||
}, [reservationProducts]);
|
}, [reservationProducts]);
|
||||||
|
|
||||||
return (
|
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>
|
<Description>{description}</Description>
|
||||||
</td>
|
</td>
|
||||||
<PriceTd>€ {price.toFixed(2)}</PriceTd>
|
<PriceTd>€ {price.toFixed(2)}</PriceTd>
|
||||||
|
<QuantityTd>
|
||||||
|
<QuantitySelect id={id} onChange={onChangeQuantity} />
|
||||||
|
</QuantityTd>
|
||||||
</Tr>
|
</Tr>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue