Преглед изворни кода

done billing form

cart-api-guide
azri пре 1 недеља
родитељ
комит
cb48b87cc3

+ 145
- 0
src/components/BillingForm/BillingForm.jsx Прегледај датотеку

@@ -0,0 +1,145 @@
1
+import React, { useState } from 'react';
2
+import {
3
+  Box,
4
+  TextField,
5
+  Button,
6
+  Typography,
7
+  MenuItem,
8
+  RadioGroup,
9
+  FormControlLabel,
10
+  Radio,
11
+} from '@mui/material';
12
+import Table from '@mui/material/Table';
13
+import TableBody from '@mui/material/TableBody';
14
+import TableCell from '@mui/material/TableCell';
15
+import TableContainer from '@mui/material/TableContainer';
16
+import TableHead from '@mui/material/TableHead';
17
+import TableRow from '@mui/material/TableRow';
18
+import Grid from '@mui/material/Grid2';
19
+
20
+const BillingForm = () => {
21
+
22
+  const rows = [
23
+    {
24
+      img_src: 'https://via.placeholder.com/300',
25
+      name: 'MELUR',
26
+      description: 'Atma Sari New Raya Collection 2024',
27
+      colour: 'black',
28
+      quantity: 1,
29
+      price: 335.50
30
+    }
31
+  ];
32
+
33
+  const [shippingMethod, setShippingMethod] = useState('COD');
34
+
35
+  const handleSubmit = (e) => {
36
+    e.preventDefault();
37
+    // Handle form submission logic
38
+    console.log('Form submitted');
39
+  };
40
+
41
+  const FieldContainer = ({ label, children }) => (
42
+    <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
43
+      <Typography variant="body1" sx={{ fontWeight: 500, minWidth: 120 }}>
44
+        {label}
45
+      </Typography>
46
+      {children}
47
+    </Box>
48
+  );
49
+
50
+  return (
51
+    <Box
52
+     
53
+      onSubmit={handleSubmit}
54
+      sx={{
55
+        width: '100%',
56
+      }}
57
+    >
58
+      
59
+      {/* Product List */}
60
+      <TableContainer>
61
+          <Table sx={{ minWidth: 650, mb: 5, backgroundColor:"#F7FBFF" }}>
62
+            <TableHead>
63
+              <TableRow>
64
+                <TableCell width={150}>
65
+                  <Typography variant='body1'>Item</Typography>
66
+                </TableCell>
67
+                <TableCell width={150}>
68
+                  {/* This is just for table offset */}
69
+                  <Typography variant='body1'></Typography>
70
+                </TableCell>
71
+                <TableCell align='center'>
72
+                  <Typography variant='body1'>Colour</Typography>
73
+                </TableCell>
74
+                <TableCell align='center'>
75
+
76
+                  <Typography variant='body1'>Quantity</Typography>
77
+                </TableCell>
78
+                <TableCell align='center'>
79
+                  <Typography variant='body1'>Unit Price</Typography>
80
+                </TableCell>
81
+                <TableCell align='center'>
82
+                  <Typography variant='body1'>Shipping</Typography>
83
+                </TableCell>
84
+                <TableCell align='center'>
85
+                  <Typography variant='body1'>Tax</Typography>
86
+                </TableCell>
87
+                <TableCell align='center'>
88
+                  <Typography variant='body1'>Duties</Typography>
89
+                </TableCell>
90
+              </TableRow>
91
+            </TableHead>
92
+            <TableBody>
93
+              {rows.map((row) => (
94
+                <TableRow
95
+                  key={row.id}
96
+                  sx={{
97
+                    '& td, & th': { border: 0 },
98
+                    '&:last-child td, &:last-child th': { border: 0 }
99
+                  }}
100
+                >
101
+                  <TableCell component="th" scope="row">
102
+                    <img
103
+                      src={row.img_src}
104
+                      alt={row.img_src}
105
+                      style={{
106
+                        width: 100,
107
+                        height: 100,
108
+                        aspectRatio: '4 / 4',
109
+                        objectFit: 'cover',
110
+                      }}
111
+                    />
112
+                  </TableCell>
113
+                  <TableCell>
114
+                    <Typography variant='body2' sx={{ fontWeight: "bold", mb: 1 }}>{row.name}</Typography>
115
+                    <Typography variant='body2'>{row.description}</Typography>
116
+                  </TableCell>
117
+                  <TableCell align='center'>
118
+                    <Typography variant='body1' sx={{ fontWeight: "bold" }} >{row.colour}</Typography>
119
+                  </TableCell>
120
+                  <TableCell align='center'>
121
+                  <Typography variant='body1' sx={{ fontWeight: "bold" }}>{row.quantity}</Typography>
122
+                  </TableCell>
123
+                  <TableCell align='center'>
124
+                    <Typography variant='body1' sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(row.price).toFixed(2)}`}</Typography>
125
+                  </TableCell>
126
+                  <TableCell align='center'>
127
+                    <Typography variant='body1' sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(row.price).toFixed(2)}`}</Typography>
128
+                  </TableCell>
129
+                  <TableCell align='center'>
130
+                    <Typography variant='body1' sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(row.price).toFixed(2)}`}</Typography>
131
+                  </TableCell>
132
+                  <TableCell align='center'>
133
+                    <Typography variant='body1' sx={{ fontWeight: "bold" }}>{`RM ${parseFloat(row.price).toFixed(2)}`}</Typography>
134
+                  </TableCell>
135
+                </TableRow>
136
+              ))}
137
+            </TableBody>
138
+          </Table>
139
+        </TableContainer>
140
+
141
+    </Box>
142
+  );
143
+};
144
+
145
+export default BillingForm;

+ 1
- 0
src/components/BillingForm/index.js Прегледај датотеку

@@ -0,0 +1 @@
1
+export { default } from './BillingForm'

+ 69
- 10
src/components/Navbar/Navbar.jsx Прегледај датотеку

@@ -1,20 +1,52 @@
1
-import React from "react";
1
+import React, { useState, useEffect } from "react";
2 2
 import AppBar from "@mui/material/AppBar";
3 3
 import Toolbar from "@mui/material/Toolbar";
4 4
 import Typography from "@mui/material/Typography";
5 5
 import Button from "@mui/material/Button";
6 6
 import IconButton from "@mui/material/IconButton";
7 7
 import Box from "@mui/material/Box";
8
+import Header from "../Header";
8 9
 import InputBase from "@mui/material/InputBase";
9 10
 import SearchIcon from "@mui/icons-material/Search";
10 11
 import AccountCircleIcon from "@mui/icons-material/AccountCircle";
11 12
 
12 13
 const Navbar = () => {
14
+  const [showHeader, setShowHeader] = useState(true);
15
+  const [lastScrollPos, setLastScrollPos] = useState(0);
16
+
17
+  useEffect(() => {
18
+    const handleScroll = () => {
19
+      const currentScrollPos = window.scrollY;
20
+
21
+      if (currentScrollPos > lastScrollPos && currentScrollPos > 50) setShowHeader(false)
22
+      else setShowHeader(true)
23
+
24
+      setLastScrollPos(currentScrollPos);
25
+    };
26
+
27
+    window.addEventListener("scroll", handleScroll);
28
+
29
+    return () => {
30
+      window.removeEventListener("scroll", handleScroll);
31
+    };
32
+  }, [lastScrollPos]);
33
+
13 34
   return (
14
-    <AppBar position="static" sx={{backgroundColor:"background.black"}}>
35
+    <AppBar position="fixed" sx={{ backgroundColor: "background.black" }}>
36
+      {/* Conditionally render the Header */}
37
+      {showHeader && <Header />}
38
+
15 39
       <Toolbar>
16 40
         {/* Left Section: Logo */}
17
-        <Typography variant="h6" sx={{ flexGrow: 0, color:"white", letterSpacing:10, marginLeft:20 }}>
41
+        <Typography
42
+          variant="h6"
43
+          sx={{
44
+            flexGrow: 0,
45
+            color: "white",
46
+            letterSpacing: 10,
47
+            mx: 20,
48
+          }}
49
+        >
18 50
           AMBER
19 51
         </Typography>
20 52
 
@@ -23,18 +55,45 @@ const Navbar = () => {
23 55
           sx={{
24 56
             flexGrow: 1,
25 57
             display: "flex",
26
-            justifyContent: "center",
27 58
             gap: 2,
28 59
           }}
29 60
         >
30
-          <Button color="inherit" onClick={()=>{ window.location.href = "/products" }}>DISCOVER</Button>
31
-          <Button color="inherit" onClick={()=>{ window.location.href = "/" }}>HOME</Button>
32
-          <Button color="inherit" onClick={()=>{ window.location.href = "/products" }}>BEAUTY</Button>
33
-          <Button color="inherit" onClick={()=>{ window.location.href = "/products" }}>SALE</Button>
61
+          <Button
62
+            color="inherit"
63
+            onClick={() => {
64
+              window.location.href = "/products";
65
+            }}
66
+          >
67
+            DISCOVER
68
+          </Button>
69
+          <Button
70
+            color="inherit"
71
+            onClick={() => {
72
+              window.location.href = "/";
73
+            }}
74
+          >
75
+            HOME
76
+          </Button>
77
+          <Button
78
+            color="inherit"
79
+            onClick={() => {
80
+              window.location.href = "/products";
81
+            }}
82
+          >
83
+            BEAUTY
84
+          </Button>
85
+          <Button
86
+            color="inherit"
87
+            onClick={() => {
88
+              window.location.href = "/products";
89
+            }}
90
+          >
91
+            SALE
92
+          </Button>
34 93
         </Box>
35 94
 
36 95
         {/* Right Section: Search and Profile */}
37
-        <Box sx={{ display: "flex", alignItems: "center", marginRight:20 }}>
96
+        <Box sx={{ display: "flex", alignItems: "center", marginRight: 20 }}>
38 97
           <Box
39 98
             sx={{
40 99
               display: "flex",
@@ -53,7 +112,7 @@ const Navbar = () => {
53 112
             />
54 113
           </Box>
55 114
           <IconButton color="inherit">
56
-            <AccountCircleIcon sx={{color:"white"}}/>
115
+            <AccountCircleIcon sx={{ color: "white" }} />
57 116
           </IconButton>
58 117
         </Box>
59 118
       </Toolbar>

+ 6
- 4
src/pages/Checkout.jsx Прегледај датотеку

@@ -5,6 +5,7 @@ import Feature from '../components/Feature'
5 5
 import LoginForm from '../components/LoginForm'
6 6
 import SignUpForm from '../components/SignUpForm'
7 7
 import ShippingForm from '../components/ShippingForm'
8
+import BillingForm from '../components/BillingForm/BillingForm'
8 9
 
9 10
 import Grid from '@mui/material/Grid2';
10 11
 
@@ -80,14 +81,15 @@ const Checkout = () => {
80 81
       </Grid>}
81 82
 
82 83
       {(content == 1) && <Grid container sx={{ mb: 5 }}>
83
-
84 84
         <Grid item size={12}>
85
-
86 85
           <ShippingForm/>
87
-
88 86
         </Grid>
87
+      </Grid>}
89 88
 
90
-
89
+      {(content == 2) && <Grid container sx={{ mb: 5 }}>
90
+        <Grid item size={12}>
91
+          <BillingForm/>
92
+        </Grid>
91 93
       </Grid>}
92 94
 
93 95
 

Loading…
Откажи
Сачувај