#167 week-data-start added to the front in store/actions/commonActions

parent 251b2975
...@@ -47,7 +47,6 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> { ...@@ -47,7 +47,6 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
.leftJoinAndSelect('member.user', 'user') .leftJoinAndSelect('member.user', 'user')
.where('project.id IN(:...projectIds)', {projectIds}) .where('project.id IN(:...projectIds)', {projectIds})
.getMany() .getMany()
console.log('projects \n',projects)
return res.send({projects}) return res.send({projects})
} catch(e) { } catch(e) {
return res.status(502).send({message:(e as Error).message}) return res.status(502).send({message:(e as Error).message})
......
...@@ -133,7 +133,6 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response ...@@ -133,7 +133,6 @@ router.get('/user/:userId', async (req: Request, res: Response):Promise<Response
id:userId id:userId
}}, }},
}) })
console.log('tasks \n',tasks)
return res.send({tasks}) return res.send({tasks})
} catch(e){ } catch(e){
return res.status(502).send({message:(e as Error).message}) return res.status(502).send({message:(e as Error).message})
...@@ -402,6 +401,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp ...@@ -402,6 +401,7 @@ router.get('/users-tasks', auth,async (req: Request, res: Response):Promise<Resp
* object with key displayName related to userId, list of Project related to user * object with key displayName related to userId, list of Project related to user
*/ */
router.get('/week-data-start/:userId',auth, async (req: Request, res: Response):Promise<Response>=>{ router.get('/week-data-start/:userId',auth, async (req: Request, res: Response):Promise<Response>=>{
console.log('week-data-start')
const {userId} = req.params const {userId} = req.params
try{ try{
const requesterUser= req.body.user const requesterUser= req.body.user
...@@ -436,18 +436,17 @@ router.get('/week-data-start/:userId',auth, async (req: Request, res: Response): ...@@ -436,18 +436,17 @@ router.get('/week-data-start/:userId',auth, async (req: Request, res: Response):
.getRepository(Task) .getRepository(Task)
.find({ .find({
relations:{ relations:{
project:true, executor:true,
}, },
where:{ where:
project:{ {
id:In(projectIds) executor:{
} id:userId
} }},
}) })
const {displayName} = user const {displayName} = user
if (!tasks) return res.status(404).send({Message:'tasks not found'}) if (!tasks) return res.status(404).send({Message:'tasks not found'})
console.log('tasks: ',tasks, "projects" ,projects , 'displayName' ,displayName) console.log('tasks: ',tasks, "projects: " ,projects , 'displayName : ' ,displayName)
return res.send({displayName, projects, tasks}) return res.send({displayName, projects, tasks})
} catch(e){ } catch(e){
return res.status(502).send({message:(e as Error).message}) return res.status(502).send({message:(e as Error).message})
......
...@@ -51,7 +51,6 @@ return res.send({users}) ...@@ -51,7 +51,6 @@ return res.send({users})
.where("user.id = :userId", { userId }) .where("user.id = :userId", { userId })
.getOne() .getOne()
if (!displayName) return res.status(404).send({message:'displayName not found'}) if (!displayName) return res.status(404).send({message:'displayName not found'})
console.log('displayName \n',displayName)
return res.send(displayName) return res.send(displayName)
} catch(e) { } catch(e) {
return res.status(502).send({message:(e as Error).message}) return res.status(502).send({message:(e as Error).message})
......
...@@ -11,6 +11,7 @@ import DefaultModal from '../../components/UI/DefaultModal/DefaultModal'; ...@@ -11,6 +11,7 @@ import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants'; import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants';
import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers'; import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers';
import { fetchWeekDataStart } from '../../store/actions/commonActions';
import { fetchAllUserProjects } from '../../store/actions/projectsActions'; import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deactivateCreateCopyTasksMode, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions'; import { addCalendarTask, addCopyCalendarTask, deactivateCreateCopyTasksMode, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions'; import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
...@@ -44,14 +45,17 @@ function WeekCalendar() { ...@@ -44,14 +45,17 @@ function WeekCalendar() {
useEffect(() => { useEffect(() => {
if (userCalendarId) { if (userCalendarId) {
setUserId(userCalendarId) setUserId(userCalendarId)
dispatch(fetchCalendarTasks(userCalendarId)) // dispatch(fetchCalendarTasks(userCalendarId))
dispatch(fetchCurrentCalendarDisplayName(userCalendarId)) // dispatch(fetchCurrentCalendarDisplayName(userCalendarId))
dispatch(fetchAllUserProjects()) // dispatch(fetchAllUserProjects())
dispatch(fetchWeekDataStart(userCalendarId))
} else { } else {
setUserId(user.id) setUserId(user.id)
dispatch(fetchCalendarTasks(user.id)) dispatch(fetchWeekDataStart(user.id))
dispatch(fetchCurrentCalendarDisplayName(user.id))
dispatch(fetchAllUserProjects()) // dispatch(fetchCalendarTasks(user.id))
// dispatch(fetchCurrentCalendarDisplayName(user.id))
// dispatch(fetchAllUserProjects())
} }
}, [userCalendarId, dispatch, user.id]) }, [userCalendarId, dispatch, user.id])
......
...@@ -34,6 +34,10 @@ export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE" ...@@ -34,6 +34,10 @@ export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE" export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE"
export const FETCH_WEEK_DATA_START_REQUEST = "FETCH_WEEK_DATA_START_REQUEST";
export const FETCH_WEEK_DATA_START_SUCCESS = "FETCH_WEEK_DATA_START_SUCCESS";
export const FETCH_WEEK_DATA_START_FAILURE = "FETCH_WEEK_DATA_START_FAILURE";
......
import axios from '../../axiosPlanner';
import {
FETCH_WEEK_DATA_START_REQUEST,
FETCH_WEEK_DATA_START_SUCCESS,
FETCH_WEEK_DATA_START_FAILURE,
FETCH_CALENDAR_TASKS_REQUEST,
} from '../actionTypes/tasksTypes';
import {fetchAllUserProjectsSuccess} from './projectsActions';
import { fetchCalendarTasksSuccess } from './tasksActions';
import { fetchCurrentCalendarDisplayNameSuccess } from './usersActions';
export const showNotification = (message, variant="success") => { export const showNotification = (message, variant="success") => {
return {type: "SHOW_NOTIFICATION", message, variant} return {type: "SHOW_NOTIFICATION", message, variant}
} }
export const hideNotification = () => { export const hideNotification = () => {
return {type: "HIDE_NOTIFICATION"}; return {type: "HIDE_NOTIFICATION"};
}; };
/** weekDataStart, recieves userId returns type WEEK_DATA_START_REQUEST*/
const fetchWeekDataStartRequest = () => {
return { type: FETCH_WEEK_DATA_START_REQUEST }
}
/** weekDataStart, recieves userId returns type WEEK_DATA_START_SUCCESS*/
const fetchWeekDataStartSuccess = (weekData) => {
return { type: FETCH_WEEK_DATA_START_SUCCESS, weekData }
}
/** weekDataStart, recieves userId returns type WEEK_DATA_START_FAILURE*/
const fetchWeekDataStartFailure = (error) => {
return { type: FETCH_WEEK_DATA_START_FAILURE, error }
}
/**fetchWeekDataStart, recieves userId ,make GET request to 'tasks/week-data-start/{userId}, recieves weekdata */
export const fetchWeekDataStart = (userId) => {
return async (dispatch) => {
dispatch(fetchWeekDataStartRequest());
try {
console.log('fetchWeekDataStart front', userId)
const response = await axios.get(`/tasks/week-data-start/${userId}`);
dispatch(fetchCalendarTasksSuccess(response.data.tasks))
dispatch(fetchAllUserProjectsSuccess(response.data.projects));
dispatch(fetchCurrentCalendarDisplayNameSuccess(response.data.displayName));
} catch (error) {
dispatch(fetchWeekDataStartFailure(error.response.data));
}
}
}
\ No newline at end of file
...@@ -143,7 +143,7 @@ export const createMember = (memberData) => { ...@@ -143,7 +143,7 @@ export const createMember = (memberData) => {
}; };
} }
const fetchAllUserProjectsSuccess = (projects) => { export const fetchAllUserProjectsSuccess = (projects) => {
return { type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects }; return { type: FETCH_ALL_USER_PROJECTS_SUCCESS, projects };
}; };
......
...@@ -24,6 +24,10 @@ import { ...@@ -24,6 +24,10 @@ import {
SORT_TASKS, SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS, FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE, FETCH_PROJECTS_NON_WATCHER_FAILURE,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_WEEK_DATA_START_FAILURE,
FETCH_WEEK_DATA_START_REQUEST,
FETCH_WEEK_DATA_START_SUCCESS
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner' import axios from '../../axiosPlanner'
...@@ -31,7 +35,7 @@ const fetchCalendarTasksRequest = () => { ...@@ -31,7 +35,7 @@ const fetchCalendarTasksRequest = () => {
return { type: FETCH_CALENDAR_TASKS_REQUEST } return { type: FETCH_CALENDAR_TASKS_REQUEST }
}; };
const fetchCalendarTasksSuccess = (tasks) => { export const fetchCalendarTasksSuccess = (tasks) => {
return { type: FETCH_CALENDAR_TASKS_SUCCESS, tasks } return { type: FETCH_CALENDAR_TASKS_SUCCESS, tasks }
}; };
...@@ -353,3 +357,6 @@ export const activateCreateCopyTasksMode = (task, navigate) => { ...@@ -353,3 +357,6 @@ export const activateCreateCopyTasksMode = (task, navigate) => {
export const deactivateCreateCopyTasksMode = () => { export const deactivateCreateCopyTasksMode = () => {
return { type: DEACTIVATE_CREATE_COPY_TASKS_MODE } return { type: DEACTIVATE_CREATE_COPY_TASKS_MODE }
} }
...@@ -137,7 +137,7 @@ export const fetchUsersAllFields = () => { ...@@ -137,7 +137,7 @@ export const fetchUsersAllFields = () => {
} }
}; };
const fetchCurrentCalendarDisplayNameSuccess = (displayName) => { export const fetchCurrentCalendarDisplayNameSuccess = (displayName) => {
return {type: FETCH_DISPLAYNAME_SUCCESS, displayName} return {type: FETCH_DISPLAYNAME_SUCCESS, displayName}
} }
......
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
ACTIVATE_CREATE_COPY_TASKS_MODE, ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE, DEACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS, SORT_TASKS,
FETCH_WEEK_DATA_START_FAILURE,
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
...@@ -156,6 +157,8 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -156,6 +157,8 @@ const tasksReduсer = (state = initialState, action) => {
return { ...state, copyMode: { working: true, task: action.task } } return { ...state, copyMode: { working: true, task: action.task } }
case DEACTIVATE_CREATE_COPY_TASKS_MODE: case DEACTIVATE_CREATE_COPY_TASKS_MODE:
return { ...state, copyMode: { working: false, task: null } } return { ...state, copyMode: { working: false, task: null } }
case FETCH_WEEK_DATA_START_FAILURE:
return { ...state, loading: false, error: action.error };
case SORT_TASKS: case SORT_TASKS:
let filteredTasks = [] let filteredTasks = []
if (action.activeTasksOn) { if (action.activeTasksOn) {
......
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