Skip to content

Commit

Permalink
Add handleSubmit for cart submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
otttooming committed Mar 18, 2018
1 parent 4d2a9ab commit 1dbe3b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/components/checkoutView/CheckoutView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ import ProductsListing from "../productsListing/ProductsListing";
interface Props {
productsInCart: ProductProps[] | undefined;
onLocationChange?: (props: LocationChangeProps) => void;
handleSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
}

const CheckoutView = ({ productsInCart, onLocationChange }: Props) => {
const CheckoutView = ({
productsInCart,
onLocationChange,
handleSubmit,
}: Props) => {
return (
<>
<section className="bg__common mb1 p1">
Expand All @@ -33,7 +38,10 @@ const CheckoutView = ({ productsInCart, onLocationChange }: Props) => {
/>
</section>

<ContactForm onLocationChange={onLocationChange} />
<ContactForm
handleSubmit={handleSubmit}
onLocationChange={onLocationChange}
/>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/contactForm/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AdditionalInformation from "./children/AdditionalInformation";
import { LocationChangeProps } from "../../common/products/typings";

interface Props {
handleSubmit?: any;
handleSubmit?: (event: React.FormEvent<HTMLFormElement>) => void;
paymentGateways?: any;
shippingMethods?: any;
onLocationChange: (props: LocationChangeProps) => void;
Expand Down
14 changes: 14 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import PageView from "../components/pageView/PageView";
import { PageProps } from "../services/pageApi/pageApi";
import { getMultipleSingleProducts } from "../services/productApi/singleProductApi";
import { calculateShoppingCartPrice } from "../services/pricing/pricing";
import { buildOrder } from "../services/orderApi/helpers";

interface Props extends InjectedFormProps {
categories: CategoryProps[];
Expand Down Expand Up @@ -189,6 +190,17 @@ class IndexPage extends React.Component<Props, State> {
});
};

handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

const { formValues } = this.props;
const { productsInCart } = this.state;

const order = buildOrder(formValues, productsInCart);

console.log("handleSubmit", order);
};

render() {
const { menuItems, categories, formValues } = this.props;
const { navRouting } = this.state;
Expand Down Expand Up @@ -267,6 +279,7 @@ class IndexPage extends React.Component<Props, State> {
!this.state.productsInCart ? undefined : this.state.productsInCart
}
onLocationChange={this.handleLocationChange}
handleSubmit={this.handleSubmit}
/>
)}

Expand All @@ -276,6 +289,7 @@ class IndexPage extends React.Component<Props, State> {
!this.state.productsInCart ? undefined : this.state.productsInCart
}
onLocationChange={this.handleLocationChange}
handleSubmit={this.handleSubmit}
/>
)}

Expand Down

0 comments on commit 1dbe3b8

Please sign in to comment.