This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Header from './components/Header'; | |
import { useSelector, useDispatch } from 'react-redux'; | |
import { removeFromCart } from '../lib/reducer'; | |
export default function Home() { | |
const totalValue = useSelector((state) => state.totalValue); | |
const totalItems = useSelector((state) => state.totalItems); | |
const cart = useSelector((state) => state.cart); | |
const dispatch = useDispatch(); | |
const handleRemoveFromCart = ({ productId, price, quantity }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Header from './components/Header'; | |
import { products } from '../lib/products'; | |
import Product from './components/Product'; | |
export default function Home() { | |
console.log(products); | |
return ( | |
<> | |
<Header /> | |
<div className="container mx-auto pt-4"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { useDispatch } from 'react-redux'; | |
import { addToCart } from '../../lib/reducer'; | |
import Image from 'next/image'; | |
function Product({ product }) { | |
const dispatch = useDispatch(); | |
const handleAddToCart = () => { | |
dispatch(addToCart(product)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { useSelector } from 'react-redux'; | |
import Link from 'next/link'; | |
const Header = () => { | |
const totalValue = useSelector((state) => state.totalValue); | |
const totalItems = useSelector((state) => state.totalItems); | |
return ( | |
<div className="w-full bg-slate-200 py-4 "> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import '../styles/globals.css'; | |
import { wrapper } from '../lib/store'; | |
import { PersistGate } from 'redux-persist/integration/react'; | |
import { useStore } from 'react-redux'; | |
function MyApp({ Component, pageProps }) { | |
const store = useStore(); | |
return ( | |
<PersistGate persistor={store.__persistor} loading={<div>Loading...</div>}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const products = [ | |
{ | |
id: 1, | |
name: 'Coffee beans - Costa Rica Finca la Planada', | |
price: '35', | |
imageSrc: '/costa-rica-finca-la-planada-600x600.jpg', | |
imageAlt: 'Coffee beans - Costa Rica Finca la Planada', | |
}, | |
//add more products | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlice } from '@reduxjs/toolkit'; | |
const initialState = { | |
cart: [], | |
totalValue: 0, | |
totalItems: 0, | |
}; | |
const cartSlice = createSlice({ | |
name: 'cart', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { configureStore } from '@reduxjs/toolkit'; | |
import { createWrapper } from 'next-redux-wrapper'; | |
import { persistReducer, persistStore } from 'redux-persist'; | |
import storage from 'redux-persist/lib/storage'; | |
import rootReducer from './reducer'; | |
const persistConfig = { | |
key: 'root', | |
storage, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from 'next/server' | |
export default async function middleware(req: NextRequest) { | |
const bot=checkBot(req.headers.user-agent); | |
if (bot=== true) { | |
const url = req.nextUrl; | |
url.pathname = `/404`; | |
return NextResponse.rewrite(url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextResponse } from 'next/server'; | |
export function middleware(request) { | |
const cookie = request.cookies.get('group') | |
if (group===1) { | |
const url = request.nextUrl.clone() | |
url.pathname = '/offer-1' | |
return NextResponse.rewrite(url) | |
} | |
if (group===2) { |