React js Navigation through table rows - reactjs

import React, { Component } from 'react';
import { Link } from 'react-router'
import { Dropdown, DropdownMenu, DropdownItem, Progress } from 'reactstrap';
class Notifications extends Component {
constructor(){
super();
this.state = {
data:[
{title:"Nikko Laus1" , text:"abcd" , type:"Big text" },
{title:"Sam Collins", text:"" ,type:"Inbox style"},
{title:"Sam ", text:"" ,type:"Image style"}
]
};
}
render() {
let rows = this.state.data.map(person =>
{
return <TableRow key={person.id} data={person}/>
});
return (<div><div>
<div className="animated fadeIn">
<div className="px-2 mb-1">
<Link to={'/Components/BasicNotification'} style= {{ width:20 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Add Notification</Link>
</div>
<br /><div className="card" style={{ width: 57 + '%' }}>
<div className="card-header">
Manage Notifications
</div>
<div className="card-block">
<table className="table table-hover table-outline mb-0 hidden-sm-down">
<tbody>
{this.props.type.Bigtext ? <Link to={'/Components/BigText'} className="nav-link" activeClassName="active" />:
this.props.type.ImageStyle ? <Link to={'/Components/ImageStyle'} className="nav-link" activeClassName="active" />:
<Link to={'/Components/InboxStyle'} className="nav-link" activeClassName="active" />}
{rows}</tbody>
</table></div>
<br />
</div>
</div><div className="px-2 mb-1"><Link to={'/components/tabs'} style={{ width:20 + '%' }} className="px-1 nav-link btn btn-block btn-success" activeClassName="active">Filter Notifications</Link>
</div>
</div></div>
)
}
}
class TableRow extends React.Component
{
constructor()
{
super();
}
render()
{
return (<tr>
<td className="text-center">{this.props.data.title}<br />
{this.props.data.text}<br /></td></tr>
);
}
}
export default Notifications;
I want to give condition and if else condition and using that condition I want to open an particular page as seen in the code snippet.
But when I run no output comes at all.
I just wanted to do like on the basis of notification type relevant page is to be opened on clicking that table row

You can make use of this.context.router.push to dynamically change the route onClick of the table row. See the below snippet.
import React, { Component } from 'react';
import { Link } from 'react-router'
import { Dropdown, DropdownMenu, DropdownItem, Progress } from 'reactstrap';
class Notifications extends Component {
constructor(){
super();
this.state = {
data:[
{title:"Nikko Laus1" , text:"abcd" , type:"Big text" },
{title:"Sam Collins", text:"" ,type:"Inbox style"},
{title:"Sam ", text:"" ,type:"Image style"}
]
};
}
static contextTypes = {
router: React.PropTypes.object
}
handleClick = (index) => {
if(this.state.data[index].type === "Big text") {
this.context.router.push('/Components/BigText');
} else if(this.state.data[index].type === "Image style") {
this.context.router.push('/Components/ImageStyle');
} else {
this.context.router.push('/Components/InboxStyle');
}
}
render() {
let rows = this.state.data.map((person, index) =>
{
return <TableRow key={person.id} data={person} onClick={this.handleClick.bind(this, index)}/>
});
return (<div><div>
<div className="animated fadeIn">
<div className="px-2 mb-1">
<Link to={'/Components/BasicNotification'} style= {{ width:20 + '%' }} className="nav-link btn btn-block btn-success" activeClassName="active">Add Notification</Link>
</div>
<br /><div className="card" style={{ width: 57 + '%' }}>
<div className="card-header">
Manage Notifications
</div>
<div className="card-block">
<table className="table table-hover table-outline mb-0 hidden-sm-down">
<tbody>
{rows}</tbody>
</table></div>
<br />
</div>
</div><div className="px-2 mb-1"><Link to={'/components/tabs'} style={{ width:20 + '%' }} className="px-1 nav-link btn btn-block btn-success" activeClassName="active">Filter Notifications</Link>
</div>
</div></div>
)
}
}
class TableRow extends React.Component
{
constructor(props)
{
super(props);
}
render()
{
return (<tr onClick={this.props.onClick}>
<td className="text-center">{this.props.data.title}<br />
{this.props.data.text}<br /></td></tr>
);
}
}
export default Notifications;

Related

I keep getting `handleColor` is not a function error

I have some problem with a function I set up to change the background color of a button when it is clicked.
I setup the function in a parent component below:
import React, { useRef, useState } from 'react';
import Aside from './Aside';
import Content from './Content';
const Dashboard = () => {
let asideRef = useRef(null);
const handleColor = color => {
asideRef.current.style.backgroundColor = color;
};
return (
<div className="d-flex flex-row" id="main_wrapper">
<Aside handleColor={handleColor} postedRef={asideRef} />
<Content />
</div>
);
};
export default Dashboard;
in the child component it is called in this manner:
import { Link } from 'react-router-dom';
import React, { createRef } from 'react';
class Aside extends React.Component {
constructor(props) {
super(props);
this.state = {
btn: true,
btnEn: true,
background: '#fff',
};
this.handleClick = this.handleClick.bind(this);
}
handleClick = () => {
const { btn } = this.state;
this.setState({
btn: !btn,
});
};
render() {
const { btn, btnEn, background } = this.state;
const { handleColor, postedRef } = this.props;
console.log(this.props);
return (
<div className="d-flex flex-column asidebar" id="aside_wrapper" style={{ width: '20%', height: '100vh' }}>
<div className="d-flex flex-row justify-content-center nav-header">
<a href="/dashboard" className="brand-logo">
<picture>
<img src="https://user-images.githubusercontent.com/25479050/99581983-c1c18e00-29e1-11eb-9bd3-4a53585456cb.png" className="img-fluid img-thumbnail" alt="plaschema logo" />
<source media="(min-width:650px)" srcSet="https://user-images.githubusercontent.com/25479050/99581983-c1c18e00-29e1-11eb-9bd3-4a53585456cb.png" type="image/svg+xml" />
<source media="(min-width:465px)" srcSet="https://user-images.githubusercontent.com/25479050/99582047-d736b800-29e1-11eb-92f3-83dce3912e39.png" type="image/svg+xml" />
</picture>
</a>
</div>
<div className="link_container d-flex flex-column">
<button type="button" className="buttonTrue" ref={postedRef} onClick={() => { handleColor('#f4f2f6'); }}>
<Link to="/">
<i className="lni lni-dashboard" />
<span className="link_name">Dashboard</span>
</Link>
</button>
<button type="button" className={btnEn ? 'buttonTrue' : 'buttonFalse'}>
<Link to="/enroll">
<i className="lni lni-tab" />
<span className="link_name">Enrollment</span>
</Link>
</button>
<Link className=" icons accreditation-wrapper" to="/accreditation">
<i className="lni lni-checkbox" />
<span className="link_name">Accreditation</span>
</Link>
<Link className=" icons subscription-wrapper" to="/subscription">
<i className="lni lni-tab" />
<span className="link_name">Subscription</span>
</Link>
<Link className=" icons service-wrapper" to="/service">
<i className="lni lni-control-panel" />
<span className="link_name">Service Usage</span>
</Link>
<Link className=" icons report-wrapper" to="/report">
<i className="lni lni-library" />
<span className="link_name">Reports</span>
</Link>
</div>
</div>
);
}
}
export default Aside;
After setup, anytime I click on the only button I set it up on as a test, I keep getting this error page handleColor is not a function. Right now I can't think of what the issue maybe because I have tried several approaches to get it to work but the error is still there. Below is the code of the component I am trying to apply it on:
Looking forward to helpful responses. Thanks.
The question has been updated for more insight. Sorry for the earlier issues with the first iteration.
you can try with
const handleClick = () => {
or
function handleClick () {
You're wrongly referring the handleColor. handleColor is not a prop, it is a component method, you can use like this.handleColor
const { handleColor } = this.props // this is wrong, it's not a prop method
<button type="button" className="buttonTrue" ref={this.colorSwitch} onClick={() => { this.handleColor('#f4f2f6'); // this is right }}>
<Link to="/">
<i className="lni lni-dashboard" />
<span className="link_name">Dashboard</span>
</Link>
</button>
I have created sample example here with some of your code. Check out this link

React Rotate Accordion Arrow Onclick

How can I rotate the arrows onclick
This is my code below for my react collapse and I would like to rotate the arrows of my collapse accordion when it clicked.
I'm using reactstrap to build it and react fontawsome for my Icons
I've also attached a .GIF Link to demonstrate how my accordion is currently functioning.
import React, { Component } from "react";
import { Collapse, CardBody, Card, CardHeader } from "reactstrap";
import { faChevronDown } from "#fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
const nested = [
{
id: 10,
title:"Customer Queries"
},
];
const Icon = <FontAwesomeIcon icon={faChevronDown} color={"#EB8C00" } />;
class Colapse extends Component {
constructor(props) {
super(props);
this.tog = this.tog.bind(this);
this.state = {
col: 0,
cards: [
{
id:1,
title:"General information requests",
sub_title:"Fault reports",
body:"Something to display for body 1",
},
{
id:2,
title:"Account queries",
sub_title:"Communication protocols",
body:"Something to display for body 2",
}
] };
}
tog(e) {
let event = e.target.dataset.event;
this.setState({
col: this.state.col === Number(event) ? 0 : Number(event),
});
}
render() {
const { col, cards } = this.state;
return (
<div className="container collapse-container">
{nested.map((element, index) => {
return (
<Card key={index} className="card rounded ">
<CardHeader
className="card-header"
onClick={this.tog}
data-event={(index = element.id)}
>
<p className="collapse d-flex">
<div className=" p-2 mr-auto font-weight-bold">
<p className="">{element.title}</p>
</div>
<a
class="click-layer"
onClick={this.tog}
data-event={index}
></a>
</p>
</CardHeader>
<Collapse isOpen={col !== index}>
<CardBody className="card-body">
<p className="card-text">Customer Queries relate to information, account or meter related faults reported by the customer.</p>
{/**HERE NESTED */}
{cards.map((index) => {
return (
<Card key={index} className="card-sub rounded ">
<p className="card-header-sub" >{index.title}</p>
<CardHeader
className="card-header-sub"
onClick={this.tog}
data-event={index.id}
>
<p className="colle d-flex">
<div className="p-2 rotate">{Icon}</div>
<div className=" p-2 mr-auto font-weight-bold">
<p className="card-header-sub">{index.sub_title}</p>
</div>
<a
class="click-layer"
onClick={this.tog}
data-event={index.id}
></a>
</p>
</CardHeader>
<Collapse isOpen={col === index.id}>
<CardBody className="card-body-sub">
<p className="card-text-body">{index.body}</p>
</CardBody>
</Collapse>
</Card>
);
})}
{/**End Of Nested */}
</CardBody>
</Collapse>
</Card>
);
})}
</div>
);
}
}
export default Colapse;
Rotate the svg according to some condition e.g. col === element.id
<div className={`p-2 rotate ${col === element.id ? "isRotated" : ""}`}>{Icon}</div>
on your stylesheet:
.isRotated svg {
transform: rotate(-90deg);
}

Moving an item from Todolist to delete list and delete it from TodoList

Hello i want to move an item from todo list to delete list in ReactJS and i want to delete it from todo list when i move it to done list i did everything i can delete the selected item or all items but i cant add it to done list when i move it
import React from 'react';
import './App.css';
import Todoinput from './Components/Todoinput'
import Todolist from './Components/Todolist'
import Tododone from './Tododone'
import { render } from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import uuid from 'uuid';
class App extends React.Component {
state= {
items:[],
id:uuid(),
item:'',
editItem:false
}
handleChange = (e) => {
this.setState ({
item:e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault ();
const newItem = {
id:this.state.id,
title:this.state.item,
};
const updatedItems = [...this.state.items,newItem]
this.setState ({
items:updatedItems,
item:'',
id:uuid(),
editItem:false
})
}
clearList = (e) => {
this.setState ({
items:[]
})
}
doneItem = (id) => {
const doneItems = this.state.items.filter (item => item.id !== id);
this.setState ({
items:doneItems,
})
}
handleEdit = (id) => {
const doneItems = this.state.items.filter (item => item.id !== id);
const selectedItem = this.state.items.find(item=> item.id === id)
console.log(selectedItem)
this.setState ({
items:doneItems,
item:selectedItem.title,
editItem:true,
id:id
})
}
render() {
return (
<div className="container">
<div className="row">
<div className="col-10 mx-auto col-md-8 mt-4">
<h3 className="text-capitalize text-center">Todo Inputs</h3>
<Todoinput item={this.state.item} handleChange={this.handleChange}
handleSubmit={this.handleSubmit}
editItem={this.state.editItem}
/>
<Todolist items={this.state.items} clearList={this.clearList} doneItem={this.doneItem} handleEdit={this.handleEdit}/>
<Tododone doneItem={this.doneItem} />
</div>
</div>
</div>
);
}
}
export default App;
/**/
import React from 'react'
import Todoitem from './Todoitem'
class Todolist extends React.Component {
render() {
const {items,clearList,doneItem,handleEdit}=this.props
return (
<ul className="list-group my-5">
<h3 className="text-capitalize text-center">todo list</h3>
{
items.map(item => {
return (
<Todoitem
key={item}
title={item.title}
doneItem={()=> doneItem(item.id)}
handleEdit={()=> handleEdit(item.id)}
/>
)
})
}
<button type="button" className="btn btn-danger btn-block text-capitalize mt-5"
onClick={clearList}
>clear list</button>
</ul>
)
}
}
export default Todolist
/**/
import React from 'react'
class Todoinput extends React.Component {
render() {
const {item,handleChange,handleSubmit,editItem} = this.props
return (
<div className="card card-body my-3">
<form onSubmit={handleSubmit}>
<div className="input-group">
<div className="input-group-prepend">
<div className="input-group-text bg-primary text-white">
<i className="fa fa-book" ></i>
</div>
</div>
<input type="text" className="form-control text-capitalize" placeholder="Add A To Do Item"
value={item}
onChange={handleChange}
/>
</div>
<button type="submit"
className={editItem ? "btn btn-block btn-success mt-3" : "btn btn-block btn-primary mt-3" }>
{editItem ? 'Edit Item' : "Add Item"}</button>
</form>
</div>
)
}
}
export default Todoinput
/**/
import React from 'react'
class Todoitem extends React.Component {
render() {
const {title,doneItem,handleEdit} = this.props
return (
<li className="list-group-item text-capitalize d-flex justify-content-between my-2">
<h6>{title}</h6>
<div className="todo-icon">
<span className="mx-2 text-success" onClick={handleEdit}>
<i className="fa fa-edit"></i>
</span>
<span className="mx-2 text-danger"onClick={doneItem}>
<i className="fa fa-window-close"></i>
</span>
</div>
</li>
)
}
}
export default Todoitem
/**/
import React from 'react'
class Tododone extends React.Component {
render() {
const {items,clearList,doneItem,title,item}=this.props
return (
<div>
<h2 className="text-capitalize text-center">Done Items</h2>
<li className="list-group-item text-capitalize d-flex justify-content-between my-2">
<h6>{item}</h6>
<div className="todo-icon">
<span className="mx-2 text-danger" onClick={doneItem}>
<i className="fa fa-trash"></i>
</span>
</div>
</li>
<button type="button" className="btn btn-danger btn-block text-capitalize mt-5"
onClick={clearList}>clear list</button>
</div>
)
}
}
export default Tododone
so if anyone can help Please i post all the code above if anyone can help me please <
To track if a task is done, add a isDone field to item, when you say it's done, flag it to true.
So when you create a new item:
const newItem = {
id:this.state.id,
title:this.state.item,
isDone: false
};
When you render items that are not done, filter through isDone===false, like this:
<Todolist items={this.state.items.filter(item => item.isDone === false)} ... />
When you delete an item from the ToDoList you want it to go to the DoneList, so you set your doneItem function like this:
doneItem = id => {
const newItems = [...this.state.items];
const item = newItems.find(item => item.id === id);
item.isDone = true;
this.setState({
items: newItems
});
}
When you render the done list, filter through isDone === true, like this:
<Tododone items={this.state.items.filter(item => item.isDone === true)} ... />
Now get the items prop in Tododone and map it to see the done items, this below is just an example:
{items.map(item => (
<li className="list-group-item text-capitalize d-flex justify-content-between my-2">
<h6>{item.title}</h6>
<div className="todo-icon">
<span className="mx-2 text-danger" onClick={doneItem}>
<i className="fa fa-trash"></i>
</span>
</div>
</li>
))}
Since I don't know what you want to do with those divs and spans I'll leave them like you set them.
When you click on clear list I assume you want to delete only the todoList or only the doneList, I suggest you to pass a flag to tell App which list to clear.
Here's the sandbox with your code that solves your problem.
down and dirty because I have to head to work would be to add something like doneItemsArray: [] in your state and then just do another filter in your doneItem method.
doneItem = id => {
const filteredTodos = this.state.items.filter(item => item.id !== id);
const doneItem = this.state.items.filter(item => item.id === id);
this.setState({
items: doneItems,
doneItemsArray: [...this.state.doneItemsArray, doneItem]
});
};

Reactjs map function does not render the component

This is the error I am trying to render the createCardHotels function;however, whenever I run it, nothing shows up. Any help will be appreciated.
I used map function to loop through the data and whenever I run it I can see on the console that there is the data. The problem is just the rendering part.
import React, {Component} from 'react';
import {Container, Button, DropdownMenu, DropdownItem, Dropdown, DropdownToggle} from 'reactstrap';
import {Carousel} from 'react-responsive-carousel';
import styles from 'react-responsive-carousel/lib/styles/carousel.min.css';
import './selectHotel.css'
import Scroll from '../ScrollUp';
import {search} from '../../actions/search';
import {connect} from 'react-redux';
class SelectHotel extends Component{
constructor(props){
super(props);
this.state={
dropdownOpen: false,
hotels: []
};
this.toggleDropdown = this.toggleDropdown.bind(this);
}
static getDerivedStateFromProps(state, props){
if(props.hotels !== state.hotels)
return{
...state,
hotels: props.hotels
}
return null;
}
createCardHotels = () => {
return this.state.hotels.map((hotel) => {
return(
<div key={hotel._id} className="card">
<div className="row ">
<div className="col-md-4">
<Carousel autoPlay infiniteLoop>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
<div>
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
</div>
</Carousel>
</div>
<div className="col-md-5 px-3">
<div className="card-block px-3">
<h3 className="card-title">{hotel.name}</h3>
<p className="card-text">description</p>
</div>
</div>
<div className="col-md-3 price">
<h1 className="reservation-price">$Price</h1>
<Button style={cssStyles.buttonRoom} bsStyle="primary">Choose Hotel</Button>
</div>
</div>
</div>
)}
)
}
toggleDropdown() {
this.setState(prevState => ({
dropdownOpen: !prevState.dropdownOpen
}));
}
render(){
console.log(this.state)
console.log(this.props)
return(
<div>
<Container>
<Scroll/>
<div>
<Dropdown className = 'sortbutton' size="lg" isOpen={this.state.dropdownOpen} toggle={this.toggleDropdown}>
<DropdownToggle style={{backgroundColor: "white", borderColor: "grey" , color: "black"}} caret>
Sort By:
</DropdownToggle>
<DropdownMenu>
<DropdownItem onClick={()=>{this.setSort("low");}}>
Price: Low to High
</DropdownItem>
<DropdownItem divider />
<DropdownItem onClick={()=>{this.setSort("high");}}>
Price: High to Low
</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>
{this.createCardHotels()}
<br></br>
</Container>
</div>
);
}
}
const cssStyles = {
buttonRoom:{
backgroundColor: '#156bc1',
border: '1px solid #156bc1',
alignItems: 'left',
boxShadow: 'inset 0 -2px 0 #063665',
paddingLeft: '2rem',
paddingRight: '2rem',
fontSize: '0.8rem'
}
}
const mapStatetoProps = state => {
return {
hotels: state.search.hotels
};
}
export default connect(mapStatetoProps, {search})(SelectHotel);
EDIT:
This is the image from console after I put console.log(this.state), console.log(this.props), it seems like there is data in this.props and not in this.state
The issue is with add class names to JSX elements. You are using class to apply css styles with class names but class is reserved for creating class components in React so you need to use className
Wherever you see class on jsx elements change it to className
Also never forget to add key to the top parent jsx element when you render them in loop. If you have unique from data then set id from data as a key like I did below else use index as key
Change
return this.state.hotels.map((hotel) => {
return(
<div class="card">
........
To
return this.state.hotels.map((hotel) => {
return(
<div key={hotel.id} className="card">
.......
Also
Change
<h1 className="reservation-price">$Price</h1>
To
<h1 className="reservation-price">{"$Price"}</h1>
For images you need to use require or import
Change
<img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400" className="w-100"/>
To
<img src={require("https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400")} className="w-100"/>
Do the same for other images as well
Or import it like
import text from "https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97400&w=400&h=400";
<img src={text} className="w-100"/>
Сould you please show your building file. May be a problem with file-loader.

Who can I call the function only if

Hey guys I need your help. I want to call a function but only if other function works. But I can't do that unfortunately, could you help me?
Here's my code:
'use strict';
import React from 'react/addons';
import { Carousel, CarouselItem } from 'react-bootstrap';
import { Link } from 'react-router';
import cx from 'classnames';
import { user as userAccount } from '../../scripts/account-details';
function getColorForChannel(name) {
const hue = Array.from(name)
.map((ch, i) => ch.charCodeAt(0) * (i + 1))
.reduce((sum, ch) => sum + ch, 0) % 360;
return `hsl(${hue}, 75%, 75%)`;
}
function urlify(text){
var urlRegex = /(https?:\/\/[^\s]+)?\.(com|pt|es|org|net|)?/g;
return urlRegex.test(text);
}
function parseLinha(linha) {
return linha.split(' ')
.map((x, i) => urlify(x) ? <a key={i} href={x.trim()} target='_blank' rel='nofollow'>{x} </a> : x + " ");
}
/**
* Usernames that don't really link to people.
*/
const nonPeopleUserNames = ['linsasupport'];
const TimelineItem = React.createClass({
getDefaultProps() {
return {
important: false
};
},
propTypes: {
routeDepth: React.PropTypes.number,
router: React.PropTypes.func,
item: React.PropTypes.object.isRequired,
onDelete: React.PropTypes.func,
onLinkClicked: React.PropTypes.func.isRequired,
important: React.PropTypes.bool
},
getChildContext() {
return {
routeDepth: this.props.routeDepth,
router: this.props.router
};
},
childContextTypes: {
routeDepth: React.PropTypes.number.isRequired,
router: React.PropTypes.func.isRequired
},
getUrlState() {
return (
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="..." alt="..."/>
<div class="caption">
<h3>Thumbnail label</h3>
<p>...</p>
<p>Button Button</p>
</div>
</div>
</div>
</div>
);
},
renderAttachments(attachments) {
if (!attachments.length) { return null; }
if (attachments.every((a) => a.Type.toLowerCase() === 'image')) {
return (
<Carousel>
{attachments.map((a) =>
<CarouselItem key={a.Id}>
<a href={`timeline/${this.props.item.Id}/attachments/${a.Id}`} target='_blank'>
<div style={{
backgroundImage: `url(/timeline/${this.props.item.Id}/attachments/${a.Id})`,
backgroundSize: 'contain',
backgroundPosition: 'center center',
height: 300, width: '100%', backgroundRepeat: 'no-repeat' }} />
</a>
</CarouselItem>)}
</Carousel>
);
}
return (
<div className='si-timeline-item-attachments'>
<ul className='fa-ul'>
{attachments.map((a) =>
<li key={a.Id}>
<i className='fa-li fa fa-file' />
<a href={`/timeline/${this.props.item.Id}/attachments/${a.Id}`}
target='_blank'>
{a.Name}
</a>
</li>)}
</ul>
</div>
);
},
handleDelete() {
if (typeof (this.props.onDelete) === 'function') {
this.props.onDelete();
}
},
render() {
const { item, important } = this.props;
const itemClasses = cx({
'si-timeline-item': true,
'si-urgent': important
});
const d = item.Date instanceof Date ? item.Date : new Date(item.Date);
return (
<div className={itemClasses}>
<div className='si-timeline-item-header'>
{important ?
<button className='btn btn-default si-delete-btn'
onClick={this.handleDelete}
title='Remover notificação'>
<i className='fa fa-lg fa-remove' />
</button> : null}
<div className='si-profile-image-fixed'
style={{
backgroundImage: `url(/users/${item.Author.UserName}/profileimage)`
}} />
<div>
{nonPeopleUserNames.indexOf(item.Author.UserName) === -1 ?
<Link className='si-timeline-item-title-fixed'
onClick={(e) => this.props.onLinkClicked(e)}
to={`/users/${item.Author.UserName}`}>
{item.Author.Name} {item.Author.UserName === userAccount.manager ? <small>(Manager)</small> : null}
</Link> :
<span className='si-timeline-item-title-fixed'>
{item.Author.Name} {item.Author.UserName === userAccount.manager ? <small>(Manager)</small> : null}
</span>}
<date className='si-timeline-item-date-fixed' dateTime={d.toISOString()}>
{d.toLocaleString(navigator.language)}
</date>
</div>
<small className='si-timeline-item-channel'
style={{borderRight: `7px solid ${getColorForChannel(item.Channel.Name)}`}}>
{item.Channel.Name}
</small>
</div>
<div className='si-timeline-item-content'>
{item.Contents.split('/n')
.map((l, i) => {
const conteudos = parseLinha(l);
console.log(conteudos);
return <p key={i}>{conteudos}</p>;
})}
{this.getUrlState()}
</div>
{this.renderAttachments(item.Attachments)}
</div>
);
}
});
export default TimelineItem;
Here's the function :
function urlify(text){
var urlRegex = /(https?:\/\/[^\s]+)?\.(com|pt|es|org|net|)?/g;
return urlRegex.test(text);
And here's the function I want to call only if function urlify happens:
getUrlState() {
return (
<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="..." alt="..."/>
<div class="caption">
<h3>Thumbnail label</h3>
<p>...</p>
<p>Button Button</p>
</div>
</div>
</div>
</div>
);
},
Really need your help thanks.

Resources