Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions frontend/src/screens/CartScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, useNavigate } from 'react-router-dom';
import { Link, useNavigate, useLocation } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import {
Row,
Expand All @@ -17,6 +17,8 @@ const CartScreen = () => {
const navigate = useNavigate();
const dispatch = useDispatch();

const currentPath = useLocation().pathname;

const cart = useSelector((state) => state.cart);
const { cartItems } = cart;

Expand Down Expand Up @@ -51,7 +53,9 @@ const CartScreen = () => {
<Image src={item.image} alt={item.name} fluid rounded />
</Col>
<Col md={3}>
<Link to={`/product/${item._id}`}>{item.name}</Link>
<Link to={`/product/${item._id}?goBackPath=${currentPath}`}>
{item.name}
</Link>
</Col>
<Col md={2}>${item.price}</Col>
<Col md={2}>
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/screens/OrderScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { Link, useParams } from 'react-router-dom';
import { Link, useParams, useLocation } from 'react-router-dom';
import { Row, Col, ListGroup, Image, Card, Button } from 'react-bootstrap';
import { PayPalButtons, usePayPalScriptReducer } from '@paypal/react-paypal-js';
import { useSelector } from 'react-redux';
Expand All @@ -16,6 +16,8 @@ import {
const OrderScreen = () => {
const { id: orderId } = useParams();

const currentPath = useLocation().pathname;

const {
data: order,
refetch,
Expand Down Expand Up @@ -166,7 +168,9 @@ const OrderScreen = () => {
/>
</Col>
<Col>
<Link to={`/product/${item.product}`}>
<Link
to={`/product/${item.product}?goBackPath=${currentPath}`}
>
{item.name}
</Link>
</Col>
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/screens/PlaceOrderScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { Link, useNavigate, useLocation } from 'react-router-dom';
import { toast } from 'react-toastify';
import { Button, Row, Col, ListGroup, Image, Card } from 'react-bootstrap';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -12,6 +12,8 @@ import { clearCartItems } from '../slices/cartSlice';
const PlaceOrderScreen = () => {
const navigate = useNavigate();

const currentPath = useLocation().pathname;

const cart = useSelector((state) => state.cart);

const [createOrder, { isLoading, error }] = useCreateOrderMutation();
Expand Down Expand Up @@ -83,7 +85,9 @@ const PlaceOrderScreen = () => {
/>
</Col>
<Col>
<Link to={`/product/${item.product}`}>
<Link
to={`/product/${item._id}?goBackPath=${currentPath}`}
>
{item.name}
</Link>
</Col>
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/screens/ProductScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { addToCart } from '../slices/cartSlice';
const ProductScreen = () => {
const { id: productId } = useParams();

const queryParams = new URLSearchParams(window.location.search);
const goBackPath = queryParams.get('goBackPath') || '/';

const dispatch = useDispatch();
const navigate = useNavigate();

Expand Down Expand Up @@ -67,7 +70,7 @@ const ProductScreen = () => {

return (
<>
<Link className='btn btn-light my-3' to='/'>
<Link className='btn btn-light my-3' to={goBackPath}>
Go Back
</Link>
{isLoading ? (
Expand Down