Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
48 views
11 pages
Strapi
Uploaded by
1U20CA038Karthick raja.J
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download
Save
Save strapi For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
48 views
11 pages
Strapi
Uploaded by
1U20CA038Karthick raja.J
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save strapi For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save strapi For Later
You are on page 1
/ 11
Search
Fullscreen
Full stack Shopping Cart Application using Strapi.
Frontend (React js)
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
app.js
import {useState,useEffect} from 'react';
import apple from './apple.jpeg';
import orange from './orange.jpeg';
import cabbage from './cabbage.jpeg';
import beans from './beans.jpeg';
import axios from 'axios';
import Card from 'react-bootstrap/Card';
import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
import Button from 'react-bootstrap/Button';
function App() {
let photos = [apple,orange,cabbage,beans];
let products = [{name:"Apple",country:"India",instock:10,price:120},
{name:"Orange",country:"India",instock:10,price:100},
{name:"cabbage",country:"srilanka",instock:12,price:50},
{name:"beans",country:"UK",instock:12,price:80}]
let [item,setItem] = useState(products)
let [cart,setCart] = useState([])
let [cost,setCost] = useState(0)
let [data,setData] = useState([])
let [name,setName] = useState("")
let [country,setCountry] = useState("")
let [instock,setInstock] = useState("")
let [price,setPrice] = useState("")
let [delTrigger,setDelTrigger] = useState(false);
const [productId,setProductId] = useState('');
let [productIdDel,setProductIdDel] = useState('')
let url = "http://localhost:1337/api/carts";
function addCart(selectedItem){
if(selectedItem.instock <=0){
alert('Out of stock');
return;
}
const newCart =[...cart];
let itemFound = false;
for(let i=0;i<newCart.length;i++){
if(newCart[i].name===selectedItem.name){
newCart[i].quantity++;
itemFound=true;
break;
}
}
if(!itemFound){
newCart.push({...selectedItem,quantity:1})
}
const newList = item.map((listItem)=>
listItem.name===selectedItem.name ? {...listItem,instock:listItem.instock-1}:listItem)
setCart(newCart)
let newTotal = 0;
newCart.forEach((item)=>{
newTotal += item.price * item.quantity;
})
setCost(newTotal)
setItem(newList)
}
console.log(cart)
console.log(data)
useEffect(()=>{
async function fetchdata(){
let res = await axios(url);
let result = res.data;
setData(result)
}
fetchdata();
},[url])
const restockproducts = (data) =>{
let newItem = data.data.map((item)=>{
let {name,country,price,instock} = item.attributes;
return {name,country,price,instock}
});
setItem([...newItem])
console.log(item)
}
function handleSubmit(){
axios.post('http://localhost:1337/api/carts',{"data":{name,country,instock,price}})
}
const handleSubmitUpdate = async (e) => {
e.preventDefault();
await axios.put(`http://localhost:1337/api/carts/${productId}`, {"data":{name,
country,
instock,
price}
});
alert("Updated Successfully")
setName('');
setCountry('');
setInstock('');
setPrice('');
};
const handleDel = async() =>{
await axios.delete(`http://localhost:1337/api/carts/${productIdDel}`);
alert("Product Deleted");
}
return (<>
<h1 className='heading'>Shopping Cart</h1>
<div className='row'>
{
item.map((item,key)=><div className='col-md-3'>
<Card style={{ width: '25rem' }}>
<Card.Img variant="top" src={photos[key%4]} height={200} width={100} />
<Card.Body>
<Card.Text>
<h5>Name : {item.name}<br></br> Instock : {item.instock} <br></br> Price :$
{item.price}</h5>
</Card.Text>
<Button onClick={()=>addCart(item)} variant="success" className='cart'>Add To
Cart</Button>
</Card.Body>
</Card>
</div>)
}
</div>
<h2 className='citems'>Cart Items</h2><br></br>
<h5 className='item'>{cart.map((item,key)=><h5
style={{color:'indigo'}}>Name: {item.name}
Quantity: {item.quantity}</h5>)}</h5>
<h2 className='citems'>Total Cost</h2><br></br><h5 style={{color:'indigo'}}
className='tot'>{cost}</h5>
<h2 className='citems'>Restock Items</h2>
<form className='form1' onSubmit={(e) => {
restockproducts(data);
e.preventDefault();
}}>
<input type='text' value={url}></input>
<button>Submit</button>
</form>
<h2 className='citems'>Create a Data</h2>
<form className='form2' onSubmit={handleSubmit}>
<input onChange={(e)=>setName(e.target.value)} type='text' placeholder='Enter
Name'></input>
<input onChange={(e)=>setCountry(e.target.value)} type='text' placeholder='Enter
Country'></input>
<input onChange={(e)=>setInstock(e.target.value)} type='text' placeholder='Enter
Stock'></input>
<input onChange={(e)=>setPrice(e.target.value)} type='text' placeholder='Enter
Cost'></input><br></br>
<button type='submit'>Push</button>
</form>
<div>
<h2 className='citems'>Update Product Details</h2><br></br>
<form className='form3' onSubmit={handleSubmitUpdate}>
<input
type="text"
value={productId}
onChange={(e) => setProductId(e.target.value)}
placeholder="Enter product Id"/>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter Name"/>
<input
type="text"
value={country}
onChange={(e) => setCountry(e.target.value)}
placeholder="Enter Country"/>
<input
type="text"
value={instock}
onChange={(e) => setInstock(e.target.value)}
placeholder="Enter Stock"/>
<input
type="text"
value={price}
onChange={(e) => setPrice(e.target.value)}
placeholder="Enter Price"/>
<button type="submit">Update Product</button>
</form>
</div>
<h2 className='citems'>Delete Items</h2><br></br>
<form className='form4'>
<input
type="text"
value={productIdDel}
onChange={(e) => setProductIdDel(e.target.value)}
placeholder="Enter Product Id to delete"/>
<button type="submit" onClick={handleDel}>Delete Product</button>
</form>
</>);
}
export default App;
App.css
body{
background-color:black;
}
.heading{
text-align: center;
color: white;
background-color: green;
padding: 15px;
font-family:Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
letter-spacing: 3px;
margin-bottom: 30px;
}
.citems{
text-align: center;
margin-top: 40px;
color: green;
font-family: Verdana, Geneva, Tahoma, sans-serif;
text-shadow: 0px 0px 5px darkgreen;
}
.item{
text-align: center;
}
.tot{
text-align: center;
}
input{
display:list-item;
margin: 10px;
height: 45px;
width: 500px;
border: 2px solid palevioletred;
border-radius: 10px;
text-align: center;
}
button{
height: 45px;
width: 500px;
margin: 10px;
background-color: palevioletred;
border: none;
border-radius: 10px;
}
.form1,.form2,.form3,.form4{
/* margin-left: 480px; */
display: grid;
justify-content: center;
align-items: center;
}
.cart{
width: 150px;
height: 50px;
padding: 0px;
margin: 15%;
}
Output:
You might also like
Comen S8 Service Manual
PDF
100% (1)
Comen S8 Service Manual
59 pages
# Managing Conflict in The Workplace
PDF
100% (2)
# Managing Conflict in The Workplace
53 pages
Brand List Page
PDF
No ratings yet
Brand List Page
5 pages
Pompa (P-01 Sampai P-07)
PDF
No ratings yet
Pompa (P-01 Sampai P-07)
62 pages
Steel Beams Analysis
PDF
No ratings yet
Steel Beams Analysis
15 pages
Crud Operation: Create Insert Delete Update Records in Reactjs
PDF
100% (1)
Crud Operation: Create Insert Delete Update Records in Reactjs
10 pages
Organisational Behaviour
PDF
No ratings yet
Organisational Behaviour
75 pages
RCW - Eng
PDF
No ratings yet
RCW - Eng
77 pages
Oracle Upgrade To EBS R12
PDF
No ratings yet
Oracle Upgrade To EBS R12
10 pages
Crack Propagation in Ansys
PDF
100% (2)
Crack Propagation in Ansys
24 pages
E Commerce
PDF
No ratings yet
E Commerce
2 pages
Product Assignment
PDF
No ratings yet
Product Assignment
5 pages
Raport Practica 2024
PDF
No ratings yet
Raport Practica 2024
41 pages
Nuevo Documento de Texto
PDF
No ratings yet
Nuevo Documento de Texto
9 pages
FS Record
PDF
No ratings yet
FS Record
52 pages
1
PDF
No ratings yet
1
83 pages
Index
PDF
No ratings yet
Index
34 pages
Order History Page
PDF
No ratings yet
Order History Page
4 pages
Cartreducer 1
PDF
No ratings yet
Cartreducer 1
2 pages
Chapter5 6 7
PDF
No ratings yet
Chapter5 6 7
28 pages
Product
PDF
No ratings yet
Product
2 pages
Category JS
PDF
No ratings yet
Category JS
6 pages
MaterialUI Card
PDF
No ratings yet
MaterialUI Card
2 pages
Clinical and Health Psychology
PDF
No ratings yet
Clinical and Health Psychology
14 pages
Canteen Management - 22bd1a0527
PDF
No ratings yet
Canteen Management - 22bd1a0527
12 pages
React Meals
PDF
No ratings yet
React Meals
28 pages
New 1
PDF
No ratings yet
New 1
2 pages
WT Exp 12
PDF
No ratings yet
WT Exp 12
12 pages
PC300 (350) - 7 20001-Up Engine Control
PDF
No ratings yet
PC300 (350) - 7 20001-Up Engine Control
6 pages
Fodd Delivery
PDF
No ratings yet
Fodd Delivery
3 pages
Food Ordering System
PDF
No ratings yet
Food Ordering System
7 pages
2-5 Acceleration: Distance Above The Floor, Showing Its Position at Regular Time Intervals As It Falls
PDF
No ratings yet
2-5 Acceleration: Distance Above The Floor, Showing Its Position at Regular Time Intervals As It Falls
9 pages
Header
PDF
No ratings yet
Header
7 pages
Ecoms 2
PDF
No ratings yet
Ecoms 2
17 pages
Compiler Design
PDF
No ratings yet
Compiler Design
4 pages
WDF Unit 3 Programms
PDF
No ratings yet
WDF Unit 3 Programms
7 pages
Document 1
PDF
No ratings yet
Document 1
9 pages
AMAZON
PDF
No ratings yet
AMAZON
53 pages
Nodejs Lab Program 3
PDF
No ratings yet
Nodejs Lab Program 3
5 pages
Batch 10 Assignment 08
PDF
No ratings yet
Batch 10 Assignment 08
5 pages
Easy Sell
PDF
No ratings yet
Easy Sell
14 pages
Const (Companyphone, setCompanyPhon
PDF
No ratings yet
Const (Companyphone, setCompanyPhon
7 pages
FSD Project MID 2
PDF
No ratings yet
FSD Project MID 2
19 pages
Lab 15
PDF
No ratings yet
Lab 15
14 pages
Step 1 Set Up Laragon
PDF
No ratings yet
Step 1 Set Up Laragon
5 pages
Analogy
PDF
No ratings yet
Analogy
4 pages
Mis Project Idea
PDF
No ratings yet
Mis Project Idea
11 pages
Crud React Redux
PDF
No ratings yet
Crud React Redux
5 pages
Chawi
PDF
No ratings yet
Chawi
5 pages
Electrical Master Electrician
PDF
No ratings yet
Electrical Master Electrician
2 pages
Web Tech Lab-10 140
PDF
No ratings yet
Web Tech Lab-10 140
11 pages
Frontend Assignment - Whatbytes
PDF
No ratings yet
Frontend Assignment - Whatbytes
4 pages
Ajay Lovestory
PDF
No ratings yet
Ajay Lovestory
2 pages
React E-Commerce Website
PDF
No ratings yet
React E-Commerce Website
8 pages
Home JSX
PDF
No ratings yet
Home JSX
5 pages
Centenary of 'A Portrait of The Artist As A Young Man' (ABEI Journal, Vol.18-2016)
PDF
No ratings yet
Centenary of 'A Portrait of The Artist As A Young Man' (ABEI Journal, Vol.18-2016)
206 pages
React Training Assignment-Problem Statement
PDF
No ratings yet
React Training Assignment-Problem Statement
1 page
Chat Fruit E Commerce Website
PDF
No ratings yet
Chat Fruit E Commerce Website
75 pages
SDC Program 01
PDF
No ratings yet
SDC Program 01
17 pages
Laravel 5 Simple Crud Application Using Reactjs Part 2
PDF
No ratings yet
Laravel 5 Simple Crud Application Using Reactjs Part 2
8 pages
ReactJS Assignment
PDF
No ratings yet
ReactJS Assignment
3 pages
Case Study Problem Statement - React JS
PDF
No ratings yet
Case Study Problem Statement - React JS
15 pages
ShopEZ - E-Commerce Application - Report
PDF
No ratings yet
ShopEZ - E-Commerce Application - Report
14 pages
Jsonaddtocart
PDF
No ratings yet
Jsonaddtocart
6 pages
G Mart Review
PDF
No ratings yet
G Mart Review
6 pages
Performance Evaluation Form
PDF
No ratings yet
Performance Evaluation Form
1 page
GrNo.2 Consumer Dashboard
PDF
No ratings yet
GrNo.2 Consumer Dashboard
10 pages
Fullstack Assignment
PDF
No ratings yet
Fullstack Assignment
4 pages
React Practical Test
PDF
No ratings yet
React Practical Test
2 pages
Objective:: Lab#10: 7-Segment Display SSUET/QR/114
PDF
No ratings yet
Objective:: Lab#10: 7-Segment Display SSUET/QR/114
4 pages
E-Commerce Web Application Report
PDF
No ratings yet
E-Commerce Web Application Report
5 pages
Project
PDF
No ratings yet
Project
25 pages
E-Commerce Web App Practical Report
PDF
No ratings yet
E-Commerce Web App Practical Report
4 pages
Seanewdim Philology Ii10 Issue 47
PDF
No ratings yet
Seanewdim Philology Ii10 Issue 47
118 pages
Idef02 - BPWin Standard
PDF
No ratings yet
Idef02 - BPWin Standard
238 pages
2nd Grade Skills Checklist: Reading & Language Arts
PDF
No ratings yet
2nd Grade Skills Checklist: Reading & Language Arts
4 pages
E Commerce
PDF
No ratings yet
E Commerce
5 pages
Complete Shopping API Spec
PDF
No ratings yet
Complete Shopping API Spec
4 pages
Industry 4.0
PDF
No ratings yet
Industry 4.0
4 pages
Organisational Change Od Assignment
PDF
No ratings yet
Organisational Change Od Assignment
12 pages
An Agenda For Gesture Studies
PDF
No ratings yet
An Agenda For Gesture Studies
19 pages
Stockhausen Serves Imperialism, and Other Articles With Commentary and Notes (Cornelius Cardew) (Z-Library)
PDF
No ratings yet
Stockhausen Serves Imperialism, and Other Articles With Commentary and Notes (Cornelius Cardew) (Z-Library)
132 pages
11.cattle Insurance
PDF
No ratings yet
11.cattle Insurance
22 pages
Kung 2015
PDF
No ratings yet
Kung 2015
37 pages
MasterEase 3503 v1
PDF
No ratings yet
MasterEase 3503 v1
2 pages
76.research On The Influence of Heat Treatment On The
PDF
No ratings yet
76.research On The Influence of Heat Treatment On The
7 pages
SPM Unit2
PDF
No ratings yet
SPM Unit2
17 pages
Mesin Skala Industri
PDF
No ratings yet
Mesin Skala Industri
2 pages
Activity 6-2 Name: Joella Mae Escanda Section: B
PDF
No ratings yet
Activity 6-2 Name: Joella Mae Escanda Section: B
2 pages
NgRx SignalStore: An effortless solution for state management
From Everand
NgRx SignalStore: An effortless solution for state management
Abdelfattah Ragab
No ratings yet