Commit 61d26665 authored by Ermolaev Timur's avatar Ermolaev Timur

#103 Реализовал автоселект для выбора проекта

parent 28b542ed
import { Autocomplete, TextField } from "@mui/material";
import { memo } from "react";
function CalendarModalWorkerContent({ allUserProjects, onChangeProjectHandler, workerInfo }) {
console.log(workerInfo)
return (<>
<Autocomplete
id="choose-project"
freeSolo
options={allUserProjects}
getOptionLabel={(item) => item.title || ""}
onChange={onChangeProjectHandler}
name={"userId"}
value={workerInfo.project}
renderInput={(params) => <TextField
style={{ margin: "5px" }}
label={"Проект"}
state={workerInfo.project}
{...params} />}
/>
{workerInfo.project ?
<Autocomplete
id="choose-worker"
freeSolo
options={allUserProjects}
getOptionLabel={(item) => item.title || ""}
onChange={(e, value)=>{ onChangeProjectHandler(e, value)}}
name={"userId"}
value={workerInfo.project}
renderInput={(params) => <TextField
style={{ margin: "5px" }}
label={"Проект"}
state={workerInfo.project}
{...params} />}
/>
: null}
</>);
}
export default memo(CalendarModalWorkerContent);
\ No newline at end of file
...@@ -2,7 +2,7 @@ import { AppBar, Button, Toolbar, Typography } from '@mui/material'; ...@@ -2,7 +2,7 @@ import { AppBar, Button, Toolbar, Typography } from '@mui/material';
import { Box } from '@mui/system'; import { Box } from '@mui/system';
import MonthAndYearInfo from './MonthAndYearInfo/MonthAndYearInfo'; import MonthAndYearInfo from './MonthAndYearInfo/MonthAndYearInfo';
function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMonth, calendarType, onChangeWorkerHandler, onChangeCalendarTypeHandler, worker, year, setModal, currentCalendarDisplayName }) { function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMonth, year, handleOpen, currentCalendarDisplayName }) {
return ( return (
<> <>
...@@ -22,10 +22,10 @@ function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMont ...@@ -22,10 +22,10 @@ function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMont
/> />
</Box> </Box>
<Button <Button
onClick={() => { setModal((prevState) => !prevState) }} onClick={() => { handleOpen() }}
color="inherit" color="inherit"
size="large" size="large"
sx={{marginLeft: 'auto'}} sx={{ marginLeft: 'auto' }}
> >
Выбрать сотрудника Выбрать сотрудника
</Button> </Button>
......
...@@ -16,9 +16,7 @@ const style = { ...@@ -16,9 +16,7 @@ const style = {
p: 4, p: 4,
}; };
export default function DefaultModal({modal, setModal}) { export default function DefaultModal({ modal, handleClose, children }) {
const handleClose = () => setModal(false);
return ( return (
<div> <div>
...@@ -29,7 +27,7 @@ export default function DefaultModal({modal, setModal}) { ...@@ -29,7 +27,7 @@ export default function DefaultModal({modal, setModal}) {
aria-describedby="modal-modal-description" aria-describedby="modal-modal-description"
> >
<Box sx={style}> <Box sx={style}>
<>lol</> {children}
</Box> </Box>
</Modal> </Modal>
</div> </div>
......
import { useEffect, useCallback, useState, useMemo } from 'react'; import { useEffect, useCallback, useState, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import CalendarModalWorkerContent from '../../components/Calendars/CalendarModalWorkerContent/CalendarModalWorkerContent';
import MonthCalendarBody from '../../components/Calendars/MonthCalendar/MonthCalendarBody/MonthCalendarBody'; import MonthCalendarBody from '../../components/Calendars/MonthCalendar/MonthCalendarBody/MonthCalendarBody';
import MonthCalendarHeader from '../../components/Calendars/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader'; import MonthCalendarHeader from '../../components/Calendars/MonthCalendar/MonthCalendarHeader/MonthCalendarHeader';
import DefaultModal from '../../components/UI/DefaultModal/DefaultModal'; import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers'; import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers';
import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions'; import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions'; import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
function MonthCalendar() { function MonthCalendar() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { calendarTasks } = useSelector(state => state.tasks); const { calendarTasks } = useSelector(state => state.tasks);
const {user, currentCalendarDisplayName} = useSelector(state => state.users); const { user, currentCalendarDisplayName } = useSelector(state => state.users);
const { allUserProjects } = useSelector(state => state.projects)
const params = useParams() const params = useParams()
const [hourFormat, setHourFormat] = useState(false); const [hourFormat, setHourFormat] = useState(false);
const [dateNow, setDateNow] = useState({ month: '', year: '' }) const [dateNow, setDateNow] = useState({ month: '', year: '' })
const [worker, setWorker] = useState(''); const [workerInfo, setWorkerInfo] = useState({project: '', worker: ''});
const [calendarType, setCalendarType] = useState('Месяц');
const [currentTask, setCurrentTask] = useState({ title: '', description: '', priority: null, infoForCell: { startHour: null, endHour: null } }) const [currentTask, setCurrentTask] = useState({ title: '', description: '', priority: null, infoForCell: { startHour: null, endHour: null } })
const [copyTask, setCopyTask] = useState(null) const [copyTask, setCopyTask] = useState(null)
const [cellSizes, setCellSizes] = useState({}) const [cellSizes, setCellSizes] = useState({})
...@@ -64,12 +66,11 @@ function MonthCalendar() { ...@@ -64,12 +66,11 @@ function MonthCalendar() {
return getCurrentMonthString(dateNow.month) return getCurrentMonthString(dateNow.month)
}, [dateNow.month]) }, [dateNow.month])
const onChangeWorkerHandler = useCallback((event) => { const onChangeProjectHandler = useCallback((e, value) => {
setWorker(event.target.value); setWorkerInfo((prevState)=>{return {...prevState, project: value}});
}, []); }, []);
const onChangeWorkerHandler = useCallback((e, value) => {
const onChangeCalendarTypeHandler = useCallback((event) => { setWorkerInfo((prevState)=>{return {...prevState, worker: value}});
setCalendarType(event.target.value);
}, []); }, []);
const incrementMonth = useCallback(() => { const incrementMonth = useCallback(() => {
...@@ -216,24 +217,34 @@ function MonthCalendar() { ...@@ -216,24 +217,34 @@ function MonthCalendar() {
dispatch(deleteCalendarTask(taskId, userId)) dispatch(deleteCalendarTask(taskId, userId))
} }
const handleClose = () => {
setModal(false)
}
const handleOpen = async () => {
await dispatch(fetchAllUserProjects())
setModal(true)
}
return ( return (
<> <>
<DefaultModal <DefaultModal
modal={modal} modal={modal}
setModal={setModal} handleClose={() => { handleClose() }}
> >
<CalendarModalWorkerContent
workerInfo={workerInfo}
allUserProjects={allUserProjects}
onChangeProjectHandler={onChangeProjectHandler}
onChangeWorkerHandler={onChangeWorkerHandler}
/>
</DefaultModal> </DefaultModal>
<MonthCalendarHeader <MonthCalendarHeader
year={dateNow.year} year={dateNow.year}
currentMonthString={currentMonthString} currentMonthString={currentMonthString}
decrementMonth={decrementMonth} decrementMonth={decrementMonth}
incrementMonth={incrementMonth} incrementMonth={incrementMonth}
onChangeCalendarTypeHandler={onChangeCalendarTypeHandler} handleOpen={handleOpen}
onChangeWorkerHandler={onChangeWorkerHandler}
worker={worker}
setModal={setModal}
calendarType={calendarType}
currentCalendarDisplayName={currentCalendarDisplayName} currentCalendarDisplayName={currentCalendarDisplayName}
/> />
<MonthCalendarBody <MonthCalendarBody
......
...@@ -10,3 +10,5 @@ export const CREATE_MEMBER_SUCCESS = "CREATE_MEMBER_SUCCESS"; ...@@ -10,3 +10,5 @@ export const CREATE_MEMBER_SUCCESS = "CREATE_MEMBER_SUCCESS";
export const DELETE_MEMBER_REQUEST = "DELETE_MEMBER_REQUEST"; export const DELETE_MEMBER_REQUEST = "DELETE_MEMBER_REQUEST";
export const DELETE_MEMBER_SUCCESS = "DELETE_MEMBER_SUCCESS"; export const DELETE_MEMBER_SUCCESS = "DELETE_MEMBER_SUCCESS";
export const DELETE_MEMBER_FAILURE = "DELETE_MEMBER_FAILURE"; export const DELETE_MEMBER_FAILURE = "DELETE_MEMBER_FAILURE";
export const FETCH_ALL_USER_PROJECTS_SUCCESS = "FETCH_ALL_USER_PROJECTS_SUCCESS";
\ No newline at end of file
import axios from "../../axiosPlanner"; import axios from "../../axiosPlanner";
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 { CREATE_MEMBER_SUCCESS, CREATE_PROJECT_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_ALL_USER_PROJECTS_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 = () => {
...@@ -104,3 +104,19 @@ export const createMember = (memberData, navigate) => { ...@@ -104,3 +104,19 @@ export const createMember = (memberData, navigate) => {
}; };
} }
const fetchAllUserProjectsSuccess = (projects) => {
return {type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects};
};
export const fetchAllUserProjects = () => {
return async dispatch => {
dispatch(fetchProjectsRequest());
try {
const response = await axios.get("/projects/my");
dispatch(fetchAllUserProjectsSuccess(response.data.projects));
} catch (e) {
dispatch(fetchProjectsError(e));
}
}
}
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"; import {DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
const initialState = { const initialState = {
allUserProjects: [],
projects: [], projects: [],
project: "", project: "",
loading: false, loading: false,
...@@ -23,6 +24,8 @@ const initialState = { ...@@ -23,6 +24,8 @@ const initialState = {
return {...state, loading: true}; return {...state, loading: true};
case DELETE_MEMBER_FAILURE: case DELETE_MEMBER_FAILURE:
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
case FETCH_ALL_USER_PROJECTS_SUCCESS:
return {...state, loading: false, allUserProjects: action.projects}
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