Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, {Component} from 'react';
import MainPage from "./pages/main-page.js"
import AdminPage from "./pages/admin-page.js"
import UserPage from "./pages/user-page.js"
import ShopingCard from "./pages/shoping-card.js"

import './App.css';

class App extends Component {
constructor(){
super();
this.state = {
activePage: "mainPage"
}
}

changeActivePageToAdminPage = () => {
this.setState({
activePage: "adminPage"
})
}

changeActivePageToUserPage = () => {
this.setState({
activePage: "userPage"
})
}

changeActivePageToShopCardPage = () => {
this.setState({
activePage: "shopingCard"
})
}

changeActivePageToMainPage = () => {
this.setState({
activePage: "mainPage"
})
}



render() {
const {activePage} = this.state;

if (activePage == "mainPage") {
return (
<MainPage
changeActivePageToUserPage ={this.changeActivePageToUserPage}
changeActivePageToAdminPage ={this.changeActivePageToAdminPage}
/>)
}
if (activePage == "adminPage") {
return (
<AdminPage
changeActivePageToMainPage = {this.changeActivePageToMainPage}
changeActivePageToShopCardPage = {this.changeActivePageToShopCardPage}
/>)
}
if (activePage == "userPage") {
return (
<UserPage
changeActivePageToMainPage ={this.changeActivePageToMainPage}
changeActivePageToShopCardPage={this.changeActivePageToShopCardPage}
/>)
}
if (activePage == "shopingCard") {
return (
<ShopingCard
changeActivePageToMainPage={this.changeActivePageToMainPage}
/>)
}

}
}

export default App;
74 changes: 74 additions & 0 deletions pages/admin-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, {Component} from 'react';
import staff from "../shoping-goods";
import "bootstrap/dist/css/bootstrap.css"

class AdminPage extends Component {
render() {


let ShopsGoods = staff.map((value, index, arr)=>{
return (
<li className="list-group-item" key={value.id}>
<img src="#" alt=""/>
<a href="#" className="admin-orders__link">
{value.text}
</a>
<h2 className="float-right btn-link">✎</h2>
</li>
)
})

let addStaffToShopingGoods = ()=>{
let text = document.getElementById("enterNewName").value
let id = Math.random()*100000000000000000
let newOnj = {
id: id,
text: text,
}
staff.push(newOnj)

}

const {
changeActivePageToMainPage,
changeActivePageToShopCardPage,
} = this.props

return (
<div className="container flex-grow-1">
<div className="row">
<div className="col-8">
<div className="admin-orders">
<h1>ADMIN PAGE</h1>

{ShopsGoods}
<br/>
<div className="input-group mb-3">
<div className="input-group-prepend">
<span className="input-group-text" id="basic-addon1">@</span>
</div>
<input type="text" className="form-control" id="enterNewName" placeholder="enter new name"/>
<button className="btn btn-primary" onClick ={addStaffToShopingGoods}>Add</button>
</div>
</div>
</div>
<div className="col-4">
<div>
Admin
</div>
<button
onClick = {changeActivePageToMainPage}
>User Logout</button>
<button
onClick = {changeActivePageToShopCardPage}
>Shop Card</button>
</div>
</div>
</div>

)
}
}


export default AdminPage;
29 changes: 29 additions & 0 deletions pages/main-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, {Component} from 'react';

class MainPage extends Component {


render() {
const {
changeActivePageToAdminPage,
changeActivePageToUserPage,
} = this.props

return (
<div className="container">
<h1>Main Page</h1>
<div className="row">
<button
className="btn btn-primary"
onClick={changeActivePageToAdminPage}
>Login as Admin</button>
<button
className="btn btn-outline-primary"
onClick={changeActivePageToUserPage}
>Login as User</button>
</div>
</div>
)
}
}
export default MainPage;
53 changes: 53 additions & 0 deletions pages/shoping-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {Component} from 'react';
import staffInShoppingCart from "../shoping-goods-who-has-added-to-chop";


class ShopingCard extends Component {
render() {
const {
changeActivePageToMainPage,

} = this.props


let staffFromStaffInShoppingCart = staffInShoppingCart.map((value)=>{
return (
<li className="list-group-item">
<img src="#" alt=""/>
<a href="#" className="admin-orders__link">
{value.text}
</a>
<h2 className="float-right badge-light">✓</h2>
</li>
)
})
return (
<div className="container">
<div className="row">
<div className="col-8">
<h1>Shopping Cart</h1>
<ul className="list-group">

{staffFromStaffInShoppingCart}
</ul>
</div>
<div className="col-4">
<div>
User
</div>
<button onClick={changeActivePageToMainPage}>User Logout</button>
</div>
</div>
<div className="row">
<pre>price:</pre>
</div>
<div className="row">
<button className="btn btn-primary">Ship it</button>
</div>
</div>
)
}
}


export default ShopingCard;
74 changes: 74 additions & 0 deletions pages/user-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, {Component} from 'react';
import staff from "../shoping-goods";
import "bootstrap/dist/css/bootstrap.css";
import staffInShoppingCart from "../shoping-goods-who-has-added-to-chop";

class UserPage extends Component {
render() {

const {
changeActivePageToMainPage,
changeActivePageToShopCardPage
} = this.props

// let addStaffToShoppingCart = (id)=> {
// let text = "";
// let newObj = {
//
// }
// console.log(this);
// }

let ShopsGoods = staff.map((value, index, arr)=>{
let text = value.text
let id = value.id
return (
<div className="card" key = {value.id} id = {value.id}>
<div className="card-body">
<h5 className="card-title">{value.text}</h5>
<p className="card-text">{value.text}</p>
<button className="btn btn-primery btn-lg" id={index} onClick={
e => {
staffInShoppingCart.push({
id: id,
text: text

})
}
} >Buy</button>
<h3 className="text-success">✓✓✓✓✓</h3>
</div>
</div>
)
})

return (
<div className="container">
<h1>USER PAGE</h1>
<div className="row">
<div className="col-8">
<div className="row">
{ShopsGoods}

</div>
</div>
<div className="col-4">
<div>
User
</div>
<button
onClick={changeActivePageToMainPage}
>User Logout</button>
<button
onClick={changeActivePageToShopCardPage}
>Shopping Cart</button>
</div>
</div>
</div>
)
}
}



export default UserPage;
1 change: 1 addition & 0 deletions shoping-goods-who-has-added-to-chop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default []
14 changes: 14 additions & 0 deletions shoping-goods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default [
{
"id": "4567876543456",
"text": "MacBook pro 2018"
},
{
"id": "4567876545676",
"text": "Dell xs"
},
{
"id": "2345654567878",
"text": "Microsoft Surface"
}
]