guild_front/src/components/UI/ModalCreate/ModalCreate.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-03-22 21:48:06 +03:00
import React, { useState } from "react";
2023-03-23 16:43:37 +03:00
import { useDispatch } from "react-redux";
2023-03-27 19:08:01 +03:00
import { setProject } from "../../../redux/projectsTrackerSlice";
2023-03-22 21:48:06 +03:00
import "./ModalCreate.scss";
export const ModalCreate = ({ active, setActive, title }) => {
const [inputValue, setInputValue] = useState("");
const dispatch = useDispatch();
function createName() {
2023-03-27 19:08:01 +03:00
if (inputValue === "") {
return;
} else {
let newItem = {
name: inputValue,
count: 0,
};
dispatch(setProject(newItem));
setActive(false);
setInputValue("");
}
2023-03-22 21:48:06 +03:00
}
return (
<div
className={active ? "modal-project active" : "modal-project"}
onClick={() => setActive(false)}
>
<div
className="modal-project__content"
onClick={(e) => e.stopPropagation()}
>
<div className="title-project">
<h4>{title}</h4>
<div className="input-container">
<input
className="name-project"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
></input>
</div>
</div>
<button className="create-project" onClick={createName}>
Создать
</button>
</div>
</div>
);
};
export default ModalCreate;