Advertisement
binix777

Untitled

May 26th, 2022
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import logo from './logo.svg';
  3. import './App.css';
  4. import Header from './components/header.js'
  5. import Category from './components/category.js'
  6. import Footer from './components/footer.js'
  7. import Product from './components/product.js'
  8. import Account from './components/account.js'
  9. import AllProducts from './components/allproducts.js'
  10. import Deals from './components/deals.js'
  11. import ProductPage from './components/product_page.js'
  12. import Cart from './components/cart.js'
  13. import PaymentPage from './components/payment_page.js'
  14. import promoted from './components/promoted.js'
  15. import review from './components/review.js'
  16. import ReviewSection from './components/ReviewSection.js'
  17. import suggestions from './components/suggestions.js'
  18. import { Route, Link, BrowserRouter } from 'react-router-dom'
  19.  
  20.  
  21.  
  22. import React, { Component } from 'react'
  23.  
  24. export default class App extends Component {
  25.  
  26.   constructor(props) {
  27.     super(props)
  28.     this.state = {
  29.       page: "products",
  30.       user_id: null,
  31.       email: null,
  32.       country: null,
  33.       city: null,
  34.       address: null,
  35.       postal_code: null,
  36.       promo_code: "none",
  37.       logged_id: false
  38.  
  39.     }
  40.  
  41.  
  42.  
  43.   }
  44.  
  45.  
  46.   setPage(page) {
  47.     this.setState({
  48.       page: page
  49.  
  50.     })
  51.  
  52.   }
  53.  
  54.  
  55.   addPromoCode(promo_code) {
  56.     fetch("http://localhost/Websites/GeneralStore/endpoint/check_promo_code.php?code=" + promo_code).then(function (response) {
  57.       return response.json();
  58.     }).then(function (data) {
  59.       if (data.status == "success") {
  60.         console.log("promo code is valid");
  61.         this.setState({
  62.           promo_code: promo_code
  63.         })
  64.        
  65.       }
  66.       else {
  67.         console.log("invalid promo code");
  68.  
  69.  
  70.       }
  71.     })
  72.   }
  73.      
  74.   componentWillMount() {
  75.     fetch("http://localhost/Websites/GeneralStore/endpoint/validate_session.php?session_id=" + "user").then(function (response) {
  76.       return response.json();
  77.     }
  78.     ).then(function (data) {
  79.       if (data.status == "success") {
  80.         this.setState({
  81.           user_id: data.user_id,
  82.           email: data.email,
  83.           country: data.country,
  84.           city: data.city,
  85.           address: data.address,
  86.           postal_code: data.postal_code,
  87.           logged_id: true
  88.          
  89.         })
  90.  
  91.  
  92.  
  93.         console.log("logged in");
  94.       }
  95.       else {
  96.         console.log("not logged in");
  97.       }
  98.     })
  99.   }
  100.      
  101.   render() {
  102.  
  103.     console.log(this.state.page)
  104.  
  105.     if (this.state.page == "account") {
  106.       return (
  107.         <div className="App">
  108.           <Header />
  109.           <Account />
  110.           <Footer />
  111.         </div>
  112.       );
  113.     }
  114.  
  115.     if (this.state.page == "all-products") {
  116.       return (
  117.         <div className="App">
  118.           <Header />
  119.           <AllProducts />
  120.           <Footer />
  121.         </div>
  122.       );
  123.     }
  124.  
  125.     if (this.state.page == "deals") {
  126.       return (
  127.         <div className="App">
  128.           <Header />
  129.           <Deals />
  130.           <Footer />
  131.         </div>
  132.       );
  133.  
  134.  
  135.     }
  136.  
  137.     if (this.state.page == "cart") {
  138.       return (
  139.         <div className="App">
  140.           <Header />
  141.           <Cart />
  142.           <Footer />
  143.         </div>
  144.       );
  145.     }
  146.  
  147.  
  148.     if (this.state.page == "product")
  149.     {
  150.       return (
  151.         <div className="App">
  152.           <Header />
  153.           <ProductPage />
  154.           <Footer />
  155.         </div>
  156.       );
  157.      
  158.      
  159.     }
  160.  
  161.     if (this.state.page == "products") {
  162.       return (
  163.         <div>
  164.           <Header />
  165.           <Category categoryName="fruits" description="Any food that has seeds in it is considred a fruit." className="fruits" />
  166.    
  167.           <Category categoryName="Vegetables" description="Vegetables are cool." className="vegetables" />
  168.  
  169.      
  170.           <Category categoryName="Grains" description="Things like rice and flour go here." className="grains" />
  171.    
  172.           <Category categoryName="Snacks" description="All the snacks you could ever want." className="snacks" />
  173.    
  174.    
  175.           <Category categoryName="oils" description="Very oily xD" className="oils" />
  176.    
  177.    
  178.           <a href="all-products" onClick={() => { this.setPage("all-products"); alert("bruh") }}>View All Products</a>
  179.           <Footer />
  180.         </div>
  181.       );
  182.     }
  183.  
  184.     if (this.state.page == "payment_page") {
  185.       return (
  186.         <div>
  187.           <Header />
  188.           <PaymentPage />
  189.           <Footer />
  190.         </div>
  191.       );
  192.  
  193.    
  194.  
  195.  
  196.  
  197.     }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.   }
  204.  
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
Advertisement
RAW Paste Data Copied
Advertisement