Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { useEffect } from 'react';
  2. import { BrowserRouter, Routes, Route } from 'react-router-dom';
  3. import Home from './pages/Home';
  4. import Cart from './pages/Cart';
  5. import Login from './pages/Login';
  6. import Newsletter from './pages/Newsletter';
  7. import Products from './pages/Products';
  8. import Product from './pages/Products/Product';
  9. import Checkout from './pages/Checkout';
  10. import Navbar from './components/Navbar';
  11. import Footer from './components/Footer/Footer';
  12. import Header from './components/Header';
  13. import theme from './theme/theme';
  14. import { ThemeProvider } from '@mui/material';
  15. import { fetchCart } from './redux/slices/cartSlice';
  16. import { useSelector, useDispatch } from 'react-redux';
  17. const isEmptyObject = (obj) => Object.keys(obj).length === 0 && obj.constructor === Object;
  18. function App() {
  19. const dispatch = useDispatch()
  20. useEffect(() => {
  21. //Check if cart exist
  22. let cartHistory = localStorage.getItem('amber-cart');
  23. cartHistory = cartHistory ? JSON.parse(cartHistory) : {};
  24. // if we got cart, then just fetch from BE based on ID
  25. if (!isEmptyObject(cartHistory)) {
  26. dispatch(fetchCart(cartHistory.id));
  27. }
  28. }, [])
  29. return (
  30. <ThemeProvider theme={theme}>
  31. <Header />
  32. <Navbar />
  33. <BrowserRouter>
  34. <Routes>
  35. <Route path='/' element={<Home />} />
  36. <Route path='/login' element={<Login />} />
  37. <Route path='products'>
  38. {/* All Products */}
  39. <Route index element={<Products />} />
  40. {/* Single Product */}
  41. <Route path=':pid' element={<Product />} />
  42. </Route>
  43. <Route path='/newsletter' element={<Newsletter />} />
  44. <Route path='/cart' element={<Cart />} />
  45. <Route path='/checkout' element={<Checkout />} />
  46. </Routes>
  47. </BrowserRouter>
  48. <Footer />
  49. </ThemeProvider>
  50. );
  51. }
  52. export default App;