From 8706c705b66406c22d1dad87fa9706d459145f09 Mon Sep 17 00:00:00 2001
From: Rishi Mondal <146999057+MAVRICK-1@users.noreply.github.com>
Date: Thu, 23 May 2024 18:37:24 +0530
Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"feat=20#199=20:=20implement?=
=?UTF-8?q?=20the=20shipping=20Addresses=20feature=20(#209)"=20=E2=80=A6"?=
=?UTF-8?q?=20(#217)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit a983b908c06a1e70176943302689846d54f789a1.
---
package.json | 1 +
src/App.js | 16 +-
src/components/AccountDetails/Account.js | 137 +++++++++--
.../ShippingAddress/AddressData.jsx | 49 ++++
src/components/ShippingAddress/Shipping.css | 113 +++++++++
.../ShippingAddress/ShippingForm.jsx | 216 ++++++++++++++++++
src/components/footer/footer.js | 2 +-
src/components/header/header.js | 10 +-
src/components/header/nav/nav.css | 2 +-
src/components/header/nav/nav.js | 2 +-
src/components/search/SearchResults.jsx | 150 ++++++------
src/pages/About/about.css | 4 +-
src/pages/About/index.js | 2 +-
src/pages/Compare/index.js | 127 +++++-----
src/pages/Compare/style.css | 152 ++++++------
src/pages/Details/index.js | 14 +-
src/pages/Home/style.css | 2 +-
src/pages/ResetPassword/index.js | 2 +-
src/pages/ResetPassword/style.css | 2 +-
src/pages/SignIn/index.js | 2 +-
src/pages/wishList/index.js | 2 +-
src/useFetchData.js | 2 +-
22 files changed, 749 insertions(+), 260 deletions(-)
create mode 100644 src/components/ShippingAddress/AddressData.jsx
create mode 100644 src/components/ShippingAddress/Shipping.css
create mode 100644 src/components/ShippingAddress/ShippingForm.jsx
diff --git a/package.json b/package.json
index 6a50fcd..f664376 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.1",
"bootstrap": "^4.6.2",
+ "country-state-city": "^3.2.1",
"custom-react-inner-image-zoom": "^3.0.6",
"firebase": "^10.8.0",
"leaflet": "^1.9.4",
diff --git a/src/App.js b/src/App.js
index 8c718ab..c6d4429 100644
--- a/src/App.js
+++ b/src/App.js
@@ -24,6 +24,8 @@ import MapComponent from './components/map/ITEMmap';
import { db } from './firebase';
import SellerForm from './pages/SellerRegistration';
import SearchResults from './components/search/SearchResults';
+import Shipping from './components/ShippingAddress/ShippingForm';
+import { Account } from './components/AccountDetails/Account';
const MyContext = createContext();
@@ -291,6 +293,18 @@ function App() {
} />
{/* search route */}
} />
+
+ }
+ />
+ }
+ />
+ } />
@@ -304,4 +318,4 @@ function App() {
export default App;
-export { MyContext };
\ No newline at end of file
+export { MyContext };
diff --git a/src/components/AccountDetails/Account.js b/src/components/AccountDetails/Account.js
index 88eed45..940ddc7 100644
--- a/src/components/AccountDetails/Account.js
+++ b/src/components/AccountDetails/Account.js
@@ -21,23 +21,20 @@ import {
uploadBytes,
updateMetadata
} from 'firebase/storage';
-import { useNavigate } from 'react-router-dom';
+import { Link, useNavigate } from 'react-router-dom';
import {
- addDoc,
collection,
doc,
getDoc,
- onSnapshot,
setDoc,
updateDoc,
- query,
- where,
- documentId,
- getDocs
+ getDocs,
+ deleteDoc
} from 'firebase/firestore';
import { db, storage } from '../../firebase';
import { nanoid } from 'nanoid';
-
+import AddressData from '../ShippingAddress/AddressData';
+import Loader from '../../assets/images/loading.gif';
export function Account() {
const {
register,
@@ -49,27 +46,48 @@ export function Account() {
const userImage = localStorage.getItem('userImage');
const userName = localStorage.getItem('uname');
const userEmail = localStorage.getItem('uemail');
-
+ const [loading, setLoadding] = useState(false);
const [name, setName] = useState(userName);
const [email, setEmail] = useState(userEmail);
const [address, setAddress] = useState('');
const [file, setFile] = useState(pfp);
const navigate = useNavigate();
+ const [shippingAddresses, setShippingAddresses] = useState([]);
- useEffect(() => {
- (async () => {
- const docref = doc(db, 'users', `${user_uid ? user_uid : nanoid()}`);
- const docSnap = await getDoc(docref);
- if (docSnap.exists()) {
- setName(docSnap.data().Name);
- setEmail(docSnap.data().Email);
- setAddress(docSnap.data().Address);
- setFile(docSnap.data().photo);
- } else {
- console.log(null);
- }
- })();
- }, []);
+ async function FetchTheData() {
+ setLoadding(true);
+ const docref = doc(db, 'users', `${user_uid ? user_uid : nanoid()}`);
+ const docSnap = await getDoc(docref);
+ if (docSnap.exists()) {
+ setName(docSnap.data().Name);
+ setEmail(docSnap.data().Email);
+ setAddress(docSnap.data().Address);
+ setFile(docSnap.data().photo);
+
+ // Fetch the shipping address subcollection
+ const shippingAddressCollectionRef = collection(
+ docref,
+ 'shippingaddress'
+ );
+ const shippingAddressQuerySnapshot = await getDocs(
+ shippingAddressCollectionRef
+ );
+
+ const shippingAddresses = shippingAddressQuerySnapshot.docs.map(
+ (doc) => ({
+ id: doc.id,
+ ...doc.data()
+ })
+ );
+
+ // Print the array of shipping address documents
+ console.log('Shipping Address Documents:', shippingAddresses);
+ setShippingAddresses(shippingAddresses);
+ } else {
+ console.log(null);
+ }
+ setLoadding(false);
+ }
function handlehistory() {
navigate('/');
@@ -139,6 +157,38 @@ export function Account() {
}
};
+ // shipping Address delete
+ const deleteShippingAddress = async (id) => {
+ try {
+ const userId = user_uid ? user_uid : nanoid();
+ const userDocRef = doc(db, 'users', userId);
+ const shippingAddressDocRef = doc(userDocRef, 'shippingaddress', id);
+
+ // Delete the shipping address document
+ await deleteDoc(shippingAddressDocRef);
+
+ // Update the local state to remove the deleted address
+ setShippingAddresses((prevAddresses) =>
+ prevAddresses.filter((address) => address.id !== id)
+ );
+
+ console.log('Shipping address deleted successfully');
+ } catch (error) {
+ console.error('Error deleting shipping address: ', error);
+ }
+ };
+ useEffect(() => {
+ FetchTheData();
+ }, []);
+
+ if (loading) {
+ return (
+
+
+
+ );
+ }
+
return (
<>
@@ -274,6 +324,47 @@ export function Account() {
+
+
Manage Addresses
+
+
+ {shippingAddresses.length > 0 ? (
+ <>
+ {shippingAddresses.map((add, i) => {
+ return (
+
+ );
+ })}
+
+
+
+ >
+ ) : (
+ <>
+
+
No Any Address Found
+
+
+
+
+ >
+ )}
+
+
>
);
}
diff --git a/src/components/ShippingAddress/AddressData.jsx b/src/components/ShippingAddress/AddressData.jsx
new file mode 100644
index 0000000..8912406
--- /dev/null
+++ b/src/components/ShippingAddress/AddressData.jsx
@@ -0,0 +1,49 @@
+import React from 'react';
+import { useNavigate } from 'react-router-dom';
+
+export default function AddressData({ address, deleteShippingAddress }) {
+ const Navigate = useNavigate();
+ return (
+
+ );
+}
diff --git a/src/components/ShippingAddress/Shipping.css b/src/components/ShippingAddress/Shipping.css
new file mode 100644
index 0000000..aa6de9b
--- /dev/null
+++ b/src/components/ShippingAddress/Shipping.css
@@ -0,0 +1,113 @@
+.shippingContainer {
+ width: 100%;
+ padding: 30px 0;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+}
+
+.shippingBox {
+ background-color: white;
+ width: 30%;
+ /* height: 90vh; */
+ box-sizing: border-box;
+ overflow: hidden;
+}
+
+.shippingHeading {
+ text-align: center;
+ color: rgba(0, 0, 0, 0.664);
+ font: 400 3vmax 'Roboto';
+ padding: 1.3vmax;
+ border-bottom: 1px solid rgba(0, 0, 0, 0.205);
+ width: 70%;
+ font-weight: 700;
+ margin: auto;
+}
+
+.shippingForm {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ margin: auto;
+ gap: 20px;
+ padding: 2vmax;
+ justify-content: space-evenly;
+ height: 100%;
+ transition: all 0.5s;
+}
+
+.shippingForm > div {
+ display: flex;
+ width: 100%;
+ align-items: center;
+}
+
+.shippingForm > div > input,
+.shippingForm > div > select {
+ padding: 1vmax 4vmax;
+ padding-right: 1vmax;
+ width: 100%;
+ box-sizing: border-box;
+ border: 1px solid rgba(0, 0, 0, 0.267);
+ border-radius: 4px;
+ font: 300 2vmax cursive;
+ outline: none;
+}
+
+.shippingForm > div > svg {
+ position: absolute;
+ transform: translateX(1vmax);
+ font-size: 2vmax;
+ color: rgba(0, 0, 0, 0.623);
+}
+
+.shippingBtn {
+ border: none;
+ background-color: rgb(0, 150, 57);
+ color: rgb(255, 255, 255);
+ font: 300 1.6vmax 'Roboto';
+ padding: 1vmax;
+ cursor: pointer;
+ transition: all 0.5s;
+ outline: none;
+ text-transform: uppercase;
+ font-weight: bold;
+ margin: 2vmax;
+}
+
+@media screen and (max-width: 600px) {
+ .shippingBox {
+ width: 100vw;
+ /* height: 100vh; */
+ }
+
+ .shippingHeading {
+ font: 400 6vw 'Roboto';
+ padding: 5vw;
+ }
+
+ .shippingForm {
+ display: flex;
+ gap: 20px;
+ padding: 11vw 14vw;
+ }
+
+ .shippingForm > div > input,
+ .shippingForm > div > select {
+ padding: 3vw 6vw;
+ font: 300 5vw cursive;
+ padding-left: 50px;
+ }
+
+ .shippingForm > div > svg {
+ font-size: 4vw;
+ transform: translateX(3vw);
+ }
+
+ .shippingBtn {
+ font: 300 4vw 'Roboto';
+ padding: 4vw;
+ }
+}
diff --git a/src/components/ShippingAddress/ShippingForm.jsx b/src/components/ShippingAddress/ShippingForm.jsx
new file mode 100644
index 0000000..0a95f44
--- /dev/null
+++ b/src/components/ShippingAddress/ShippingForm.jsx
@@ -0,0 +1,216 @@
+import React, { useEffect, useState } from 'react';
+import { useParams, useNavigate } from 'react-router-dom';
+import { nanoid } from 'nanoid';
+import { collection, doc, getDoc, addDoc, updateDoc } from 'firebase/firestore';
+import { db } from '../../firebase';
+import HomeIcon from '@mui/icons-material/Home';
+import { Country, State } from 'country-state-city';
+import LocationCityIcon from '@mui/icons-material/LocationCityRounded';
+import PinDropIcon from '@mui/icons-material/PinDrop';
+import PhoneIcon from '@mui/icons-material/Phone';
+import PublicIcon from '@mui/icons-material/Public';
+import TransferWithinAStationIcon from '@mui/icons-material/TransferWithinAStation';
+import './Shipping.css';
+import Loader from '../../assets/images/loading.gif';
+export default function Shipping() {
+ const { addressId } = useParams(); // Get the addressId from URL parameters
+ const navigate = useNavigate();
+ const [isUpdate, setIsUpdate] = useState(!!addressId);
+ const [currentDocId, setCurrentDocId] = useState(addressId || null);
+ const [loading, setLoading] = useState(false);
+ const [addressType, setAddressType] = useState('other');
+ const [address, setAddress] = useState('');
+ const [city, setCity] = useState('');
+ const [state, setState] = useState('');
+ const [country, setCountry] = useState('');
+ const [pinCode, setPinCode] = useState('');
+ const [phoneNo, setPhoneNo] = useState('');
+
+ const user_uid = localStorage.getItem('uid');
+
+ // Fetch the Update Address Data
+ const fetchAddress = async () => {
+ setLoading(true);
+ const userId = user_uid ? user_uid : nanoid();
+ const userDocRef = doc(db, 'users', userId);
+ const addressDocRef = doc(userDocRef, 'shippingaddress', addressId);
+ const addressDocSnap = await getDoc(addressDocRef);
+
+ if (addressDocSnap.exists()) {
+ const addressData = addressDocSnap.data();
+ setAddressType(addressData.addressType || 'other');
+ setAddress(addressData.address);
+ setCity(addressData.city);
+ setState(addressData.state);
+ setCountry(addressData.country);
+ setPinCode(addressData.pinCode);
+ setPhoneNo(addressData.phoneNo);
+ } else {
+ console.log('No address found with the given ID.');
+ navigate('/');
+ }
+ setLoading(false);
+ };
+
+ useEffect(() => {
+ if (addressId) {
+ fetchAddress();
+ }
+ }, [addressId, user_uid]);
+
+ // Update And Add New Address
+ const submitShipping = async (e) => {
+ e.preventDefault();
+
+ if (phoneNo.length !== 10) {
+ alert('Phone number must be 10 digits long');
+ return;
+ }
+
+ try {
+ const userId = user_uid ? user_uid : nanoid();
+ const userDocRef = doc(db, 'users', userId);
+
+ if (isUpdate && currentDocId) {
+ const addressDocRef = doc(userDocRef, 'shippingaddress', currentDocId);
+ await updateDoc(addressDocRef, {
+ addressType,
+ address,
+ city,
+ state,
+ country,
+ pinCode,
+ phoneNo
+ });
+
+ console.log('Shipping address updated successfully');
+ } else {
+ await addDoc(collection(userDocRef, 'shippingaddress'), {
+ addressType,
+ address,
+ city,
+ state,
+ country,
+ pinCode,
+ phoneNo
+ });
+
+ console.log('Shipping address added successfully');
+ }
+
+ navigate('/my-account');
+ } catch (error) {
+ console.error('Error adding/updating shipping address: ', error);
+ }
+ };
+ if (loading) {
+ return (
+
+
+
+ );
+ }
+ return (
+
+
+
+ {isUpdate ? 'Update Shipping Details' : 'Add Shipping Details'}
+
+
+
+
+ );
+}
diff --git a/src/components/footer/footer.js b/src/components/footer/footer.js
index 2e644b5..fc0ba3f 100644
--- a/src/components/footer/footer.js
+++ b/src/components/footer/footer.js
@@ -317,4 +317,4 @@ const Footer = () => {
);
};
-export default Footer;
\ No newline at end of file
+export default Footer;
diff --git a/src/components/header/header.js b/src/components/header/header.js
index a806a70..da9c408 100644
--- a/src/components/header/header.js
+++ b/src/components/header/header.js
@@ -342,9 +342,11 @@ const Header = (props) => {
{isOpenDropDown !== false && (
-
-
+
+
+
-
*/}
-
{' '}
diff --git a/src/pages/Compare/style.css b/src/pages/Compare/style.css
index 9ff9509..f79c664 100644
--- a/src/pages/Compare/style.css
+++ b/src/pages/Compare/style.css
@@ -1,78 +1,78 @@
.cartSection {
- width: 100%;
- height: auto;
- padding: 10px 0px;
- display: flex;
- justify-content: center;
- }
- .cartSection .clearCart {
- font-weight: 600;
- font-size: 18px;
- }
- .cartSection .clearCart svg {
- font-size: 25px !important;
- }
-
- .cartWrapper table thead {
- background: #f1f1f1;
- overflow: hidden;
- }
- .cartWrapper table thead th:first-child {
- border-top-left-radius: 15px;
- border-bottom-left-radius: 15px;
- }
- .cartWrapper table thead th:last-child {
- border-top-right-radius: 15px;
- border-bottom-right-radius: 15px;
- }
-
- .cartWrapper table tbody td {
- vertical-align: middle;
- }
- .cartWrapper table tbody td .img {
- width: 30%;
- height: 150px;
- padding: 5px;
- border: 1px solid rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- }
- .cartWrapper table tbody td .img img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- .cartWrapper table tbody td .info {
- width: 70%;
- }
- .cartWrapper table tbody td .info a {
- color: rgba(0, 0, 0, 0.7);
- }
- .cartWrapper table tbody td .info a:hover {
- text-decoration: none;
- }
-
- .cartWrapper table tbody td span {
- font-weight: 600;
- font-size: 28px;
- }
- .cartWrapper table tbody td span.text-g {
- font-weight: bold;
- }
-
- .cartRightBox {
- padding-left: 100px;
- padding-bottom: 30px;
- height: auto;
- }
- .cartRightBox .card {
- position: sticky;
- top: 150px;
- height: auto;
- margin: auto;
- max-width: 430px;
- }
+ width: 100%;
+ height: auto;
+ padding: 10px 0px;
+ display: flex;
+ justify-content: center;
+}
+.cartSection .clearCart {
+ font-weight: 600;
+ font-size: 18px;
+}
+.cartSection .clearCart svg {
+ font-size: 25px !important;
+}
- .cartSection > div > div{
- display: flex;
- justify-content: center;
- }
\ No newline at end of file
+.cartWrapper table thead {
+ background: #f1f1f1;
+ overflow: hidden;
+}
+.cartWrapper table thead th:first-child {
+ border-top-left-radius: 15px;
+ border-bottom-left-radius: 15px;
+}
+.cartWrapper table thead th:last-child {
+ border-top-right-radius: 15px;
+ border-bottom-right-radius: 15px;
+}
+
+.cartWrapper table tbody td {
+ vertical-align: middle;
+}
+.cartWrapper table tbody td .img {
+ width: 30%;
+ height: 150px;
+ padding: 5px;
+ border: 1px solid rgba(0, 0, 0, 0.1);
+ border-radius: 5px;
+}
+.cartWrapper table tbody td .img img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+.cartWrapper table tbody td .info {
+ width: 70%;
+}
+.cartWrapper table tbody td .info a {
+ color: rgba(0, 0, 0, 0.7);
+}
+.cartWrapper table tbody td .info a:hover {
+ text-decoration: none;
+}
+
+.cartWrapper table tbody td span {
+ font-weight: 600;
+ font-size: 28px;
+}
+.cartWrapper table tbody td span.text-g {
+ font-weight: bold;
+}
+
+.cartRightBox {
+ padding-left: 100px;
+ padding-bottom: 30px;
+ height: auto;
+}
+.cartRightBox .card {
+ position: sticky;
+ top: 150px;
+ height: auto;
+ margin: auto;
+ max-width: 430px;
+}
+
+.cartSection > div > div {
+ display: flex;
+ justify-content: center;
+}
diff --git a/src/pages/Details/index.js b/src/pages/Details/index.js
index d202694..f274b2b 100644
--- a/src/pages/Details/index.js
+++ b/src/pages/Details/index.js
@@ -73,8 +73,7 @@ const DetailsPage = (props) => {
const [isAlreadyAddedInCart, setisAlreadyAddedInCart] = useState(false);
const [isAlreadyAddedInWishlist, setisAlreadyAddedInWishlist] =
useState(false);
- const [isAlreadyAddedInCompare, setIsAlreadyAddedInCompare] =
- useState(false);
+ const [isAlreadyAddedInCompare, setIsAlreadyAddedInCompare] = useState(false);
const [reviewFields, setReviewFields] = useState({
review: '',
@@ -271,7 +270,6 @@ const DetailsPage = (props) => {
};
const toggleWishlistItem = async (item) => {
-
if (!isAlreadyAddedInWishlist) {
try {
const user = localStorage.getItem('uid');
@@ -375,7 +373,6 @@ const DetailsPage = (props) => {
}
};
-
return (
<>
{context.windowWidth < 992 && (
@@ -606,11 +603,14 @@ const DetailsPage = (props) => {
>
{' '}
-