Skip to content

Commit 7684c0a

Browse files
committed
api call & redux basic setup
1 parent 5593252 commit 7684c0a

File tree

8 files changed

+189
-36
lines changed

8 files changed

+189
-36
lines changed

package-lock.json

+90-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13+
"@reduxjs/toolkit": "^2.2.3",
1314
"axios": "^1.6.8",
1415
"react": "^18.2.0",
1516
"react-dom": "^18.2.0",
1617
"react-icons": "^5.0.1",
1718
"react-loading-skeleton": "^3.4.0",
19+
"react-redux": "^9.1.2",
1820
"react-router-dom": "^6.22.3",
1921
"react-slick": "^0.30.2",
2022
"react-toastify": "^10.0.5",

src/main.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import App from "./App";
44
import "./index.css";
55
import "react-toastify/dist/ReactToastify.css";
66
import { ToastContainer } from "react-toastify";
7-
import 'react-loading-skeleton/dist/skeleton.css'
7+
import "react-loading-skeleton/dist/skeleton.css";
8+
import store from "./app/store";
9+
import { Provider } from "react-redux";
810

911
ReactDOM.createRoot(document.getElementById("root")).render(
1012
<React.StrictMode>
11-
<App />
13+
<Provider store={store}>
14+
<App />
15+
</Provider>
1216
<ToastContainer
1317
theme="colored"
1418
closeOnClick

src/pages/Home.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function Home() {
2020
pauseOnHover: true,
2121
initialSlide: 0,
2222
arrows: false,
23-
dots:false,
23+
dots: false,
2424
responsive: [
2525
{
2626
breakpoint: 1024,

src/pages/Login.jsx

+50-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import { Link } from "react-router-dom";
33
import BreadCrumb from "../components/BreadCrumb";
4+
import axios from "axios";
45

56
export default function Login() {
7+
const [formData, setFormData] = useState({
8+
9+
password: "password",
10+
});
11+
12+
function handleSubmit(e) {
13+
e.preventDefault();
14+
axios.post("https://ecommerce-sagartmg2.vercel.app/api/users/login", {
15+
email: e.target.email.value,
16+
password: e.target.password.value,
17+
});
18+
}
19+
620
return (
721
<>
822
{/* Top Div with text */}
@@ -26,32 +40,44 @@ export default function Login() {
2640
</p>
2741
</div>
2842

29-
<div className="space-y-4 ">
30-
<input
31-
className="h-[36px] w-full rounded-[2px] border border-gray-light pl-[13px] focus:shadow-[0px_6px_25px_0px_rgba(0,0,0,0.4)] focus:outline-none sm:h-[43px] md:h-[52px]"
32-
type="email"
33-
title="Add Valid Email Address"
34-
placeholder="Email Address"
35-
/>
36-
<input
37-
className="h-[36px] w-full rounded-[2px] border border-gray-light pl-[13px] focus:shadow-[0px_6px_25px_0px_rgba(0,0,0,0.4)] focus:outline-none sm:h-[43px] md:h-[52px]"
38-
type="password"
39-
title="Make Stronge Password"
40-
placeholder="Password"
41-
/>
42-
</div>
43+
<form onSubmit={handleSubmit}>
44+
<div className="space-y-4 ">
45+
<input
46+
className="h-[36px] w-full rounded-[2px] border border-gray-light pl-[13px] focus:shadow-[0px_6px_25px_0px_rgba(0,0,0,0.4)] focus:outline-none sm:h-[43px] md:h-[52px]"
47+
type="email"
48+
name="email"
49+
onChange={(e) => {
50+
setFormData(e.target.value);
51+
}}
52+
value={formData.email}
53+
title="Add Valid Email Address"
54+
placeholder="Email Address"
55+
/>
56+
<input
57+
className="h-[36px] w-full rounded-[2px] border border-gray-light pl-[13px] focus:shadow-[0px_6px_25px_0px_rgba(0,0,0,0.4)] focus:outline-none sm:h-[43px] md:h-[52px]"
58+
type="password"
59+
name="password"
60+
onChange={(e) => {
61+
setFormData(e.target.value);
62+
}}
63+
value={formData.password}
64+
title="Make Stronge Password"
65+
placeholder="Password"
66+
/>
67+
</div>
4368

44-
<a href="/forgetPassword" className="text-[#9096B2]">
45-
Forget Your Password
46-
</a>
69+
<a href="/forgetPassword" className="text-[#9096B2]">
70+
Forget Your Password
71+
</a>
4772

48-
<div className="text-gray-light">
49-
<input type="checkbox"></input> Stay logged in
50-
</div>
73+
<div className="text-gray-light">
74+
<input type="checkbox"></input> Stay logged in
75+
</div>
5176

52-
<button className="w-full rounded-[3px] bg-secondary py-[10px] text-white hover:bg-secondary-dark hover:shadow-[0px_3px_25px_0px_rgba(0,0,0,0.15)]">
53-
Sign in
54-
</button>
77+
<button className="w-full rounded-[3px] bg-secondary py-[10px] text-white hover:bg-secondary-dark hover:shadow-[0px_3px_25px_0px_rgba(0,0,0,0.15)]">
78+
Sign in
79+
</button>
80+
</form>
5581
<p className="text-gray-light">
5682
Don’t have an Account?
5783
<Link

src/pages/Signup.jsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function Signup() {
99
const navigate = useNavigate();
1010
const [isLoading, setIsLoading] = useState(false);
1111

12-
const [formDara, setFormData] = useState({
12+
const [formData, setFormData] = useState({
1313
name: "Sanchit",
1414
1515
password: "sassword",
@@ -29,7 +29,7 @@ export default function Signup() {
2929
.then((res) => {
3030
toast.success("Succesfully.");
3131
setIsLoading(false);
32-
// navigate("/login");
32+
navigate("/login");
3333
})
3434
.catch((err) => {
3535
console.log(err);
@@ -43,6 +43,7 @@ export default function Signup() {
4343
title={"Sign Up"}
4444
links={[
4545
{title: "Home", url:"/"},
46+
{title: ". Pages", url:"/pages"},
4647
{title: ". Signup", url:"#"},
4748
]}
4849
/>
@@ -65,7 +66,7 @@ export default function Signup() {
6566
onChange={(e) => {
6667
setFormData(e.target.value);
6768
}}
68-
value={formDara.name}
69+
value={formData.name}
6970
type="text"
7071
placeholder="Name"
7172
required
@@ -76,7 +77,7 @@ export default function Signup() {
7677
<input
7778
className="form-control"
7879
name="email"
79-
value={formDara.email}
80+
value={formData.email}
8081
type="email"
8182
placeholder="Email Address"
8283
required
@@ -87,7 +88,7 @@ export default function Signup() {
8788
<input
8889
className="form-control"
8990
name="password"
90-
value={formDara.password}
91+
value={formData.password}
9192
type="password"
9293
required
9394
placeholder="Password"
@@ -99,7 +100,7 @@ export default function Signup() {
99100
placeholder="Role"
100101
className="form-control"
101102
name="role"
102-
value={formDara.role}
103+
value={formData.role}
103104
>
104105
<option value="">Select Role</option>
105106
<option value="seller">seller</option>

src/redux/slice/user.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createSlice } from '@reduxjs/toolkit'
2+
3+
export const userSlice = createSlice({
4+
name: 'user',
5+
initialState: {
6+
value: 0
7+
},
8+
reducers: {
9+
increment: state => {
10+
// Redux Toolkit allows us to write "mutating" logic in reducers. It
11+
// doesn't actually mutate the state because it uses the Immer library,
12+
// which detects changes to a "draft state" and produces a brand new
13+
// immutable state based off those changes
14+
state.value += 1
15+
},
16+
decrement: state => {
17+
state.value -= 1
18+
},
19+
incrementByAmount: (state, action) => {
20+
state.value += action.payload
21+
}
22+
}
23+
})
24+
25+
// Action creators are generated for each case reducer function
26+
export const { increment, decrement, incrementByAmount } = userSlice.actions
27+
28+
export default userSlice.reducer

0 commit comments

Comments
 (0)