Commit 28b542ed authored by Ermolaev Timur's avatar Ermolaev Timur

#103 Релизовал вывод информации чей это календарь

parent 1fba0e35
...@@ -7,6 +7,7 @@ import path from 'path'; ...@@ -7,6 +7,7 @@ import path from 'path';
import {config} from "../config" import {config} from "../config"
import { Project } from '../models/Project'; import { Project } from '../models/Project';
import { Member, MemberRole } from '../models/Member'; import { Member, MemberRole } from '../models/Member';
import { auth } from '../helpers';
const router:Router = express.Router(); const router:Router = express.Router();
const dataSource = myDataSource; const dataSource = myDataSource;
...@@ -35,6 +36,19 @@ const users = await dataSource ...@@ -35,6 +36,19 @@ const users = await dataSource
return res.send({users}) return res.send({users})
}) })
//** return displayName of user, requested by userId */
router.get('/display-name/:userId', auth, async (req : Request, res : Response):Promise<object> => {
const {userId} = req.params
const displayName = await dataSource
.createQueryBuilder()
.select(['user.displayName'])
.from(User, "user")
.where("user.id = :userId", { userId })
.getOne()
if (!displayName) return res.status(404).send({message:'displayName not found'})
return res.send(displayName)
})
//** return all users of DB */ //** return all users of DB */
router.get('/all-fields/', async (req : Request, res : Response):Promise<object> => { router.get('/all-fields/', async (req : Request, res : Response):Promise<object> => {
......
...@@ -4,7 +4,7 @@ import { priorities } from "../../../constants"; ...@@ -4,7 +4,7 @@ import { priorities } from "../../../constants";
import CustomSelect from '../../UI/СustomSelect/СustomSelect' import CustomSelect from '../../UI/СustomSelect/СustomSelect'
function MonthCalendarModalContent({ title, onChangeCurrentTaskHandler, description, priority, sendNewTaskHandler, deleteTaskHandler, startHour, endHour }) { function CalendarModalContent({ title, onChangeCurrentTaskHandler, description, priority, sendNewTaskHandler, deleteTaskHandler, startHour, endHour }) {
return (<> return (<>
<TextField <TextField
id="task-description-title" id="task-description-title"
...@@ -61,4 +61,4 @@ function MonthCalendarModalContent({ title, onChangeCurrentTaskHandler, descript ...@@ -61,4 +61,4 @@ function MonthCalendarModalContent({ title, onChangeCurrentTaskHandler, descript
</>); </>);
} }
export default memo(MonthCalendarModalContent); export default memo(CalendarModalContent);
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,7 @@ import CalendarRow from "../../CalendarRow/CalendarRow"; ...@@ -4,7 +4,7 @@ import CalendarRow from "../../CalendarRow/CalendarRow";
import CalendarSmallCell from "../../CalendarSmallCell/CalendarSmallCell"; import CalendarSmallCell from "../../CalendarSmallCell/CalendarSmallCell";
import CalendarStandartCell from "../../CalendarStandartCell/CalendarStandartCell"; import CalendarStandartCell from "../../CalendarStandartCell/CalendarStandartCell";
import ModalTask from "../../../UI/ModalTask/ModalTask" import ModalTask from "../../../UI/ModalTask/ModalTask"
import MonthCalendarModalContent from "../../MonthCalendarModalContent/MonthCalendarModalContent"; import MonthCalendarModalContent from "../../CalendarModalContent/CalendarModalContent";
import CalendarRowDay from "./CalendarRowDay/CalendarRowDay"; import CalendarRowDay from "./CalendarRowDay/CalendarRowDay";
......
...@@ -12,7 +12,8 @@ function MonthAndYearInfo({ currentMonthString, year, incrementMonth, decrementM ...@@ -12,7 +12,8 @@ function MonthAndYearInfo({ currentMonthString, year, incrementMonth, decrementM
flexGrow: 1, flexGrow: 1,
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
gap: '10px' gap: '10px',
marginBottom: '20px'
}} }}
id='test_month_info' id='test_month_info'
> >
...@@ -21,7 +22,7 @@ function MonthAndYearInfo({ currentMonthString, year, incrementMonth, decrementM ...@@ -21,7 +22,7 @@ function MonthAndYearInfo({ currentMonthString, year, incrementMonth, decrementM
/> />
<Box sx={{ flexBasis: '150px' }}> <Box sx={{ flexBasis: '150px' }}>
<Typography <Typography
variant="h6" variant="h5"
sx={{ sx={{
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
......
import { AppBar, Button, Toolbar } from '@mui/material'; 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 }) { function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMonth, calendarType, onChangeWorkerHandler, onChangeCalendarTypeHandler, worker, year, setModal, currentCalendarDisplayName }) {
return ( return (
<> <>
...@@ -10,22 +10,25 @@ function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMont ...@@ -10,22 +10,25 @@ function MonthCalendarHeader({ currentMonthString, decrementMonth, incrementMont
<AppBar position="static"> <AppBar position="static">
<Toolbar> <Toolbar>
<Box>
<Typography variant="h5" sx={{ margin: "20px 0 20px 0" }}>
Календарь: {currentCalendarDisplayName}
</Typography>
<MonthAndYearInfo <MonthAndYearInfo
currentMonthString={currentMonthString} currentMonthString={currentMonthString}
decrementMonth={decrementMonth} decrementMonth={decrementMonth}
incrementMonth={incrementMonth} incrementMonth={incrementMonth}
year={year} year={year}
/> />
</Box>
<div style={{ marginLeft: '20px' }}>
<Button <Button
onClick={()=>{setModal((prevState)=>!prevState)}} onClick={() => { setModal((prevState) => !prevState) }}
color="inherit" color="inherit"
size="large" size="large"
sx={{marginLeft: 'auto'}}
> >
Выбрать сотрудника Выбрать сотрудника
</Button> </Button>
</div>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
</Box> </Box>
......
...@@ -17,7 +17,7 @@ const style = { ...@@ -17,7 +17,7 @@ const style = {
}; };
export default function DefaultModal({modal, setModal}) { export default function DefaultModal({modal, setModal}) {
console.log(modal)
const handleClose = () => setModal(false); const handleClose = () => setModal(false);
return ( return (
......
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 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 { 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';
function MonthCalendar() { function MonthCalendar() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { calendarTasks } = useSelector(state => state.tasks); const { calendarTasks } = useSelector(state => state.tasks);
const user = useSelector(state => state.users?.user); const {user, currentCalendarDisplayName} = useSelector(state => state.users);
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: '' })
...@@ -26,8 +29,15 @@ function MonthCalendar() { ...@@ -26,8 +29,15 @@ function MonthCalendar() {
month: new Date().getMonth(), month: new Date().getMonth(),
year: new Date().getFullYear(), year: new Date().getFullYear(),
}) })
if (params.id) {
setUserId(params.id)
dispatch(fetchCalendarTasks(params.id))
dispatch(fetchCurrentCalendarDisplayName(params.id))
} else {
setUserId(user.id) setUserId(user.id)
dispatch(fetchCalendarTasks(user.id)) dispatch(fetchCalendarTasks(user.id))
dispatch(fetchCurrentCalendarDisplayName(user.id))
}
}, [dispatch]) }, [dispatch])
...@@ -224,6 +234,7 @@ function MonthCalendar() { ...@@ -224,6 +234,7 @@ function MonthCalendar() {
worker={worker} worker={worker}
setModal={setModal} setModal={setModal}
calendarType={calendarType} calendarType={calendarType}
currentCalendarDisplayName={currentCalendarDisplayName}
/> />
<MonthCalendarBody <MonthCalendarBody
month={dateNow.month} month={dateNow.month}
......
...@@ -15,3 +15,5 @@ export const FETCH_USERS_FAILURE = "FETCH_USERS_FAILURE"; ...@@ -15,3 +15,5 @@ export const FETCH_USERS_FAILURE = "FETCH_USERS_FAILURE";
export const FETCH_USERS_ALL_FIELDS_REQUEST = "FETCH_USERS_ALL_FIELDS_REQUEST"; export const FETCH_USERS_ALL_FIELDS_REQUEST = "FETCH_USERS_ALL_FIELDS_REQUEST";
export const FETCH_USERS_ALL_FIELDS_SUCCESS = "FETCH_USERS_ALL_FIELDS_SUCCESS"; export const FETCH_USERS_ALL_FIELDS_SUCCESS = "FETCH_USERS_ALL_FIELDS_SUCCESS";
export const FETCH_USERS_ALL_FIELDS_FAILURE = "FETCH_USERS_ALL_FIELDS_FAILURE"; export const FETCH_USERS_ALL_FIELDS_FAILURE = "FETCH_USERS_ALL_FIELDS_FAILURE";
export const FETCH_DISPLAYNAME_SUCCESS = "FETCH_DISPLAYNAME_SUCCESS";
\ No newline at end of file
import axios from "../../axiosPlanner"; import axios from "../../axiosPlanner";
import { FETCH_USERS_FAILURE, FETCH_USERS_REQUEST, FETCH_USERS_SUCCESS, LOGIN_USER_FAILURE, LOGIN_USER_SUCCESS, LOGOUT_USER_FAILURE, LOGOUT_USER_SUCCESS, REGISTER_USER_FAILURE, REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS,FETCH_USERS_ALL_FIELDS_REQUEST, import { FETCH_USERS_FAILURE, FETCH_USERS_REQUEST, FETCH_USERS_SUCCESS, LOGIN_USER_FAILURE, LOGIN_USER_SUCCESS, LOGOUT_USER_FAILURE, LOGOUT_USER_SUCCESS, REGISTER_USER_FAILURE, REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS,FETCH_USERS_ALL_FIELDS_REQUEST,
FETCH_USERS_ALL_FIELDS_SUCCESS, FETCH_USERS_ALL_FIELDS_SUCCESS,
FETCH_USERS_ALL_FIELDS_FAILURE, } from "../actionTypes/userActionTypes" FETCH_USERS_ALL_FIELDS_FAILURE,
FETCH_DISPLAYNAME_SUCCESS, } from "../actionTypes/userActionTypes"
import { showNotification } from "./commonActions"; import { showNotification } from "./commonActions";
const registerUserRequest = () => { const registerUserRequest = () => {
...@@ -136,3 +137,20 @@ export const fetchUsersAllFields = () => { ...@@ -136,3 +137,20 @@ export const fetchUsersAllFields = () => {
} }
}; };
const fetchCurrentCalendarDisplayNameSuccess = (displayName) => {
return {type: FETCH_DISPLAYNAME_SUCCESS, displayName}
}
export const fetchCurrentCalendarDisplayName = (userId) => {
return async dispatch => {
dispatch(fetchUsersAllFieldsRequest());
try {
const response = await axios.get(`/users/display-name/${userId}`);
dispatch(fetchCurrentCalendarDisplayNameSuccess(response.data.displayName));
} catch (e) {
dispatch(fetchUsersAllFieldsFailure(e.response.data));
}
}
};
import { REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS, REGISTER_USER_FAILURE, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE, LOGOUT_USER_SUCCESS, FETCH_USERS_SUCCESS,FETCH_USERS_ALL_FIELDS_SUCCESS } from "../actionTypes/userActionTypes"; import { REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS, REGISTER_USER_FAILURE, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE, LOGOUT_USER_SUCCESS, FETCH_USERS_SUCCESS,FETCH_USERS_ALL_FIELDS_SUCCESS, FETCH_DISPLAYNAME_SUCCESS } from "../actionTypes/userActionTypes";
const initialState = { const initialState = {
user: null, user: null,
users: [], users: [],
usersAllFields:[], usersAllFields:[],
currentCalendarDisplayName: '',
registerError: null, registerError: null,
loginError: null, loginError: null,
loading: false loading: false
...@@ -30,6 +31,8 @@ const usersReducer = (state = initialState, action) => { ...@@ -30,6 +31,8 @@ const usersReducer = (state = initialState, action) => {
return {...state, loading: false, users: action.users}; return {...state, loading: false, users: action.users};
case FETCH_USERS_ALL_FIELDS_SUCCESS: case FETCH_USERS_ALL_FIELDS_SUCCESS:
return {...state, loading: false, usersAllFields: action.users}; return {...state, loading: false, usersAllFields: action.users};
case FETCH_DISPLAYNAME_SUCCESS:
return {...state, loading: false, currentCalendarDisplayName: action.displayName};
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