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.

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