Skip to content

Commit

Permalink
Signup + userSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
swatimoluguri committed May 13, 2024
1 parent bb9d98e commit 49003f9
Show file tree
Hide file tree
Showing 27 changed files with 675 additions and 226 deletions.
3 changes: 2 additions & 1 deletion db.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports={
getDb:()=>dbConnection,
getOrderModel: () => dbConnection.collection('orders'),
getUserModel: () => dbConnection.collection('users'),
getCustomerEnquiries: () => dbConnection.collection('customer-enquiries')
getCustomerEnquiries: () => dbConnection.collection('customer-enquiries'),
getNewsletter:()=>dbConnection.collection('newsletters')
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.8",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-react-views": "^0.11.0",
Expand Down
4 changes: 4 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link
href="https://fonts.googleapis.com/css2?family=Poppins&family=Satisfy&display=swap"
rel="stylesheet"
/>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
31 changes: 24 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const { ObjectId } = require("mongodb");
const { connectToDb, getDb, getOrderModel, getUserModel, getCustomerEnquiries } = require("./db");
const {
connectToDb,
getDb,
getOrderModel,
getUserModel,
getCustomerEnquiries,
getNewsletter,
} = require("./db");
const Razorpay = require("razorpay");
const crypto = require("crypto");
const { OAuth2Client } = require("google-auth-library");
Expand All @@ -15,7 +22,7 @@ const razorpay = new Razorpay({
});

// Middleware setup
app.use(express.static('build'));
app.use(express.static("build"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
Expand Down Expand Up @@ -190,7 +197,7 @@ app.post("/sign-up", async (req, res) => {
const newUser = await userModel
.insertOne(req.body.formData)
.then(() => {
res.redirect("http://localhost:3001/");
res.status(200).json({ redirect: '/' });
})
.catch((err) => {
console.log(err);
Expand All @@ -199,14 +206,24 @@ app.post("/sign-up", async (req, res) => {

app.post("/contact-us", async (req, res) => {
try {
// add to database
res.redirect("/");
const enquiryModel = getCustomerEnquiries();
await enquiryModel.insertOne(req.body.formData).then((result) => {
res.status(200).json({ success: result.insertedId });
});
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
}
});

app.get("/",(req,res)=>{
res.sendFile(__dirname + '/build/index.html');
app.post("/newsletter", async (req, res) => {
try {
const newsletterModel = getNewsletter();
await newsletterModel.insertOne(req.body).then((result) => {
res.status(200).json({ success: result.insertedId });
});
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
}
});
15 changes: 5 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ import Routings from "./components/Partials/Routings";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { AppStore, persistor } from "./utils/AppStore";
import UserContext from "./utils/UserContext";
import { useState } from "react";
import Navbar from "./components/Partials/Navbar";
import Footer from "./components/Partials/Footer";

function App() {
const [loggedUser, setLoggedUser] = useState("");

return (
<Provider store={AppStore}>
<PersistGate loading={null} persistor={persistor}>
<UserContext.Provider value={{ loggedInUser: loggedUser, setLoggedUser }}>
<div className="App">
<Navbar />
<Routings />
<Footer />
</div>
</UserContext.Provider>
<div className="App">
<Navbar />
<Routings />
<Footer />
</div>
</PersistGate>
</Provider>
);
Expand Down
Binary file added src/assets/people/Jenny.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/people/Mitchell.jpg
Binary file not shown.
13 changes: 6 additions & 7 deletions src/components/Checkout/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ const Cart = () => {
const dispatch = useDispatch();
const [cartTotal, setCartTotal] = useState(0);
const [cartItems, setCartItems] = useState(0);
const cart = useSelector((store) => store.cart.items);
console.log(cart);
const cart = useSelector((store) => store.cart);
useEffect(() => {
let total = cart.reduce((acc, item) => {
let total = cart.items.reduce((acc, item) => {
acc += Math.round(item.price * 84) * item.count;
return acc;
}, 0);
let totalItems = cart.reduce((acc, item) => {
let totalItems = cart.items.reduce((acc, item) => {
acc += item.count;
return acc;
}, 0);
Expand Down Expand Up @@ -85,7 +84,7 @@ const Cart = () => {
<div className="flex flex-col items-center bg-[url('assets/bg.jpg')] bg-cover ">
<Heading text="Shopping Cart" heading="" highlight="" />
</div>
{cart.reduce((acc, item) => {
{cart.items.reduce((acc, item) => {
acc += item.count;
return acc;
}, 0) > 0 ? (
Expand All @@ -102,7 +101,7 @@ const Cart = () => {
</tr>
</thead>
<tbody>
{cart.map((item, index) => (
{cart.items.map((item, index) => (
<tr key={index} className="border-b border-gray-200">
<td className="p-3 flex items-center gap-6">
<Link to={"/products/" + item._id} key={item._id}>
Expand Down Expand Up @@ -183,7 +182,7 @@ const Cart = () => {
<th className="text-left p-2">Sub Total</th>
<td className="text-right p-2">
{cart.reduce((acc, item) => {
{cart.items.reduce((acc, item) => {
acc += Math.round(item.price * 84) * item.count;
return acc;
}, 0)}
Expand Down
87 changes: 81 additions & 6 deletions src/components/Contact/About.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,87 @@
import Heading from "../Partials/Heading";
import DetailsStrip from "../Partials/DetailsStrip";
import Jenny from "../../assets/people/Jenny.jpg";
import Jacob from "../../assets/people/jacob.jpg";
import John from "../../assets/people/john.jpg";
import Awards from "./Awards";

const About=()=>{
return <div>
<div className="flex flex-col items-center bg-[url('assets/bg.jpg')] bg-cover ">
<Heading text="About Us" heading="" highlight="" />
const About = () => {
const cards = [
{
name: "Jenny Alexander",
designation: "Director, CEO",
img: Jenny,
},
{
name: "Jacob Thomas",
designation: "Head of Technology",
img: Jacob,
},
{
name: "John Marcus",
designation: "Sales and Marketing",
img: John,
},
];
return (
<div>
<div className="flex flex-col items-center bg-[url('assets/bg.jpg')] bg-cover ">
<Heading
text="Our Story"
heading="Crafted Comfort:"
highlight="Quality Material and fast deliveries"
/>
</div>
<div className="w-2/3 mx-auto">
<p className="text-gray-500 font-medium text-lg text-justify py-4 my-4 ">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<div className=" text-center ">
<h1 className="font-satisfy text-3xl text-app-green">
Jenny Alexander
</h1>
<p>CEO</p>
<img src={Jenny} alt="CEO Jenny" className="h-112 mx-auto rounded-xl" />
</div>
<Awards />
<Heading text="Our team" heading="Meet:" highlight="Our Team" />
<div className="flex justify-around">
{cards.map((item) => (
<div className="bg-gray-50 rounded-lg p-4">
<div className="h-96 w-96">
<img
className="h-full w-full object-cover rounded-lg"
src={item.img}
alt="team"
/>
</div>
<div className="text-center pt-4">
<h2 className="font-semibold text-xl">{item.name}</h2>
<p className="text-gray-500">{item.designation}</p>
</div>
</div>
))}
</div>
<div className="flex flex-col items-center bg-[url('assets/bg.jpg')] bg-cover my-10">
<p className="text-gray-500 font-medium text-lg text-justify py-4 w-2/3 mx-auto ">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<DetailsStrip />
</div>
}
export default About;
);
};
export default About;
102 changes: 102 additions & 0 deletions src/components/Contact/Awards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useState, useEffect,useRef } from "react";
import {
faCalendar,
faHome,
faTrophy,
faUser,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

const Awards = () => {
const [currentYears, setCurrentYears] = useState(0);
const [currentCustomer, setCurrentCustomer] = useState(0);
const [currentStores, setCurrentStores] = useState(0);
const [currentAwards, setCurrentAwards] = useState(0);
const awardsRef = useRef(null);
const duration = 500;
const targetValues = [
{ target: 12, stateSetter: setCurrentYears },
{ target: 100, stateSetter: setCurrentCustomer },
{ target: 180, stateSetter: setCurrentStores },
{ target: 35, stateSetter: setCurrentAwards },
];

useEffect(() => {
const options = {
root: null,
rootMargin: "0px",
threshold: 0.5,
};

const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
const intervals = targetValues.map(({ target, stateSetter }) => {
const increment = target / duration;
return setInterval(() => {
stateSetter((prevState) => {
const newValue = prevState + increment;
return newValue >= target ? target : newValue;
});
}, 0.1);
});

return () => {
intervals.forEach(clearInterval);
};
}
}, options);

if (awardsRef.current) {
observer.observe(awardsRef.current);
}

return () => {
observer.disconnect();
};
}, [duration, targetValues]);

return (
<div
ref={awardsRef}
className="flex justify-around bg-app-yellow py-8 my-8"
>
<div className="flex justify-center items-center gap-4">
<div className="text-6xl">
<FontAwesomeIcon className="text-app-green" icon={faCalendar} />
</div>
<div className="flex flex-col text-center">
<p className="text-4xl font-bold">{Math.round(currentYears)}+</p>
<p>Years</p>
</div>
</div>
<div className="flex justify-center items-center gap-4">
<div className="text-6xl">
<FontAwesomeIcon className="text-app-green" icon={faUser} />
</div>
<div className="flex flex-col text-center">
<p className="text-4xl font-bold">{Math.round(currentCustomer)}M+</p>
<p>Happy Customers</p>
</div>
</div>
<div className="flex justify-center items-center gap-4">
<div className="text-6xl">
<FontAwesomeIcon className="text-app-green" icon={faHome} />
</div>
<div className="flex flex-col text-center">
<p className="text-4xl font-bold">{Math.round(currentStores)}+</p>
<p>Stores</p>
</div>
</div>
<div className="flex justify-center items-center gap-4">
<div className="text-6xl">
<FontAwesomeIcon className="text-app-green" icon={faTrophy} />
</div>
<div className="flex flex-col text-center">
<p className="text-4xl font-bold">{Math.round(currentAwards)}+</p>
<p>Awards</p>
</div>
</div>
</div>
);
};
export default Awards;
Loading

0 comments on commit 49003f9

Please sign in to comment.