I'm new to React and been struggling with new challenges. Please write me your opinion and help me to get out of this challenge. I need to take the input value and append it in list area. Basically getting that state.inputValue and append it in ul of listArea.
This is InputTask component.
import React from 'react';
class InputTask extends React.Component {
state = { inputValue: ''}
onInputSubmit = (e) => {
this.setState({inputValue: e.target.value})
}
handleSubmit = (e) => {
e.preventDefault();
console.log('A name was submitted: ' + this.state.inputValue);
}
render() {
return (
<form className="ui input" onSubmit={this.handleSubmit} style={{marginRight:10}}>
<input type="text" value={ this.state.inputValue } onChange={this.onInputSubmit}/>
</form>
)
}
}
export default InputTask;
And this is listArea component.
import React from 'react';
class ListArea extends React.Component{
render() {
const style={
backgroundColor: "#f5d556",
height: "400px",
padding: "40px",
borderRadius: "20px"
};
const listStyle = {
backgroundColor: "green",
color: "white",
listStyle: "none",
textAlign: "left",
padding: "5px",
marginBottom: "10px",
borderRadius: "5px"
}
const iconStyle = {
float: "right"
}
const labelStyle = {
color: "white"
}
return(
<div className="ui form" style={{marginBottom:10}}>
<div className="field">
<div style={style}>
<ul style={{paddingLeft: 0}}>
<li style={listStyle}>
<div className="ui checkbox">
<input type="checkbox" name="example"/>
<label style={labelStyle}> hello there!</label>
</div>
<i className="white trash icon" style={iconStyle}></i>
</li>
</ul>
</div>
</div>
</div>
)
}
}
export default ListArea;
this is App component
import React from 'react';
import ReactDOM from 'react-dom';
import InputTask from "./components/inputTask";
import ListArea from "./components/listArea";
class App extends React.Component {
render() {
return (
<div className="ui container" style={{textAlign:'center'}}>
<h1>Tasks</h1>
<ListArea />
<InputTask />
</div>
);
}
}
ReactDOM.render(<App />,document.getElementById('root'));
In InputTask component at handleSubmit with this.props.InputSelected(this.state.inputValue);
I sent back selected input to it's parent(App.js)
import React from "react";
class InputTask extends React.Component {
state = { inputValue: "" };
onInputSubmit = (e) => {
this.setState({ inputValue: e.target.value });
};
handleSubmit = (e) => {
e.preventDefault();
console.log("A name was submitted: " + this.state.inputValue);
this.props.InputSelected(this.state.inputValue);
this.setState({ inputValue: "" });
};
render() {
return (
<form
className="ui input"
onSubmit={this.handleSubmit}
style={{ marginRight: 10 }}
>
<input
type="text"
value={this.state.inputValue}
onChange={this.onInputSubmit}
/>
</form>
);
}
}
export default InputTask;
In App component I got selected value with handleInputSelected and added it to list to send to ListArea component
import React from "react";
import InputTask from "./components/inputTask";
import ListArea from "./components/listArea";
class App extends React.Component {
state = { list: [] };
handleInputSelected = (input) => {
const { list } = { ...this.state };
list.push(input);
this.setState(list);
};
render() {
return (
<div className="ui container" style={{ textAlign: "center" }}>
<h1>Tasks</h1>
<ListArea list={this.state.list} />
<InputTask InputSelected={(input) => this.handleInputSelected(input)} />
</div>
);
}
}
export default App;
And finally in ListArea component with map on list I just append li element to ul.
import React from "react";
class ListArea extends React.Component {
render() {
console.log("data: ", this.props.data);
const style = {
backgroundColor: "#f5d556",
height: "400px",
padding: "40px",
borderRadius: "20px",
overflow: "scroll"
};
const listStyle = {
backgroundColor: "green",
color: "white",
listStyle: "none",
textAlign: "left",
padding: "5px",
marginBottom: "10px",
borderRadius: "5px"
};
const iconStyle = {
float: "right"
};
const labelStyle = {
color: "white"
};
console.log(this.props.data);
return (
<div className="ui form" style={{ marginBottom: 10 }}>
<div className="field">
<div style={style}>
<ul style={{ paddingLeft: 0 }}>
<li style={listStyle}>
<div className="ui checkbox">
<input type="checkbox" name="example" />
<label style={labelStyle}> hello there!</label>
</div>
<i className="white trash icon" style={iconStyle}></i>
</li>
{this.props.list.map((m) => (
<li style={listStyle}>
<div className="ui checkbox">
<input type="checkbox" name="example" />
<label style={labelStyle}> {m}</label>
</div>
<i className="white trash icon" style={iconStyle}></i>
</li>
))}
</ul>
</div>
</div>
</div>
);
}
}
export default ListArea;
Related
I am visualising a List of Cards with content and what I want to achieve is to set contentEditable=true to the clicked card via its button. I am able to select the content of the element, however contentEditable is not set to true and it returns the following error instead:
Uncaught TypeError: Cannot create property 'contentEditable' on string
And I cant figure out why. What am I doing wrong here and how can I set contentEditable to true for the clicked element via its button?
Here is my code:
import * as React from 'react';
import { ListView } from '#progress/kendo-react-listview';
import { Input } from '#progress/kendo-react-inputs';
import {
Card,
CardTitle,
CardImage,
CardActions,
CardBody,
} from '#progress/kendo-react-layout';
import { Pager } from '#progress/kendo-react-data-tools';
import articles from '../data/articles.json';
import { BubbleChart } from "../components/products/BubbleChart"
const onEdit = (item) => {
console.log(item.Content)
let cardContent = item.Content.contentEditable = "true";
return cardContent
}
const MyItemRender = (props) => {
let item = props.dataItem;
return (
<div
style={{
padding: '20px 20px',
}}
className="parent-container"
>
<div className="k-card-list">
<Card
style={{
width: 260,
height: 340
}}
>
<CardBody
style={{
borderBottom: 'solid 1px rgba(0,0,0,.08)'
}}
>
<CardImage
src={require(`../assets/article-images/${item.Image}`)}
style={{
width: 260,
height: 140,
maxWidth: 260,
}}
/>
<CardTitle
style={{
fontSize: 18,
}}
/>
<CardTitle>{item.Title}</CardTitle>
<CardTitle>{item.Subtitle}</CardTitle>
<p className="content">
Some quick example text to build on the card title and make up the
bulk of the card content.
</p>
</CardBody>
<CardActions>
<div className="footer-buttons-container">
<span>
<span className="k-button k-button-md k-button-rectangle k-rounded-md k-button-flat k-button-flat-base">
<span className="k-icon k-i-preview"></span>Review
</span>
</span>
<span>
<span className="k-button k-edit-button k-button-md k-button-rectangle k-rounded-md k-button-flat k-button-flat-primary" onClick={() => onEdit(item)}>
<span className="k-icon k-i-edit"></span>Edit
</span>
</span>
</div>
</CardActions>
</Card>
</div>
</div>
);
};
export const Products = () => {
const [filteredList, setFilteredList] = React.useState(articles);
const [value, setValue] = React.useState('');
const [page, setPage] = React.useState({
skip: 0,
take: 10,
});
const handlePageChange = (e) => {
setPage({
skip: e.skip,
take: e.take,
});
};
const handleChange = React.useCallback((event) => {
setValue(event.target.value);
const results = articles.filter(post => {
if (event.target.value === "") return articles
return post.Title.includes(event.target.value)
})
console.log(results)
setFilteredList(results)
});
const { skip, take } = page;
return <div>
<div className="chart-container">
<br/>
<br/>
<BubbleChart/>
</div>
<div className="input-container">
<Input
style={{
border: '2px solid #ccc',
boxShadow: 'inset 0px 0px 0.5px 0px rgba(0,0,0,0.0.1)',
}}
placeholder={'Search'}
value={value}
onChange={handleChange}
/>
</div>
<div className="listbox-card-container">
<ListView
data={filteredList.slice(skip, skip + take)}
item={MyItemRender}
style={{
width: '100%',
height: '100%',
}}
/>
<Pager
skip={skip}
take={take}
onPageChange={handlePageChange}
total={articles.length}
/>
</div>
</div>
}
Can't do multiple assigning in one line. add separate lines
const onEdit = (item) => {
console.log(item.Content)
const content = {...item.Content }
content.contentEditable = "true";
return content
}
I am new to React. I am trying to pass the value of a select box imported from a separate .jsx file to an event for full-calendar. I can't find anything on this or figure out how to do it for the life of me. This is my component for the select box in a separate file.
import React from 'react'
export const Dropdown = (props) => (
<div className="form-group">
<select
className="form-control"
name="partner"
onChange={props.onChange}
>
<option defaultValue>Select Partner</option>
{props.options.map((item, index) => (
<option key={index} value={item.value}>
{item.label}
</option>
))}
</select>
</div>
)
export default class DropdownList extends React.Component {
constructor() {
super()
this.state = {
list: [],
chosenValue: '',
}
}
componentDidMount() {
fetch('/calendar/users')
.then((response) => response.json())
.then((item) => this.setState({ list: item }))
}
onDropdownChange = (e) => {
this.setState({ chosenValue: e.target.value })
}
render() {
return (
<div className="form-group">
<Dropdown
name="partner"
id="partner"
options={this.state.list}
onDropdownChange={this.onDropdownChange}
/>
</div>
)
}
}
This is my modal that contains the form to pass through as an event to full-calendar
import React, {useState} from "react";
import Modal from "react-modal";
import DateTimePicker from "react-datetime-picker";
import 'bootstrap-icons/font/bootstrap-icons.css'
import DropdownList from "./SelectBox";
export default function ({ isOpen, onClose, onEventAdded }) {
const [title, setTitle] = useState("");
const [start, setStart] = useState(new Date());
const [end, setEnd] = useState(new Date());
const [selectValue] = useState(DropdownList);
const onSubmit = (event) => {
event.preventDefault();
onEventAdded({
title,
start,
partner: selectValue,
end
});
onClose()
};
return (
<Modal isOpen={isOpen}
onClose={onClose}
style={{
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.5)'
},
content: {
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)',
border: '1px solid #ccc',
background: '#fff',
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
borderRadius: '4px',
outline: 'none',
padding: '20px',
maxWidth: '1200px',
minHeight: '80%',
textAlign: 'center'
}
}}
>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch#4.5.2/dist/lux/bootstrap.min.css" />
<form onSubmit={onSubmit}>
<div className='form-group'>
<input className='form-control' placeholder="Title" value={title} onChange={e => setTitle(e.target.value)} />
</div>
<DropdownList />
<div className='form-group'>
<DateTimePicker name='start' value={start} onChange={date => setStart(date)} />
</div>
<div className='form-group'>
<DateTimePicker name='end' value={end} onChange={date =>setEnd(date)} />
</div>
<button className="btn btn-primary btn-block" type="submit">Add Event</button>
<button className="btn btn-danger btn-block" onClick={onClose}>Cancel</button>
</form>
</Modal>
)
}
I have tried DropdownList.value, redoing the onDropdownChange(e) function in the modal jsx file to no avail. I'm sure this is really simple and I'm getting a headache so thank you for your kindness ahead of time. I'm currently trying to use props but it's all coming up undefined.
Edit: tried to add to component in the modal file
const [partner, setPartner] = useState();
<DropdownList
ref={partnerRef}
onDropdownChange={e => setPartner(this.chosenValue = e.target.value)}
/>
const boxes = {
height: 220,
width: 220,
backgroundColor: 'red',
borderRadius: '25%',
};
const main = {
display: 'grid',
gridTemplateColumns: 'auto auto auto',
gridGap: '20px',
justifyContent: 'center',
marginTop: '20px',
};
const box = document.querySelectorAll('.boxes');
console.log(box.length);
class Easy extends React.Component {
render() {
return (
<div className="easy-game">
<div className="Easy-main" style={main}>
<div style={boxes} className="boxes" />
<div style={boxes} className="boxes" />
<div style={boxes} className="boxes" />
</div>
</div>
);
}
}
export default Easy;
This is my Code and my .length method gives 0 in return while there are 3 divs using the same class I am starting in react so I can be wrong somewhere
Your code runs before render, so there will be no element rendered
Move it inside a componentDidMount which run after the initial render:
class Easy extends React.Component {
componentDidMount() {
const box = document.querySelectorAll('.boxes'); //<-- Move it here
console.log(box.length);
}
render() {
return (
<div className="easy-game">
<div className="Easy-main" style={main}>
<div style={boxes} className="boxes" />
<div style={boxes} className="boxes" />
<div style={boxes} className="boxes" />
</div>
</div>
);
}
}
My semantic-ui-react Menu component is acting strange when I add my google maps component to be rendered. Before I added my MapContainer, the FilterSection was working pretty fine. But after I render the MapContainer my sections in my Menu are no longer clickable nor do they react to my mouse hover. What should I do?
Snippet of render:
return (
<div>
<Navbar/>
<FilterSection/>
<ChatWidget/>
<div className="map-and-cards">
<MapContainer/> // This line causes the problem
<div style={containerStyle} className="cards-container">
<div class="card-columns" style={{gridTemplateColumns: '350px 350px', display: 'grid', rowGap: '50px', columnGap: '18px'}}>
<Cards listingData={listingData}/>
</div>
</div>
</div>
</div>
)
and my MapContainer.js:
import React from 'react';
import { Map, GoogleApiWrapper } from 'google-maps-react';
const style = {
position: 'relative',
top: '65px',
width: '47.5%', // 47.5
height: '85%',
};
const defaultCenter = {
lat: 41.04137, lng: 28.979530
}
export class MapContainer extends React.Component<MapProps> {
render() {
return (
<Map
style = {style}
google={this.props.google}
centerAroundCurrentLocation={true}
zoom={12}
initialCenter={defaultCenter}
/>
);
}
}
export default GoogleApiWrapper({
apiKey: (0)
})(MapContainer)
FilterSection.js:
import React, { Component } from "react";
import { Menu, Dropdown, Input, Button } from "semantic-ui-react";
import 'semantic-ui-css/semantic.min.css'
export class Price extends Component {
state = { isOpen: false };
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const { activeItem } = this.state;
return (
<div style={{float: 'left'}}>
<Menu secondary >
<Menu.Item>
<Dropdown
text={"Price"}
className="item"
onClick={this.toggleOpen}
open={this.state.isOpen}
>
<Dropdown.Menu onClick={this.preventClosing}>
<Dropdown.Header icon="money" content={" Price Range"} />
<Dropdown.Divider />
<form
style = {{margin: '10px'}}
name="id"
type="number"
max={900}
action={<Button onClick={this.toggleOpen} content={"Send"} />}
>
<Input style={{zoom: '0.9'}} placeholder="min"/> — <Input style={{zoom: '0.9'}} placeholder="max"/>
</form>
</Dropdown.Menu>
</Dropdown>
</Menu.Item>
</Menu>
</div>
);
}
toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
preventClosing = e => e.stopPropagation();
}
export class BedsAndBaths extends Component {
state = { isOpen: false };
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const { activeItem } = this.state;
return (
<div style={{float: 'left'}}>
<Menu secondary>
<Menu.Item>
<Dropdown
text={"Bedrooms & Livingrooms"}
className="item"
onClick={this.toggleOpen}
open={this.state.isOpen}
>
<Dropdown.Menu onClick={this.preventClosing}>
<form
style = {{margin: '10px'}}
name="id"
type="number"
max={900}
action={<Button onClick={this.toggleOpen} content={"Send"} />}
>
<Input style={{zoom: '0.9'}} placeholder="3"/> + <Input style={{zoom: '0.9'}} placeholder="1"/>
</form>
</Dropdown.Menu>
</Dropdown>
</Menu.Item>
</Menu>
</div>
);
}
toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
preventClosing = e => e.stopPropagation();
}
export class More extends Component {
state = { isOpen: false };
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const { activeItem } = this.state;
return (
<div style={{float: 'left'}}>
<Menu secondary>
<Menu.Item>
<Dropdown
text={"More"}
className="item"
onClick={this.toggleOpen}
open={this.state.isOpen}
>
<Dropdown.Menu onClick={this.preventClosing}>
<Dropdown.Header icon="money" content={" Price Range"} />
<Dropdown.Divider />
<form
style = {{margin: '10px'}}
name="id"
type="number"
max={900}
action={<Button onClick={this.toggleOpen} content={"Send"} />}
>
<Input style={{zoom: '0.9'}} placeholder="min"/> — <Input style={{zoom: '0.9'}} placeholder="max"/>
</form>
</Dropdown.Menu>
</Dropdown>
</Menu.Item>
</Menu>
</div>
);
}
toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
preventClosing = e => e.stopPropagation();
}
export class Alert extends Component {
state = { isOpen: false };
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const { activeItem } = this.state;
return (
<div style={{float: 'left', position: 'relative', top: '11.5px', left: '15px', zoom: '0.9'}}>
<Menu secondary >
<button class="ui button ">
Create Alert
</button>
</Menu>
</div>
);
}
toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
preventClosing = e => e.stopPropagation();
}
export class Search extends Component {
state = { isOpen: false };
handleItemClick = (e, { name }) => this.setState({ activeItem: name });
render() {
const { activeItem } = this.state;
return (
<div style={{float: 'left', position: 'relative', top: '12px', right: '50px', zoom: '0.9'}}>
<Menu secondary >
<div style={{float: 'left', position: 'relative', right: '10px'}} class="ui input focus">
<input type="text" placeholder="Enter an adress, neigborhood, city, or ZIP code
" size="45"/>
</div>
<button class="ui button ">
Search
</button>
</Menu>
</div>
);
}
toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
preventClosing = e => e.stopPropagation();
}
export default function FilterSection(){
return (
<div style={{position: 'relative', left: '75px', bottom: '1px'}}><Search/><div style={{position: 'relative', right: '30px'}}><More/><BedsAndBaths/><Price/><Alert/></div></div>
)
}
As I said, only the MapContainer component is triggering the deactivation of the menu.
You can see the actual page at royaremlak.com/search
This is the full code of my login page. It is based on react-boilerplate .
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { FormattedMessage } from 'react-intl';
import { createStructuredSelector } from 'reselect';
import { compose } from 'redux';
import { LoginFooter } from 'containers/LoginFooter';
import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
import makeSelectLoginPage, { makeSelectUsername, makeSelectPassword, makeSelectUserInfo, makeSelectSetErrMessage } from './selectors';
import reducer from './reducer';
import saga from './saga';
import messages from './messages';
import { InputText } from 'primereact/components/inputtext/InputText';
import { changePassword, changeUsername, submitForm, getErrMessage } from './actions';
import { Button } from 'primereact/components/button/Button';
import { Growl } from 'primereact/components/growl/Growl';
import { Panel } from 'primereact/components/panel/Panel';
export class LoginPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
componentDidUpdate() {
this.props.changeMessage('');
}
render() {
if (this.props.setErrMessage) {
let msg = { severity: 'error', summary: 'Failure', detail: this.props.setErrMessage };
this.growl.show(msg);
}
return (
<div>
{/* <Helmet>
<meta name="description" content="Description of LoginPage" />
</Helmet> */}
<div className='ui-g ui-fluid login-img'>
<div className='ui-g-8 ui-sm-1 ui-md-3 ui-lg-7'>
</div>
<div className='ui-g-4 ui-sm-10 ui-md-6 ui-lg-4 loginpanelbar' style={{ marginLeft: '20px', marginTop: '28px', marginBottom: '13px' }}>
<Panel className='panellogin' style={{ paddingTop: '50px', paddingBottom: '50px' }}>
<div className='ui-g ui-fluid' >
<div className='ui-g-2 ui-sm-3 ui-md-2 ui-lg-2'>
</div>
<div className='ui-g-8 ui-sm-12 ui-md-8 ui-lg-8'>
<div className='logoimg' style={{ height: '80px' }}>
</div>
</div>
<div className='ui-g-2 ui-sm-3 ui-md-2 ui-lg-2'>
</div>
</div>
<div className='ui-g ui-fluid'>
<div className='ui-g-12 ui-sm-12 ui-md-12 ui-lg-12'>
<label for="name">Username</label>
<span class="md-inputfield" style={{ marginBottom: '20px', marginTop: '10px' }}>
<InputText id="netiinputfield1" style={{ height: '37px' }} type="text" value={this.props.username} onChange={(e) => { this.props.onChangeUsername(e.target.value) }} required class=" ui-state-default ui-corner-all ui-widget" />
</span>
</div>
</div>
<div className='ui-g ui-fluid'>
<div className='ui-g-12 ui-sm-12 ui-md-12 ui-lg-12'>
<label for="name">Password</label>
<span class="md-inputfield" style={{ marginBottom: '20px', marginTop: '10px' }}>
<InputText id="netiinputfield2" style={{ height: '37px' }} type="password" value={this.props.password} onChange={(e) => { this.props.onChangePassword(e.target.value) }} required class="ui-state-default ui-corner-all ui-widget" />
</span>
</div>
</div>
<div className='shortFont'>
<div className='ui-g ui-fluid'>
<div class='ui-g-12 ui-sm-6 ui-md-6 ui-lg-6'>
<div class="form-check" >
<input type="checkbox" className="form-check-input exampleCheck1" className='checkboxsize' />
<label class="form-check-label" for="exampleCheck1">Remember Me</label>
</div>
</div>
<div class='ui-g-12 ui-sm-6 ui-md-6 ui-lg-6' style={{ textAlign: 'right' }}>
<a href='#/'>Forget Password?</a>
</div>
</div>
</div>
<div className='ui-g ui-fluid' style={{ marginBottom: '13px' }}>
<div class="ui-g-12">
<Growl ref={(el) => this.growl = el} />
<Button label='LOGIN' onClick={this.props.submitLoginForm} />
</div>
</div>
</Panel>
</div>
<div className='ui-g-1 ui-sm-1 ui-md-1 ui-lg-1'>
</div>
</div>
<div className="login-img-footer">
<div class="textcss"><p>START WITH DIGITAL</p></div>
</div>
<div className="ui-g ui-fluid bottomPart"></div>
{/* <LoginFooter /> */}
</div>
);
}
}
LoginPage.propTypes = {
dispatch: PropTypes.func.isRequired,
username: PropTypes.any,
onChangeUsername: PropTypes.func,
password: PropTypes.any,
onChangePassword: PropTypes.func,
submitLoginForm: PropTypes.func,
userInfo: PropTypes.any,
changeMessage: PropTypes.any,
setErrMessage: PropTypes.any,
};
const mapStateToProps = createStructuredSelector({
loginpage: makeSelectLoginPage(),
username: makeSelectUsername(),
password: makeSelectPassword(),
userInfo: makeSelectUserInfo(),
setErrMessage: makeSelectSetErrMessage(),
});
function mapDispatchToProps(dispatch) {
return {
dispatch,
onChangeUsername: (value) => {
dispatch(changeUsername(value));
},
onChangePassword: (value) => {
dispatch(changePassword(value));
},
submitLoginForm: (evt) => {
dispatch(submitForm());
},
changeMessage: (evt) => {
dispatch(getErrMessage(evt));
}
};
}
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({ key: 'loginPage', reducer });
const withSaga = injectSaga({ key: 'loginPage', saga });
export default compose(
withReducer,
withSaga,
withConnect,
)(LoginPage);
The submit button works for mouse click, But i also need Enter key( key=13) to submit the form.
I tested some methods , but none of them worked out. How can i do it along with onClick and Enter Key.
You can simply wrap your form fields at tag and listen onSubmit event on it:
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { FormattedMessage } from 'react-intl';
import { createStructuredSelector } from 'reselect';
import { compose } from 'redux';
import { LoginFooter } from 'containers/LoginFooter';
import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
import makeSelectLoginPage, { makeSelectUsername, makeSelectPassword, makeSelectUserInfo, makeSelectSetErrMessage } from './selectors';
import reducer from './reducer';
import saga from './saga';
import messages from './messages';
import { InputText } from 'primereact/components/inputtext/InputText';
import { changePassword, changeUsername, submitForm, getErrMessage } from './actions';
import { Button } from 'primereact/components/button/Button';
import { Growl } from 'primereact/components/growl/Growl';
import { Panel } from 'primereact/components/panel/Panel';
export class LoginPage extends React.Component { // eslint-disable-line react/prefer-stateless-function
componentDidUpdate() {
this.props.changeMessage('');
}
render() {
if (this.props.setErrMessage) {
let msg = { severity: 'error', summary: 'Failure', detail: this.props.setErrMessage };
this.growl.show(msg);
}
return (
<div>
{/* <Helmet>
<meta name="description" content="Description of LoginPage" />
</Helmet> */}
<div className='ui-g ui-fluid login-img'>
<div className='ui-g-8 ui-sm-1 ui-md-3 ui-lg-7'>
</div>
<div className='ui-g-4 ui-sm-10 ui-md-6 ui-lg-4 loginpanelbar' style={{ marginLeft: '20px', marginTop: '28px', marginBottom: '13px' }}>
<Panel className='panellogin' style={{ paddingTop: '50px', paddingBottom: '50px' }}>
<form onSubmit={this.props.submitLoginForm}>
<div className='ui-g ui-fluid' >
<div className='ui-g-2 ui-sm-3 ui-md-2 ui-lg-2'>
</div>
<div className='ui-g-8 ui-sm-12 ui-md-8 ui-lg-8'>
<div className='logoimg' style={{ height: '80px' }}>
</div>
</div>
<div className='ui-g-2 ui-sm-3 ui-md-2 ui-lg-2'>
</div>
</div>
<div className='ui-g ui-fluid'>
<div className='ui-g-12 ui-sm-12 ui-md-12 ui-lg-12'>
<label for="name">Username</label>
<span class="md-inputfield" style={{ marginBottom: '20px', marginTop: '10px' }}>
<InputText id="netiinputfield1" style={{ height: '37px' }} type="text" value={this.props.username} onChange={(e) => { this.props.onChangeUsername(e.target.value) }} required class=" ui-state-default ui-corner-all ui-widget" />
</span>
</div>
</div>
<div className='ui-g ui-fluid'>
<div className='ui-g-12 ui-sm-12 ui-md-12 ui-lg-12'>
<label for="name">Password</label>
<span class="md-inputfield" style={{ marginBottom: '20px', marginTop: '10px' }}>
<InputText id="netiinputfield2" style={{ height: '37px' }} type="password" value={this.props.password} onChange={(e) => { this.props.onChangePassword(e.target.value) }} required class="ui-state-default ui-corner-all ui-widget" />
</span>
</div>
</div>
<div className='shortFont'>
<div className='ui-g ui-fluid'>
<div class='ui-g-12 ui-sm-6 ui-md-6 ui-lg-6'>
<div class="form-check" >
<input type="checkbox" className="form-check-input exampleCheck1" className='checkboxsize' />
<label class="form-check-label" for="exampleCheck1">Remember Me</label>
</div>
</div>
<div class='ui-g-12 ui-sm-6 ui-md-6 ui-lg-6' style={{ textAlign: 'right' }}>
<a href='#/'>Forget Password?</a>
</div>
</div>
</div>
<div className='ui-g ui-fluid' style={{ marginBottom: '13px' }}>
<div class="ui-g-12">
<Growl ref={(el) => this.growl = el} />
<Button label='LOGIN' onClick={this.props.submitLoginForm} />
</div>
</div>
</form>
</Panel>
</div>
<div className='ui-g-1 ui-sm-1 ui-md-1 ui-lg-1'>
</div>
</div>
<div className="login-img-footer">
<div class="textcss"><p>START WITH DIGITAL</p></div>
</div>
<div className="ui-g ui-fluid bottomPart"></div>
{/* <LoginFooter /> */}
</div>
);
}
}
LoginPage.propTypes = {
dispatch: PropTypes.func.isRequired,
username: PropTypes.any,
onChangeUsername: PropTypes.func,
password: PropTypes.any,
onChangePassword: PropTypes.func,
submitLoginForm: PropTypes.func,
userInfo: PropTypes.any,
changeMessage: PropTypes.any,
setErrMessage: PropTypes.any,
};
const mapStateToProps = createStructuredSelector({
loginpage: makeSelectLoginPage(),
username: makeSelectUsername(),
password: makeSelectPassword(),
userInfo: makeSelectUserInfo(),
setErrMessage: makeSelectSetErrMessage(),
});
function mapDispatchToProps(dispatch) {
return {
dispatch,
onChangeUsername: (value) => {
dispatch(changeUsername(value));
},
onChangePassword: (value) => {
dispatch(changePassword(value));
},
submitLoginForm: (evt) => {
dispatch(submitForm());
},
changeMessage: (evt) => {
dispatch(getErrMessage(evt));
}
};
}
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({ key: 'loginPage', reducer });
const withSaga = injectSaga({ key: 'loginPage', saga });
export default compose(
withReducer,
withSaga,
withConnect,
)(LoginPage);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>