source: frontend/src/screens/PaymentMethodScreen.js@ 55ed171

Last change on this file since 55ed171 was 16237c4, checked in by Nace Gjorgjievski <nace.gorgievski123@…>, 22 months ago

Added Order Functionality

  • Property mode set to 100644
File size: 2.6 KB
Line 
1import React, { useContext, useEffect, useState } from "react";
2import { Helmet } from "react-helmet-async";
3import CheckoutSteps from "../components/CheckoutSteps";
4import Container from "react-bootstrap/Container";
5import Button from "react-bootstrap/Button";
6import Form from "react-bootstrap/Form";
7import { Store } from "../Store";
8import { useNavigate } from "react-router-dom";
9import CreditCardIcon from "@mui/icons-material/CreditCard";
10
11function PaymentMethodScreen() {
12 const navigate = useNavigate();
13 const { state, dispatch: ctxDispatch } = useContext(Store);
14 const {
15 cart: { shippingAddress, paymentMethod },
16 } = state;
17 const [paymentMethodName, setPaymentMethod] = useState(
18 paymentMethod || "Karticka"
19 );
20
21 useEffect(() => {
22 if (!shippingAddress.address) {
23 navigate("/shipping");
24 }
25 }, [shippingAddress, navigate]);
26 const submitHandler = (e) => {
27 e.preventDefault();
28 ctxDispatch({ type: "SAVE_PAYMENT_METHOD", payload: paymentMethodName });
29 localStorage.setItem("paymentMethod", paymentMethodName);
30 navigate("/placeorder");
31 };
32 return (
33 <div className="pageContainer shipPC">
34 <CheckoutSteps step1 step2 step3 />
35 <Container className="main">
36 <Helmet>
37 <title>Начин на наплата</title>
38 </Helmet>
39 <h1 style={{ marginTop: "10px" }}>Начин на наплата</h1>
40 <Form
41 onSubmit={submitHandler}
42 style={{
43 display: "flex",
44 flexDirection: "column",
45 alignItems: "center",
46 }}
47 >
48 <div className="radioContainer" style={{ marginTop: "10px" }}>
49 <Form.Check
50 type="radio"
51 id="Karticka"
52 label="Со платежна картичка"
53 value="Karticka"
54 checked={paymentMethodName === "Karticka"}
55 onChange={(e) => setPaymentMethod(e.target.value)}
56 />
57 </div>
58 <div className="radioContainer" style={{ marginTop: "10px" }}>
59 <Form.Check
60 type="radio"
61 id="voGotovo"
62 label="Во готово при достава"
63 value="voGotovo"
64 checked={paymentMethodName === "voGotovo"}
65 onChange={(e) => setPaymentMethod(e.target.value)}
66 />
67 </div>
68 <div style={{ marginTop: "20px" }}>
69 <Button variant="danger" type="submit">
70 Продолжи
71 </Button>
72 </div>
73 </Form>
74 </Container>
75 </div>
76 );
77}
78
79export default PaymentMethodScreen;
Note: See TracBrowser for help on using the repository browser.