Skip to content

Commit

Permalink
Revert "feat #199 : implement the shipping Addresses feature (#209)" (#…
Browse files Browse the repository at this point in the history
…216)

This reverts commit b3c3c37.
  • Loading branch information
MAVRICK-1 authored May 23, 2024
1 parent b3c3c37 commit a983b90
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 749 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@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",
Expand Down
16 changes: 1 addition & 15 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ 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();

Expand Down Expand Up @@ -293,18 +291,6 @@ function App() {
<Route exact={true} path="*" element={<NotFound />} />
{/* search route */}
<Route exact={true} path="/search" element={<SearchResults />} />

<Route
exact={true}
path="/update-shipping-address/:addressId"
element={<Shipping />}
/>
<Route
exact={true}
path="/add-shipping-address"
element={<Shipping />}
/>
<Route exact={true} path="/my-account" element={<Account />} />
</Routes>
<Footer />
</MyContext.Provider>
Expand All @@ -318,4 +304,4 @@ function App() {

export default App;

export { MyContext };
export { MyContext };
137 changes: 23 additions & 114 deletions src/components/AccountDetails/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ import {
uploadBytes,
updateMetadata
} from 'firebase/storage';
import { Link, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import {
addDoc,
collection,
doc,
getDoc,
onSnapshot,
setDoc,
updateDoc,
getDocs,
deleteDoc
query,
where,
documentId,
getDocs
} 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,
Expand All @@ -46,48 +49,27 @@ 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([]);

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);
}
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);
}
})();
}, []);

function handlehistory() {
navigate('/');
Expand Down Expand Up @@ -157,38 +139,6 @@ 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 (
<div className="loader">
<img src={Loader} />
</div>
);
}

return (
<>
<div className="container-fluid d-flex flex-column justify-content-center align-items-center p-5">
Expand Down Expand Up @@ -324,47 +274,6 @@ export function Account() {
</CardFooter>
</Card>
</div>
<div className="container-fluid d-flex flex-column justify-content-center align-items-center ">
<h1 class="h1 font-weight-bold mt-0 mb-4">Manage Addresses</h1>

<div className="container-fluid d-flex justify-content-center align-items-stretch flex-wrap p-2 ">
{shippingAddresses.length > 0 ? (
<>
{shippingAddresses.map((add, i) => {
return (
<AddressData
key={i}
address={add}
deleteShippingAddress={deleteShippingAddress}
/>
);
})}
<Link to={'/add-shipping-address'} className="align-self-center">
<button
type="button"
class="btn btn-success py-4 px-5 mx-5 font-weight-bold btn-lg text-uppercase "
>
Add New Address
</button>
</Link>
</>
) : (
<>
<div className="my-5 d-flex flex-column align-items-center justify-content-center">
<h3 className="text-capitalize">No Any Address Found </h3>
<Link to={'/add-shipping-address'}>
<button
type="button"
class="btn btn-success py-4 px-5 my-5 font-weight-bold btn-lg text-uppercase"
>
Add New Address
</button>
</Link>
</div>
</>
)}
</div>
</div>
</>
);
}
49 changes: 0 additions & 49 deletions src/components/ShippingAddress/AddressData.jsx

This file was deleted.

113 changes: 0 additions & 113 deletions src/components/ShippingAddress/Shipping.css

This file was deleted.

Loading

0 comments on commit a983b90

Please sign in to comment.