Commit 06b02f32 authored by Ibadullina Inabat's avatar Ibadullina Inabat

устранена неполадка вывода данных при добавлении нового участника в проект

parent fec54d89
...@@ -25,34 +25,36 @@ const MemberForm = ({ onSubmit }) => { ...@@ -25,34 +25,36 @@ const MemberForm = ({ onSubmit }) => {
const users = useSelector(state => state.users.users) const users = useSelector(state => state.users.users)
const [role, setRole] = useState([{ role: "user" }, { role: "admin" }, { role: "watcher" }]) const [role, setRole] = useState([{ role: "user" }, { role: "admin" }, { role: "watcher" }])
const params = useParams() const params = useParams()
console.log(users)
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true); const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false); const handleClose = () => setOpen(false);
const [state, setState] = useState({ const [state, setState] = useState({
displayName: "", // displayName: "",
roleProject: "", roleProject: "",
userId: "", user: "",
projectId: "" projectId: ""
}); });
const submitFormHandler = (e) => { const submitFormHandler = (e) => {
e.preventDefault(); e.preventDefault();
let idOfUser = users?.map((user) => (user.displayName === state.displayName) ? user.id : null) // let idOfUser = users?.map((user) => (user.displayName === state.displayName) ? user.id : null)
let idOfUser1 = users?.map((user) => { // let idOfUser = users?.map((user) => {
console.log(user) // console.log(user)
return null // return (user.id === state.displayName.id) ? user.id : null
}) // })
console.log(idOfUser1) // console.log(idOfUser)
console.log(idOfUser) // console.log(idOfUser)
console.log("state of submit " + state); console.log("state of submit " + state);
let members = {roleProject: state.roleProject, projectId: params.id, userId: idOfUser } let members = {roleProject: state.roleProject, projectId: params.id, userId: state.user.id}
console.log(members); console.log(members);
onSubmit(members); onSubmit(members);
setOpen(false);
}; };
console.log(state);
// console.log(user)
// const onChange = (e) => { // const onChange = (e) => {
// const value = e.target.value; // const value = e.target.value;
// const name = e.target.name; // const name = e.target.name;
...@@ -64,7 +66,7 @@ const MemberForm = ({ onSubmit }) => { ...@@ -64,7 +66,7 @@ const MemberForm = ({ onSubmit }) => {
// }; // };
const memberChangeHandler = (e, value) => { const memberChangeHandler = (e, value) => {
setState(() => { return { ...state, member: value, userId: state.userId} }); setState(() => { return { ...state, user: value, projectId: params.id} });
console.log("memberChangeHandler" + value) console.log("memberChangeHandler" + value)
} }
const roleChangeHandler = (e, value) => { const roleChangeHandler = (e, value) => {
...@@ -73,7 +75,7 @@ const MemberForm = ({ onSubmit }) => { ...@@ -73,7 +75,7 @@ const MemberForm = ({ onSubmit }) => {
} }
return ( return (
<div > <div >
<PersonAddIcon onClick={handleOpen} style={{marginLeft: "30px", marginTop: "-3px"}} >Добавить участника</PersonAddIcon> <PersonAddIcon onClick={handleOpen} style={{marginLeft: "30px", marginTop: "-3px", cursor: 'pointer'}} >Добавить участника</PersonAddIcon>
<Modal <Modal
open={open} open={open}
onClose={handleClose} onClose={handleClose}
...@@ -88,15 +90,13 @@ const MemberForm = ({ onSubmit }) => { ...@@ -88,15 +90,13 @@ const MemberForm = ({ onSubmit }) => {
<Autocomplete <Autocomplete
id="free-solo-demo" id="free-solo-demo"
freeSolo freeSolo
options={users?.map((user) => user.displayName)} options={users}
getOptionLabel={(item) => item.displayName || ""}
onChange={memberChangeHandler} onChange={memberChangeHandler}
name={"userId"} name={"userId"}
value={state.userId} value={state.user}
renderInput={(params) => <TextField renderInput={(params) => <TextField
style={{margin: "5px"}} style={{margin: "5px"}}
label={"Участник"} label={"Участник"}
state={state} state={state}
{...params} />} {...params} />}
...@@ -110,7 +110,6 @@ const MemberForm = ({ onSubmit }) => { ...@@ -110,7 +110,6 @@ const MemberForm = ({ onSubmit }) => {
renderInput={(params) => <TextField renderInput={(params) => <TextField
style={{margin: "5px"}} style={{margin: "5px"}}
name={"roleProject"} name={"roleProject"}
label={"Роль в проекте"} label={"Роль в проекте"}
state={state} state={state}
{...params} />} {...params} />}
......
...@@ -13,7 +13,7 @@ const NewMember = ({members}) => { ...@@ -13,7 +13,7 @@ const NewMember = ({members}) => {
const onSubmit = async (memberData) => { const onSubmit = async (memberData) => {
await dispatch(createMember(memberData, navigate)); await dispatch(createMember(memberData, navigate));
// navigate("/projects/" + memberData.id) navigate("/projects/" + memberData.projectId)
console.log("memberData ", memberData) console.log("memberData ", memberData)
}; };
......
...@@ -6,3 +6,7 @@ export const FETCH_PROJECT_SUCCESS = "FETCH_PROJECT_SUCCESS"; ...@@ -6,3 +6,7 @@ export const FETCH_PROJECT_SUCCESS = "FETCH_PROJECT_SUCCESS";
export const CREATE_PROJECT_SUCCESS = "CREATE_PROJECT_SUCCESS"; export const CREATE_PROJECT_SUCCESS = "CREATE_PROJECT_SUCCESS";
export const CREATE_MEMBER_SUCCESS = "CREATE_MEMBER_SUCCESS"; export const CREATE_MEMBER_SUCCESS = "CREATE_MEMBER_SUCCESS";
export const DELETE_MEMBER_REQUEST = "DELETE_MEMBER_REQUEST";
export const DELETE_MEMBER_SUCCESS = "DELETE_MEMBER_SUCCESS";
export const DELETE_MEMBER_FAILURE = "DELETE_MEMBER_FAILURE";
\ No newline at end of file
import axios from "../../axiosPlanner"; import axios from "../../axiosPlanner";
import { CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, FETCH_MEMBERS_ERROR, FETCH_MEMBERS_REQUEST, FETCH_MEMBERS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes"; import { CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_MEMBERS_ERROR, FETCH_MEMBERS_REQUEST, FETCH_MEMBERS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
import { showNotification } from "./commonActions"; import { showNotification } from "./commonActions";
const fetchProjectsRequest = () => { const fetchProjectsRequest = () => {
...@@ -23,6 +23,31 @@ const createMemberSuccess = (member) => { ...@@ -23,6 +23,31 @@ const createMemberSuccess = (member) => {
return {type: CREATE_MEMBER_SUCCESS, member}; return {type: CREATE_MEMBER_SUCCESS, member};
}; };
const deleteMemberRequest = () => {
return {type: DELETE_MEMBER_REQUEST}
};
const deleteMemberSuccess = () => {
return {type: DELETE_MEMBER_SUCCESS}
};
const deleteMemberFailure = (error) => {
return {type: DELETE_MEMBER_FAILURE, error}
};
export const deleteMember = (memberId) => {
return async (dispatch) => {
dispatch(deleteMemberRequest());
try {
await axios.delete(`/tasks/${memberId}`);
dispatch(deleteMemberSuccess())
dispatch(fetchProject())
} catch (error) {
dispatch(deleteMemberFailure(error.response.data));
}
}
}
export const fetchProjects = () => { export const fetchProjects = () => {
return async dispatch => { return async dispatch => {
dispatch(fetchProjectsRequest()); dispatch(fetchProjectsRequest());
...@@ -41,7 +66,7 @@ export const fetchProject = (id) => { ...@@ -41,7 +66,7 @@ export const fetchProject = (id) => {
try { try {
const response = await axios.get("/projects/" + id); const response = await axios.get("/projects/" + id);
dispatch(fetchProjectSuccess(response.data)); dispatch(fetchProjectSuccess(response.data));
console.log("fetch project "+response.data) console.log("fetch project ", response.data)
} catch (e) { } catch (e) {
dispatch(fetchProjectsError(e)); dispatch(fetchProjectsError(e));
} }
......
import {FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes"; import {DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
const initialState = { const initialState = {
projects: [], projects: [],
...@@ -17,6 +17,12 @@ const initialState = { ...@@ -17,6 +17,12 @@ const initialState = {
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
case FETCH_PROJECT_SUCCESS: case FETCH_PROJECT_SUCCESS:
return {...state, loading: false, project: action.project} return {...state, loading: false, project: action.project}
case DELETE_MEMBER_SUCCESS:
return {...state, loading: false};
case DELETE_MEMBER_REQUEST:
return {...state, loading: true};
case DELETE_MEMBER_FAILURE:
return {...state, loading: false, error: action.error};
default: default:
return state; return state;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment