I want to set Iscandidate to true if user role === "candidate" and same for comapny if userrole === "company" and other should be false . I am saving isCandidate and isCompany as true and false in DB , if one is true the other should be false but I am not getting desired output.
What I am trying is :
console.log("signin card");
const [phoneNumber, setPhoneNumber] = useState("");
const [isCompany, setIsCompany] = useState(null);
const [isCandidate, setIsCandidate] = useState(null);
const body = {
phoneNumber,
isCandidate,
isCompany,
};
const onSubmitHandler = async () => {
if (userRole === "candidate") {
console.log(userRole);
setIsCandidate(true);
setIsCompany(false);
}
if (userRole === "company") {
console.log(userRole);
setIsCandidate(false);
setIsCompany(true);
}
console.log("body : ", body);
const res = await axios.post(
"http://localhost:8000/user-role/recorded",
body
);
const otpRes = await axios.get(
`https://2factor.in/API/V1/b3014f3e-2e06-11ea-9fa5-0200cd936042/SMS/+91${phoneNumber}/AUTOGEN3`
);
console.log("res = ", res);
console.log("otp = ", otpRes);
};
const onChangeHandler = (e) => {
setPhoneNumber(e.target.value);
};
return (
<>
<div
className="modal"
id="signInCard"
tabIndex="-1"
aria-hidden="true"
style={{
position: "fixed",
top: "0%",
left: "50%",
width: "100%",
height: "100%",
overflowX: "hidden",
overflowY: "auto",
transform: "translateX(-50%)",
zIndex: "1055",
}}
>
<div
className="modal-dialog modal-dialog-centered"
style={{ width: "20%" }}
>
<div className="modal-content">
<div className="modal-body p-5">
<div className="position-absolute end-0 top-0 p-3">
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div className="auth-content">
<div className="w-100">
<div className="text-center mb-4">
<h5>Sign In as {userRole}</h5>
<p className="text-muted"></p>
</div>
<form
onSubmit={(e) => {
onSubmitHandler();
}}
className="auth-form"
>
<div className="input-group mb-3">
{/* <label for="usernameInput" className="form-label">Phone No.</label> */}
<div className="input-group-prepend">
<span className="input-group-text" id="basic-addon1">
+91
</span>
</div>
<input
type="number"
name="phoneNumber"
className="form-control"
id="usernameInput"
placeholder="Enter your phone no."
aria-label="number"
aria-describedby="basic-addon1"
onChange={onChangeHandler}
value={phoneNumber}
/>
<span className="text-danger"></span>
</div>
<div className="text-center">
<a href="#otpModal" data-bs-toggle="modal">
<button
type="submit"
className="btn btn-primary w-100"
onClick={onSubmitHandler}
>
Sign In
</button>
</a>
{/* <a
href="#otpModal"
className="form-text user_sign"
data-bs-toggle="modal"
>
Candidate
</a> */}
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Please help while saving into Db I am getting null
You're posting the data into db just after setting the state. You have to change that
let body = {
phoneNumber,
isCandidate,
isCompany,
};
const onSubmitHandler = async () => {
if (userRole === "candidate") {
console.log(userRole);
setIsCandidate(true);
setIsCompany(false);
body.isCandidate = true;
body.isCompany = false
}
if (userRole === "company") {
console.log(userRole);
setIsCandidate(false);
setIsCompany(true);
body.isCandidate = false;
body.isCompany = true
}
console.log("body : ", body);
const res = await axios.post(
"http://localhost:8000/user-role/recorded",
body
);
const otpRes = await axios.get(
`https://2factor.in/API/V1/b3014f3e-2e06-11ea-9fa5-0200cd936042/SMS/+91${phoneNumber}/AUTOGEN3`
);
console.log("res = ", res);
console.log("otp = ", otpRes);
};
.
You could do something like this:
Instead of using isCompany and isCandidate as states(because they aren't referred to anywhere in the component), update body inside the onSubmitHandler function itself.
console.log("signin card");
const [phoneNumber, setPhoneNumber] = useState("");
const onSubmitHandler = async () => {
const body = {
phoneNumber
};
console.log(userRole);
if (userRole === "candidate") {
body.isCandidate = true;
body.isCompany = false;
}
else if (userRole === "company") {
body.isCandidate = false;
body.isCompany = true;
}
console.log("body : ", body);
const res = await axios.post(
"http://localhost:8000/user-role/recorded",
body
);
const otpRes = await axios.get(
`https://2factor.in/API/V1/b3014f3e-2e06-11ea-9fa5-0200cd936042/SMS/+91${phoneNumber}/AUTOGEN3`
);
console.log("res = ", res);
console.log("otp = ", otpRes);
};
const onChangeHandler = (e) => {
setPhoneNumber(e.target.value);
};
return (
<>
<div
className="modal"
id="signInCard"
tabIndex="-1"
aria-hidden="true"
style={{
position: "fixed",
top: "0%",
left: "50%",
width: "100%",
height: "100%",
overflowX: "hidden",
overflowY: "auto",
transform: "translateX(-50%)",
zIndex: "1055",
}}
>
<div
className="modal-dialog modal-dialog-centered"
style={{ width: "20%" }}
>
<div className="modal-content">
<div className="modal-body p-5">
<div className="position-absolute end-0 top-0 p-3">
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div className="auth-content">
<div className="w-100">
<div className="text-center mb-4">
<h5>Sign In as {userRole}</h5>
<p className="text-muted"></p>
</div>
<form
onSubmit={(e) => {
onSubmitHandler();
}}
className="auth-form"
>
<div className="input-group mb-3">
{/* <label for="usernameInput" className="form-label">Phone No.</label> */}
<div className="input-group-prepend">
<span className="input-group-text" id="basic-addon1">
+91
</span>
</div>
<input
type="number"
name="phoneNumber"
className="form-control"
id="usernameInput"
placeholder="Enter your phone no."
aria-label="number"
aria-describedby="basic-addon1"
onChange={onChangeHandler}
value={phoneNumber}
/>
<span className="text-danger"></span>
</div>
<div className="text-center">
<a href="#otpModal" data-bs-toggle="modal">
<button
type="submit"
className="btn btn-primary w-100"
onClick={onSubmitHandler}
>
Sign In
</button>
</a>
{/* <a
href="#otpModal"
className="form-text user_sign"
data-bs-toggle="modal"
>
Candidate
</a> */}
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Related
It's a beautiful day but this thing is blocking my view:
I've tried everything (except asking a question ._.) and searched everywhere. But the expected result could not be obtained :'(
So, this is my code where I think the error is happening:
<div className="mt-3">
{data.activities?.map((act) => {
return <Chip className="mr-2 px-3" label={act} key={act.id} />;
})}
</div>{" "}
Well it's a part of my file packageCard.js but if you want the whole file here it is:
import Chip from "#material-ui/core/Chip";
import Clock from "./img/main_page_icons/clock.svg";
import Person from "./img/main_page_icons/person.svg";
import MapPin from "./img/main_page_icons/map-pin.svg";
import Package1 from "./img/main_page/package 1.png";
function PackageCard({ data }) {
console.log(data);
return (
<>
<div className="col-lg-4 col-md-6 col-sm-12 card-super-container">
<div className="card-container">
<div className="card-image-wrapper">
<div>
<div className="card-image-background">
<img
alt="package 1"
src={data.featuredImg}
style={{ borderRadius: "6px" }}
className="w-100 "
/>
</div>
</div>
</div>
<div className="card-details-container">
<span className="text-bold details-container-header">
{data.name}
</span>
<div>
<div className="card-details-text">
<div>{data.description}</div>
<div>
<h6 className="card-price">{`Price: ${data.price} USD`}</h6>
</div>
</div>
</div>
</div>
<div>
<div className="card-final-desc">
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={Clock} className="mr-1" />
{` ${data.days}D / ${data.nights}N `}
</div>
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={Person} className="mr-1" />
{` ${data.noOfPersons} Person `}
</div>
<div className="card-final-desc-item">
<span className="card-dot"></span>
<img alt="clock" src={MapPin} className="mr-1" />
{` ${data.destination} `}
</div>
</div>
</div>
<div className="card-btn-container">
<button className="btn zoki-btn">Book Now </button>
</div>
</div>
</div>
<div className="col-lg-4 mb-4">
<img
alt="package 1"
src={data.featuredImg}
style={{ height: 250 }}
className="w-100"
/>
<div
className="bg-white py-4 px-4 shadow-lg"
style={{ fontSize: 14, textAlign: "start" }}
>
<h6>{data.name}</h6>
<p>{data.description}</p>
<div className="d-flex justify-content-between w-100">
<h6 className="m-0">{`Price: ${data.price} USD`}</h6>
<h6 className="m-0" style={{ color: "#9C8E35", cursor: "pointer" }}>
Book Now
</h6>
</div>
/!*{" "}
<div className="mt-3">
{data.activities?.map((act) => {
return <Chip className="mr-2 px-3" label={act} key={act.id} />;
})}
</div>{" "}
*!/
</div>
<div
className="row shadow mx-3"
style={{ backgroundColor: "#9C8E35", fontSize: 12 }}
>
<div className="col-4 p-0 text-center">
<div
className="py-2 text-white d-flex w-100 justify-content-center"
style={{ borderRight: "1px solid white" }}
>
<img alt="clock" src={Clock} className="mr-1" />
<p className="mb-0">{` ${data.days} D / ${data.nights} N `}</p>
</div>
</div>
<div className="col-4 p-0">
<div
className="py-2 text-white d-flex w-100 justify-content-center"
style={{ borderRight: "1px solid white" }}
>
<img alt="clock" src={Person} className="mr-1" />
<p className="mb-0">{` ${data.noOfPersons} Person `}</p>
</div>
</div>
<div className="col-4 p-0">
<div className="py-2 text-white d-flex w-100 justify-content-center">
<img alt="clock" src={MapPin} className="mr-1" />
<p className="mb-0">{` ${data.destination} `}</p>
</div>
</div>
</div>
</div>
</>
);
}
export default PackageCard;
Packages.js Component
import { useState, useEffect } from "react";
import { getAvailablePackages } from "crud";
import PackageBg from "../../../assets/img/offers.jpg";
import Card from "./packageCard";
import CircularProgress from "#material-ui/core/CircularProgress";
import { useHistory } from "react-router-dom";
function Packages() {
const history = useHistory();
const [listPackages, setListPackages] = useState([]);
const [loading, setLoading] = useState(false);
useEffect(() => {
const params = {
search: { query: "" },
sort: "name",
page: 1,
pageSize: 3,
};
setLoading(true);
getAvailablePackages(params)
.then((res) => {
// console.log(res.data.data)
setListPackages(res.data.data.travelPackages);
setLoading(false);
})
.catch((error) => {
console.log(error.response.data);
console.log(error.response.status);
setLoading(false);
});
}, []);
let checkData = [
{
name: "ahmad",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "England",
featuredImg:
"https://media.gettyimages.com/photos/castle-combe-in-the-fall-wiltshire-england-picture-id157006201?s=612x612",
},
{
name: "ali",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "homeland",
featuredImg:
"https://images.unsplash.com/photo-1538332576228-eb5b4c4de6f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8ZmlubGFuZHxlbnwwfHwwfHw%3D&w=1000&q=80",
},
{
name: "ali",
description: "this is description",
price: 5,
days: 5,
nights: 9,
noOfPersons: 9,
destination: "finland",
featuredImg:
"https://images.unsplash.com/photo-1538332576228-eb5b4c4de6f5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8ZmlubGFuZHxlbnwwfHwwfHw%3D&w=1000&q=80",
},
];
return (
<div
id="zoki-packages"
className="text-center py-5 my-5"
style={{
backgroundImage: `url(${PackageBg})`,
backgroundPosition: "center",
backgroundSize: "cover",
}}
>
<div className="container" style={{ color: "#344767" }}>
<h6 className="text-bold font-italic"> EXPLORE GREAT PLACES </h6>
<h1 className=""> Popular Packages </h1>
<div className="row justify-content-center align-content-center">
{checkData?.map((pkg) => {
return <Card data={pkg} key={pkg.id} />;
})}
{loading ? (
<CircularProgress className="my-4 ml-auto mr-auto" />
) : listPackages.length ? (
listPackages?.map((pkg) => {
return <Card data={pkg} key={pkg.id} />;
})
) : (
<h4 className="my-4 ml-auto mr-auto">
No Package Available at that time.
</h4>
)}
</div>
{listPackages.length ? (
<button
onClick={() => history.push("/search-packages")}
className="btn btn-dark px-4 p-2 rounded-pill my-4"
style={{ color: "#CFBD45", backgroundColor: "black", fontSize: 14 }}
>
<p className="mb-0"> VEIW ALL PACKAGES </p>
</button>
) : null}
</div>
</div>
);
}
export default Packages;
I will be very grateful if you find a solution. I appreciate any help you can provide <33
It seems that the act does not have a unique id, try using the index of the map.
<div className="mt-3">
{data.activities?.map((act, i) => (
<Chip className="mr-2 px-3" label={act} key={i} />
))}
</div>
if you use the act.id as the key,should make sure every id is unique cause
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity
here is the official docs
I wanted to try out Strapis guide to create a Trello Clone
https://strapi.io/blog/build-a-trello-clone-application-with-react-and-strapi-1
But right now I'm having a bit of an issue moving my cards...
The cards do show up when moving them but for some reason it doesn't seem to be switching the "state".
this is what my Board.js looks like:
import { ReactSortable } from "react-sortablejs";
import { useState, useEffect } from "react";
import axios from "axios";
const Board = () => {
const [tasks, settasks] = useState([]);
const [drafts, setdrafts] = useState([]);
const [progresstasks, setprogresstasks] = useState([]);
const [approvals, setapprovals] = useState([]);
const [finished, setfinished] = useState([]);
const [onholds, setonholds] = useState([]);
const [newTask, setnewTask] = useState("");
const addTask = async () => {
if(newTask !== ""){
let res = await axios
.post("http://localhost:1337/api/tasks", {
data :{
state: "draft",
Description: newTask,
}
})
.catch((err) => alert("Error occured"));
}
await getTasks();
setnewTask("");
};
const getTasks = async () => {
let Tasks = await axios.get("http://localhost:1337/api/tasks?populate=*");
// return;
settasks(Tasks.data.data);
// For Drafts
let Drafts = tasks.filter((res) => {
return res.attributes.state=== "draft";
});
setdrafts(Drafts);
// For Progress
let Progress = tasks.filter((res) => {
return res.attributes.state === "progress";
});
setprogresstasks(Progress);
// For Finished
let Finished = tasks.filter((res) => {
return res.attributes.state === "finished";
});
setfinished(Finished);
// For Approval
let Approval = tasks.filter((res) => {
return res.attributes.state === "approval";
});
setapprovals(Approval);
// For Onhold
let Onhold = tasks.filter((res) => {
return res.attributes.state=== "onhold";
});
setonholds(Onhold);
};
const getCustomers = async () => {
let Customers = await axios.get("http://localhost:1337/api/customers?populate=*");
}
useEffect(() => {
getTasks();
getCustomers();
});
return (
<>
<div className="container mt-5 mb-5">
<div
className="row"
style={{
height: "80vh",
}}
>
<div className="col mx-2 px-2 py-3 bg-light border rounded">
<h6>Entwurf</h6>
<div
style={{
minHeight: "500px",
}}
>
<ReactSortable
list={tasks}
setList={setdrafts}
groupp={"group-1"}
group={{ name: "group-1", put: true }}
>
{tasks.filter((task) => task.attributes.state === "draft")
.map((filteredTask) => (
<div
className="card p-3 border rounded mt-2"
key={filteredTask.id}
>
{filteredTask.attributes.Description}
</div>
))}
</ReactSortable>
</div>
<div>
<textarea
rows={"1"}
cols={30}
style={{ float: "left", borderBlockColor: "#007bff" }}
value={newTask}
onChange={(event) => setnewTask(event.target.value)}
></textarea>
<button
type="button"
style={{ float: "right", marginTop: "2px" }}
class="btn btn-primary btn-sm"
onClick={addTask}
>
Add Task
</button>
</div>
</div>
<div className="col mx-2 px-2 py-3 bg-light border rounded">
<h6>In Bearbeitung</h6>
<div
style={{
minHeight: "500px",
}}
>
<ReactSortable
list={tasks}
setList={setprogresstasks}
grouppp={"group-1"}
// group={{ name: "group-1", put: true }}
>
{tasks.filter((task) => task.attributes.state === "progress")
.map((filteredTask) => (
<div
className="card p-3 border rounded mt-2"
key={filteredTask.id}
>
{filteredTask.attributes.Description}
</div>
))}
</ReactSortable>
</div>
</div>
<div className="col mx-2 px-2 py-3 bg-light border rounded">
<h6>Fertig</h6>
<div
style={{
minHeight: "500px",
}}
>
<ReactSortable
list={tasks}
setList={setfinished}
groupppp={"group-1"}
// group={{ name: "group-1", put: true }}
>
{tasks.filter((task) => task.attributes.state === "finished")
.map((filteredTask) => (
<div
className="card p-3 border rounded mt-2"
key={filteredTask.id}
>
{filteredTask.attributes.Description}
</div>
))}
</ReactSortable>
</div>
</div>
<div className="col mx-2 px-2 py-3 bg-light border rounded">
<h6>On-Hold</h6>
<div
style={{
minHeight: "500px",
}}
>
<ReactSortable
list={tasks}
setList={setonholds}
grouppppp={"group-1"}
// group={{ name: "group-1", put: true }}
>
{tasks.filter((task) => task.attributes.state === "onhold")
.map((filteredTask) => (
<div
className="card p-3 border rounded mt-2"
key={filteredTask.id}
>
{filteredTask.attributes.Description}
</div>
))}
</ReactSortable>
</div>
</div>
<div className="col mx-2 px-2 py-3 bg-light border rounded">
<h6>Wartet auf Freigabe</h6>
<div
style={{
minHeight: "500px",
}}
>
<ReactSortable
list={tasks}
setList={setapprovals}
groupppppp={"group-1"}
// group={{ name: "group-1", put: true }}
>
{tasks.filter((task) => task.attributes.state === "approval")
.map((filteredTask) => (
<div
className="card p-3 border rounded mt-2"
key={filteredTask.id}
>
{filteredTask.attributes.Description}
</div>
))}
</ReactSortable>
</div>
</div>
</div>
</div>
</>
);
};
export default Board;
Is there something I'm missing like executing a function when moving the cards?
I get this error when i go createNewPost page, I do not know why, could you help me please ? What is the problem?
The other pages (homepage and profile page) does not any problem.
(I researched, but i couldn't find anything.)
Error: Cannot call useFirebaseApp unless your component is within a FirebaseAppProvider
my createNewPost page codes here:
const CreateNewPost = () => {
const { user } = useAuth();
const uid = firebase.auth().currentUser.uid;
const postRef = useFirestore()
.collection("users")
.doc(uid)
.collection("posts");
const [post, setPost] = useState({
content: "",
imageURL: "",
});
const createPost = async () => {
await postRef.add({
content: post.content,
imageURL: post.imageURL,
timezone: dateFormat(),
});
setPost({ content: "", imageURL: "" });
};
return (
<>
<div className="container">
<form>
<div class="form-group">
<div className="d-flex justify-content-start ">
<div className="d-flex align-items-center">
<img
className="rounded-circle py-2"
alt="profile"
src={user.photoURL}
style={{
maxHeight: "80px",
maxWidth: "80px",
marginBottom: "-17px",
}}
/>
<h2 style={{ marginLeft: "7px", marginTop: "16px" }}>
{user.displayName}
</h2>
</div>
</div>
<hr></hr>
<textarea
class="form-control"
id="exampleFormControlTextarea1"
rows="23"
placeholder="Enter a description..."
onChange={(e) => setPost({ content: e.target.value })}
></textarea>
</div>
</form>
<input
class="form-control"
type="text"
placeholder="Enter the image link"
style={{ marginTop: "7px" }}
onChange={(e) => setPost({ imageURL: e.target.value })}
></input>
<div className="d-flex justify-content-end">
<button
type="button"
class="btn btn-primary btn-lg"
style={{ marginTop: "3px" }}
onClick={createPost}
>
Post
</button>
</div>
</div>
</>
);
};
I used Firebase app provider in index.jsx like this, and i solved:
ReactDOM.render(
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<App />
</FirebaseAppProvider>
,
document.getElementById('root')
);
Here is the code!!
Actually very new to react and i am working on a project which is about to-do list but while doing this i am stuck on rendering the output of the input field in the list item. if there is another solution like without the list group it would be very helpful!
Where i am doing the actual mistake please someone look upon this
Thanks in advance!
import React, { Component, Fragment } from "react";
class MainPage extends Component {
state = { data: "" };
handleChange = (e) => {
e.preventDefault();};
handleSubmit = (e) => {
e.preventDefault();
this.setState({ data: e.target.value });
};
render() {
const mystyle = {
padding: "16px 16px 16px 60px",
textAlign: "start",
fontSize: "24px",
fontFamily: 'Helvetica Neue", Helvetica, Arial, sans-serif',
width: "500px",
};
return (
<Fragment>
<h1 className="display-1 text-center" style={{ color: "#f7c6c6" }}>
todos
</h1>
<form className="todo-form" onSubmit={this.handleSubmit}>
<input
type="text"
onChange={this.handleChange.bind(this)}
className="new-todo shadow-lg p-3 mb-5 bg-white rounded"
style={mystyle}
placeholder="What needs to be done?"
/>
<button className="btn btn-primary btn-sm ml-3">Submit</button>
<ul className="list-group">
<li
className="list-group-item disabled p-3 mb-5 w-50 p-3 mx-auto "
style={{ width: "200px", fontSize: "24px" }}
>
{this.state.data}
</li>
</ul>
</form>
</Fragment>
);}}
export default MainPage;
There are some issues in your code:
You want to submit on button. For that you need to add type="submit"
<button className="btn btn-primary btn-sm ml-3" type="submit">
Submit
</button>
You need to maintain two states first for input and second for todo's. In that way you can always append in existing todo when user submits form:
state = { data: [], input: "" };
Last you are saving value onSubmit but it has not e.target.value instead you need to save in onHandleChage
Here is full code:
import React, { Component, Fragment } from "react";
class MainPage extends Component {
state = { data: [], input: "" };
handleChange = (e) => {
e.preventDefault();
this.setState({ input: e.target.value });
};
handleSubmit = (e) => {
e.preventDefault();
this.setState({ data: [...this.state.data, this.state.input], input: "" });
};
render() {
const mystyle = {
padding: "16px 16px 16px 60px",
textAlign: "start",
fontSize: "24px",
fontFamily: 'Helvetica Neue", Helvetica, Arial, sans-serif',
width: "500px"
};
return (
<Fragment>
<h1 className="display-1 text-center" style={{ color: "#f7c6c6" }}>
todos
</h1>
<form className="todo-form" onSubmit={this.handleSubmit}>
<input
type="text"
onChange={this.handleChange.bind(this)}
value={this.state.input}
className="new-todo shadow-lg p-3 mb-5 bg-white rounded"
style={mystyle}
placeholder="What needs to be done?"
/>
<button className="btn btn-primary btn-sm ml-3" type="submit">
Submit
</button>
<ul className="list-group">
{this.state.data.map((data, i) => {
return (
<li
className="list-group-item disabled p-3 mb-5 w-50 p-3 mx-auto "
style={{ width: "200px", fontSize: "24px" }}
key={"todo-" + i}
>
{data}
</li>
);
})}
</ul>
</form>
</Fragment>
);
}
}
export default function App() {
return (
<div className="App">
<MainPage />
</div>
);
}
Here is the demo: https://codesandbox.io/s/xenodochial-banzai-qwxfu?file=/src/App.js:0-1762
import React, { Component, Fragment } from "react";
class MainPage extends Component {
state = { data: "" };
handleSubmit = (e) => {
e.preventDefault();
alert(data)
};
render() {
const mystyle = {
padding: "16px 16px 16px 60px",
textAlign: "start",
fontSize: "24px",
fontFamily: 'Helvetica Neue", Helvetica, Arial, sans-serif',
width: "500px",
};
return (
<Fragment>
<h1 className="display-1 text-center" style={{ color: "#f7c6c6" }}>
todos
</h1>
<form className="todo-form" onSubmit={this.handleSubmit}>
<input
type="text"
onChange={(e) => this.setState({data: e.target.value})}
className="new-todo shadow-lg p-3 mb-5 bg-white rounded"
style={mystyle}
placeholder="What needs to be done?"
/>
<button className="btn btn-primary btn-sm ml-3">Submit</button>
<ul className="list-group">
<li
className="list-group-item disabled p-3 mb-5 w-50 p-3 mx-auto "
style={{ width: "200px", fontSize: "24px" }}
>
{this.state.data}
</li>
</ul>
</form>
</Fragment>
);}}
Try it like:
state = { data: "", FinalDataValue:"" };
handleChange = (e) => {
e.preventDefault();
this.setState({ data: e.target.value });};
handleSubmit = (e) => {
e.preventDefault();
this.setState({ FinalDataValue:this.state.data });};
and in render in list write it like :
<li
className="list-group-item disabled p-3 mb-5 w-50 p-3 mx-auto "
style={{ width: "200px", fontSize: "24px" }}
>
{this.state.FinalDataValue}
</li>
I am trying to add a dropdown button in my react project and its rendering as disabled by default. why is this happening ?
The first dropdown is working fine, i called the same dropdown in the navbar after this one and it renders as disabled. I tried other things as well, like adding a button also would not work for me.
The navbar is diplayed when i get a response from the backend and a different component is rendered (ResultTable)
import React from "react";
import ResultTable from "./ResultTable";
...
import DropdownButton from "react-bootstrap/DropdownButton";
import Dropdown from "react-bootstrap/Dropdown";
class MainContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
//more state values
threshold: 0.75
};
this.thresholdChange = this.thresholdChange.bind(this);
}
thresholdChange(input) {
this.setState({
threshold: input
});
}
toProperCase = function (txt) {
return txt.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
};
render() {
const { responseData } = this.state;
return (
<div className="container-flex container-without-scroll wrapper"
style={{
backgroundImage: `url(${bg})`,
width: "100%",
height: "100vh",
backgroundSize: "cover",
backgroundRepeat: "no-repeat",
overFlow:'hidden'
}}
>
<div
className={`container-fluid `}>
{this.state.displayTable ? (
<Navbar
style={{
position: "fixed",
left: "50%",
top: "95%",
transform: "translate(-50%, -90%)",
backgroundColor: 'black'
}}
sticky="bottom"
>
<br />
<Navbar.Collapse className="justify-content-end">
<Button
variant="primary"
disabled={
this.props.initialTransaction &&
this.props.initialTransaction.version == 0 &&
this.props.initialTransaction
? true
: false
}
size="sm"
style={{ color: "#FFF" }}
onClick={this.undoAction}
>
<span className=" fa fa-undo "></span>
Undo
</Button>
<Button
variant="primary"
size="sm"
style={{ color: "#FFF" }}
disabled={
(this.props.initialTransaction &&
this.props.initialTransaction.version) <
(this.props.currentVersion &&
this.props.currentVersion.version)
? false
: true
}
onClick={this.redoAction}
>
<span className=" fa fa-repeat "></span>
Redo
</Button>
<Button
variant="success"
size="sm"
style={{ color: "#FFF" }}
disabled={
this.props.initialTransaction &&
this.props.initialTransaction.version == 0
? true
: false
}
onClick={() =>
this.exportExcel(this.props.initialTransaction)
}
>
<span className=" fa fa-download "></span>
Export
</Button>
<DropdownButton
size="md"
title={this.state.threshold}
>
{this.state.thresholdValues.map(eachValue => {
return (
<Dropdown.Item
key = {Math.random()}
onClick={() => this.thresholdChange(eachValue)}
as="button"
>
{eachValue}
</Dropdown.Item>
);
})}
</DropdownButton>
</Navbar.Collapse>
<br/>
</Navbar>
) : null}
{this.state.displayTable ? null : (
<div
className="col-md-4 col-md-offset-4"
style={{
position: "absolute",
left: "50%",
top: "50%",
transform: "translate(-50%, -50%)",
backgroundColor: 'rgba(14, 13, 13, 0.74)'
}}
>
<br />
<div className="row">
<div className="input-group col-md-9">
<div className="input-group-prepend">
<span
style={{ cursor: 'pointer' }}
onClick={this.onFormSubmit}
className="input-group-text"
id="inputGroupFileAddon01"
>
{" "}
Upload{" "}
</span>
</div>
<div className="custom-file">
<input
type="file"
className="custom-file-input"
id="inputGroupFile01"
onChange={this.onChange}
aria-describedby="inputGroupFileAddon01"
/>
<label
className="custom-file-label"
htmlFor="inputGroupFile01"
>
{this.props.active && this.props.active.filename}
</label>
</div>
</div>
<div className="col-md-3">
<DropdownButton
size="md"
id="dropdown-item-button"
title={this.state.threshold}
>
{this.state.thresholdValues.map(eachValue => {
return (
<Dropdown.Item
onClick={() => this.thresholdChange(eachValue)}
as="button"
>
{eachValue}
</Dropdown.Item>
);
})}
</DropdownButton>
</div>
</div>
<br />
</div>
)}
<div >
{this.state.displayTable ? (
<div className = "container-flex" style =
{{overflowY:'scroll', maxHeight:'80vh'}}>
<ResultTable
data={responseData}
afterMerge={params => {
this.afterMerge(params);
}}
/>
</div>
) : null}
</div>
</div>
</div>
);
}
}
// Maps state from store to props
const mapStateToProps = (state, ownProps) => {
return {
};
};
// Maps actions to props
const mapDispatchToProps = dispatch => {
return {
};
};
// Use connect to put them together
export default connect(
mapStateToProps,
mapDispatchToProps
)(MainContainer);