Link Errormessage Field: Constructor
Link Errormessage Field: Constructor
constructor(props){
super(props);
this.state={
user:{
}
}
}
render(){
<br/>
<h2>Logiraj se</h2>
<hr/>
<br/>
<Formik
enableReinitialize={true}
initialValues={this.state.user}
onSubmit={(values, actions) => {
this.setState({
isSaving:true,
saved:false,
error:false
})
dataService.login(values).then(response=>{
debugger
if(response && (response.status==201 || response.status==200)){
this.setState({
saved:true,
isSaving:false,
})
window.location.href="http://localhost:3000/products"
}
else{
this.setState({
error:true,
isSaving:false
})
}
})
}}
validationSchema={
yup.object().shape({
render={props => (
<form onSubmit={props.handleSubmit} className="needs-validation">
)}
/>
<hr/>
<Link to="/register">Registriraj se</Link>
</div>
</div>)
}
}
import React, { Component } from 'react';
import ProductItem from './ProductItem'
import { Link } from 'react-router-dom'
import dataService from '../dataService';
constructor(props) {
super(props);
this.state = {
products: [],
isLoading: true
};
componentDidMount() {
this.setState({isLoading: true});
dataService.getProducts()
.then(data =>{
this.setState({products: data, isLoading: false})
}
);
}
render(){
return (<div class="col-md-12">
<br/>
<h2>Proizvodi</h2>
<hr/>
<Link to="/products/-1/addEdit" className="btn btn-primary">Dodaj
novi proizvod</Link>
<hr/>
<div className="row">
{this.state.products.map((product)=>{
return (
<div className="col-md-3">
<ProductItem product={product} />
</div>
)
})
}
</div>
</div>
)
}
}
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import dataService from '../dataService';
export default class ProductDetails extends Component {
constructor(props){
super(props);
this.state={
product:{}
}
this.deleteProduct=this.deleteProduct.bind(this);
}
deleteProduct(){
dataService.deleteProduct(this.props.match.params.id).then((response)=>{
if(response.status==200){
window.location.href="/products/";
}else{
alert("Došlo je do greške")
}
})
}
componentDidMount() {
this.setState({isLoading: true});
dataService.getOneProduct(this.props.match.params.id)
.then(data =>{
</div>
</div>
)
}
}
import React, { Component } from 'react';
import CategoryItem from './CategoryItem'
import { Link } from 'react-router-dom'
import dataService from '../dataService';
constructor(props) {
super(props);
this.state = {
categories: [],
isLoading: true
};
this.onCategoryDelete=this.onCategoryDelete.bind(this);
}
onCategoryDelete(deletedId){
this.setState({
categories:this.state.categories.filter(x=>x.id!=deletedId)
})
}
componentDidMount() {
this.setState({isLoading: true});
dataService.getCategories()
.then(data =>{
{this.state.categories.map((category)=>{
return (
<div class="list-group">
<CategoryItem category={category}
onCategoryDelete={this.onCategoryDelete} />
</div>
)
})
}
</div>
)
}
}