Skip to content

Commit 44842cb

Browse files
committed
after edit product redirect to edit profil settimeout 1500
1 parent 6523c8a commit 44842cb

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

src/Components/EditProduct.js

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import axios from "axios";
44
import { connect } from "react-redux";
55
import UserBox from "./Small/UserBox";
66
import ButtonComponent from "./Small/ButtonComponent";
7+
import { withRouter } from "react-router-dom";
78

89
class CreateProductPage extends Component {
910
constructor(props) {
@@ -31,20 +32,30 @@ class CreateProductPage extends Component {
3132
}
3233

3334
componentDidMount() {
34-
axios.get(`http://localhost:8080/products/${localStorage.getItem("productIdToEdit")}`)
35-
.then((result) => {
36-
this.setState({
37-
category: result.data[0].category,
38-
name: result.data[0].name,
39-
description: result.data[0].description,
40-
url: result.data[0].url,
41-
prices: result.data[0].prices,
42-
id_user_affiliate: result.data[0].id_user_affiliate,
35+
try {
36+
axios
37+
.get(
38+
`http://localhost:8080/products/${localStorage.getItem(
39+
"productIdToEdit"
40+
)}`
41+
)
42+
.then((result) => {
43+
this.setState({
44+
category: result.data[0].category,
45+
name: result.data[0].name,
46+
description: result.data[0].description,
47+
url: result.data[0].url,
48+
prices: result.data[0].prices,
49+
id_user_affiliate: result.data[0].id_user_affiliate,
50+
});
51+
})
52+
.catch(() => {
53+
console.log("Oops, request failed!");
4354
});
44-
})
45-
.catch(() => {
46-
console.log("Oops, request failed!");
47-
});
55+
} catch (error) {
56+
console.log(error)
57+
}
58+
4859
}
4960

5061
handleCategory(event) {
@@ -88,23 +99,23 @@ class CreateProductPage extends Component {
8899
};
89100
switch (true) {
90101
case productObject.category.length < 2:
91-
alert("category error: min 2 characters");
102+
alert("Category error: min 2 characters");
92103
break;
93104
case productObject.name.length < 3:
94-
alert("name error: min 3 characters");
105+
alert("Name error: min 3 characters");
95106
break;
96107
case productObject.description.length < 10:
97-
alert("description required min 10 characters");
108+
alert("Description required min 10 characters");
98109
break;
99110
case productObject.url.length < 10:
100-
alert("url of product picture required min 10 characters");
111+
alert("Url of product picture required min 10 characters");
101112
break;
102113
case productObject.prices.length < 1:
103114
alert("Price missing");
104115
break;
105116
default:
106117
try {
107-
console.log("PRODUCT OBJECT EDIT",productObject);
118+
console.log("PRODUCT OBJECT EDIT", productObject);
108119
axios
109120
.post(
110121
`http://localhost:8080/productEdit/${productIdToEdit}`,
@@ -125,6 +136,9 @@ class CreateProductPage extends Component {
125136
prices: "",
126137
id_user_affiliate: "",
127138
});
139+
let that = this
140+
setTimeout(function(){ that.props.history.push("/editProfil");}, 1500);
141+
128142
})
129143
.catch(() => {
130144
console.log("Oops, request failed!");
@@ -189,11 +203,13 @@ class CreateProductPage extends Component {
189203
<div>
190204
<div className="login-box">
191205
<h2>Edit Product</h2>
206+
<img className="uploadImg" src={this.state.url} alt="" />
207+
<br/><br/>
192208
<form>
193209
{formInput.map((elem) => {
194210
return <UserBox props={elem} key={elem.id} />;
195211
})}
196-
<img className="uploadImg" src={this.state.url} alt="" />
212+
197213
<ButtonComponent click={this.buttonIsClick} text="Edit" />
198214

199215
{submitProduct}
@@ -207,7 +223,7 @@ class CreateProductPage extends Component {
207223
const mapStateToProps = (state) => ({
208224
token: state.userReducer.token,
209225
productIdToEdit: state.productReducer.productIdToEdit,
210-
id: state.userReducer.id
226+
id: state.userReducer.id,
211227
});
212228

213-
export default connect(mapStateToProps)(CreateProductPage);
229+
export default connect(mapStateToProps)(withRouter(CreateProductPage));

src/Styles/EditProfilComponent.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ body {
8383
/*********** Uplaoad url image ***********/
8484
.uploadImg {
8585
max-width: 300px;
86-
max-height: 150px;
87-
margin-left: 50px;
86+
height: 150px;
87+
/* margin-left: 50px; */
88+
margin-left: 35%;
89+
8890
}
8991

9092
#buttonNotVisible {

0 commit comments

Comments
 (0)