Skip to content

Commit 357248b

Browse files
author
Vadim Rogov
committed
added popup & code refactoring
1 parent 0eaae82 commit 357248b

File tree

15 files changed

+162
-75
lines changed

15 files changed

+162
-75
lines changed

src/App.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { Component } from "react";
2-
import Shop from "./components/shop";
3-
import AboutUs from "./components/about-us";
4-
import ContactUs from "./components/contact-us";
5-
import TermsConditions from "./components/terms-conditions";
6-
import Checkout from "./components/checkout";
7-
import Cart from "./components/cart";
8-
import { MenuBar } from "./components/menu-bar";
2+
import Shop from "./components/Shop";
3+
import AboutUs from "./components/AboutUs";
4+
import ContactUs from "./components/ContactUs";
5+
import TermsConditions from "./components/TermsConditions";
6+
import Checkout from "./components/Checkout";
7+
import Cart from "./components/Cart";
8+
import { MenuBar } from "./components/MenuBar";
99
import { data, manufacturers } from "./db/db";
1010

1111
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
File renamed without changes.

src/components/common-link-btn.js renamed to src/components/CommonLinkBtn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, { Component } from "react";
22
import { Link } from "react-router-dom";
33

4-
export class CommonBtn extends Component {
4+
export class CommonLinkBtn extends Component {
55
render() {
66
const { linkTo, linkName } = this.props;
77

88
return (
99
<Link to={linkTo}>
10-
<button className="common-link-btn">{linkName}</button>
10+
<button className="CommonLinkBtn">{linkName}</button>
1111
</Link>
1212
);
1313
}

src/components/ContactUs.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { Component, Fragment } from "react";
2+
import Popup from "./Popup";
3+
4+
class ContactUs extends Component {
5+
state = {
6+
email: "",
7+
msg: "",
8+
popupActive: false
9+
};
10+
11+
changeEmailHandler = value =>
12+
this.setState({
13+
email: value
14+
});
15+
16+
changeMessageHandler = value =>
17+
this.setState({
18+
msg: value
19+
});
20+
21+
flushStateHandler = () =>
22+
this.setState({
23+
email: "",
24+
msg: "",
25+
popupActive: true
26+
});
27+
28+
closePopupHandler = () => {
29+
this.setState({
30+
popupActive: false
31+
});
32+
};
33+
34+
render() {
35+
return (
36+
<Fragment>
37+
{this.state.popupActive && (
38+
<Popup
39+
popupHeader={"Server say:"}
40+
renderPopupContentHandler={() => <img class="img-responsive" src='https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LtZJGF3BnjoLSeYeXE_%2F-LuOTLcQnAaCxuZPlxc2%2F-LuOVsoiOc6D7i8HNglF%2F2300883_3.jpg?alt=media&token=0c6d76e7-f6d9-4c08-ab92-5d7032935575' alt='no'/>}
41+
closePopupContentHandler={this.closePopupHandler}
42+
/>
43+
)}
44+
<div className="page-body">
45+
<div className="page-element">
46+
<h2>CONTACT US</h2>
47+
E-mail:
48+
<input
49+
value={this.state.email}
50+
className="filter-small"
51+
onChange={e => this.changeEmailHandler(e.target.value)}
52+
placeholder="Enter your email"
53+
/>
54+
Message:
55+
<textarea
56+
value={this.state.msg}
57+
className="input-field-large"
58+
onChange={e => this.changeMessageHandler(e.target.value)}
59+
placeholder="Enter your message..."
60+
/>
61+
<button
62+
className="common-btn"
63+
onClick={() => this.flushStateHandler()}
64+
>
65+
Send
66+
</button>
67+
</div>
68+
</div>
69+
</Fragment>
70+
);
71+
}
72+
}
73+
74+
export default ContactUs;

src/components/item-cart.js renamed to src/components/ItemCart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ItemCart extends Component {
1414
} = this.props;
1515

1616
return (
17-
<div className="item-cart">
17+
<div className="ItemCart">
1818
<div className="item-header">
1919
<img className="item-picture" src={item.picture} alt='not found'/>
2020
<div>
File renamed without changes.

src/components/menu-bar.js renamed to src/components/MenuBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from "react";
2-
import { NavBtn } from "./header-btn";
2+
import { NavBtn } from "./NavBtn";
33
export class MenuBar extends Component {
44
render() {
55
return (
File renamed without changes.

src/components/Popup.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { Component } from "react";
2+
3+
class Popup extends Component {
4+
constructor(props) {
5+
super(props);
6+
this.myRef = React.createRef();
7+
}
8+
9+
componentDidMount() {
10+
window.addEventListener("mousedown", this.onClickOutside);
11+
}
12+
13+
componentWillUnmount() {
14+
window.removeEventListener("mousedown", this.onClickOutside);
15+
}
16+
17+
onClickOutside = e => {
18+
if (this.myRef && !this.myRef.current.contains(e.target)) {
19+
this.props.closePopupContentHandler();
20+
}
21+
};
22+
render() {
23+
const {
24+
popupHeader,
25+
renderPopupContentHandler,
26+
closePopupContentHandler
27+
} = this.props;
28+
return (
29+
<div className="popup-element page-element" ref={this.myRef}>
30+
<div className="popup-header">
31+
<h2> {popupHeader.toUpperCase()} </h2>
32+
</div>
33+
<div className="popup-body">
34+
<div>{renderPopupContentHandler()}</div>
35+
</div>
36+
<div className="popup-footer">
37+
<button
38+
className="common-btn"
39+
onClick={() => closePopupContentHandler()}
40+
>
41+
Close
42+
</button>
43+
</div>
44+
</div>
45+
);
46+
}
47+
}
48+
49+
export default Popup;
File renamed without changes.

0 commit comments

Comments
 (0)