Commit 155ca9ab authored by Ermolaev Timur's avatar Ermolaev Timur

#30 Сделал добавление локальной задачи при клике на пустую клетку

parent 9cfd0a0e
import { Grid } from "@mui/material"; import { Grid, TextField } from "@mui/material";
import { useEffect, useState } from "react";
const CalendarStandartCell = ({children, xs, onClick}) => { const CalendarStandartCell = ({children, xs, onClick, currentTask, hours, dayNumber, createTaskInCellHandler, handleOpen, modal}) => {
const [isThisCell, setIsThisCell] = useState(false)
useEffect(()=>{
if(!modal) {
setIsThisCell(false);
}
}, [modal])
return <> return <>
<Grid <Grid
item xs={xs} item xs={xs}
sx={{borderRight: '1px solid black'}} sx={{borderRight: '1px solid black'}}
onClick={onClick}> onClick={(e)=>{createTaskInCellHandler(dayNumber, hours); setIsThisCell(true); handleOpen(e)}}>
{children} {children}
{isThisCell ?
<Grid
sx={{backgroundColor: 'lightgreen'}}
>
<span>
{currentTask.title}
</span>
</Grid> : null}
</Grid> </Grid>
</> </>
}; };
......
...@@ -2,8 +2,6 @@ import { Grid, TextField } from "@mui/material"; ...@@ -2,8 +2,6 @@ import { Grid, TextField } from "@mui/material";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, hourFormat, handleOpen}) => { const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, hourFormat, handleOpen}) => {
const getTaskInDayCell = (tasks, day, hours) => { const getTaskInDayCell = (tasks, day, hours) => {
const hour = parseInt(hours.split(':')[0]) const hour = parseInt(hours.split(':')[0])
let hourDiffEnd let hourDiffEnd
...@@ -27,7 +25,6 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, ...@@ -27,7 +25,6 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange,
}) })
return tasksCell return tasksCell
} }
const tasksCell = getTaskInDayCell(tasks, day, hours) const tasksCell = getTaskInDayCell(tasks, day, hours)
return (<> return (<>
...@@ -48,8 +45,8 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, ...@@ -48,8 +45,8 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange,
</TextField> </TextField>
</Grid> </Grid>
)} )}
) : null } )
: null}
</>) </>)
}; };
......
import { FormControl, FormControlLabel, InputLabel, MenuItem, Select, Switch, TextField } from "@mui/material"; import { Button, FormControl, FormControlLabel, InputLabel, MenuItem, Select, Switch, TextField } from "@mui/material";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import CalendarRow from "./CalendarRow/CalendarRow"; import CalendarRow from "./CalendarRow/CalendarRow";
import CalendarSmallCell from "./CalendarSmallCell/CalendarSmallCell"; import CalendarSmallCell from "./CalendarSmallCell/CalendarSmallCell";
import CalendarStandartCell from "./CalendarStandartCell.js/CalendarStandartCell"; import CalendarStandartCell from "./CalendarStandartCell.js/CalendarStandartCell";
import CalendarTask from "./CalendarTask/CalendarTask"; import CalendarTask from "./CalendarTask/CalendarTask";
import ModalTask from "../UI/ModalTask/ModalTask"; import ModalTask from "../UI/ModalTask/ModalTask";
import { TextFieldsRounded } from "@mui/icons-material";
function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, setCurrentTask, hourFormat, setHourFormat}) { function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler}) {
const [hoursInDay, setHoursInDay] = useState(['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00']) const [hoursInDay, setHoursInDay] = useState(['8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00'])
const [daysInMonth, setDaysInMonth] = useState([]) const [daysInMonth, setDaysInMonth] = useState([])
const [cellSizes, setCellSizes] = useState({}) const [cellSizes, setCellSizes] = useState({})
const [modal, setModal] = useState({open:false, y: 0, x: 0,}); const [modal, setModal] = useState({open:false, y: 0, x: 0,});
const handleOpen = (e) => { const handleOpen = (e) => {
console.log(e.nativeEvent.offsetX) setModal( {
setModal( {...modal,
open: true, open: true,
yPage: e.pageY, yPage: e.pageY,
xPage: e.pageX, xPage: e.pageX,
...@@ -25,7 +23,9 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -25,7 +23,9 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
xDiv: e.target.offsetWidth, xDiv: e.target.offsetWidth,
}) })
}; };
const handleClose = () => setModal({...modal, open: false}); const handleClose = () => {
setModal({...modal, open: false})
};
useEffect(()=>{ useEffect(()=>{
...@@ -112,7 +112,12 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -112,7 +112,12 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
<CalendarStandartCell <CalendarStandartCell
key={i} key={i}
item xs={cellSizes.standarCell} item xs={cellSizes.standarCell}
onClick={()=>{createTaskInCellHandler(day.dayNumber, hours)}} createTaskInCellHandler={createTaskInCellHandler}
hours={hours}
dayNumber={day.dayNumber}
currentTask={currentTask}
handleOpen={handleOpen}
modal={modal.open}
> >
<CalendarTask <CalendarTask
setCurrentTask={setCurrentTask} setCurrentTask={setCurrentTask}
...@@ -135,22 +140,48 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -135,22 +140,48 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
modal={modal} modal={modal}
handleClose={()=>{handleClose()}} handleClose={()=>{handleClose()}}
> >
<TextField id="outlined-basic" label="title" variant="standard" sx={{marginBottom: '30px'}}/> <TextField
<TextField id="outlined-basic" label="desctiption" variant="standard" sx={{marginBottom: '30px'}} /> id="task-description-title"
<FormControl variant="standard" sx={{width: '120px'}}> value={currentTask.title}
label="Название"
variant="outlined"
sx={{marginBottom: '30px'}}
name='title'
onChange={(e)=>{onChangeCurrentTaskHandler(e)}}
/>
<TextField
id="task-description"
multiline
rows={4}
value={currentTask.description}
label="Описание"
variant="outlined"
sx={{marginBottom: '30px'}}
name='description'
onChange={(e)=>{onChangeCurrentTaskHandler(e)}}
/>
<FormControl variant="outlined" sx={{width: '160px', marginBottom: '30px'}}>
<InputLabel id="calendar-type-label">Приоритет</InputLabel> <InputLabel id="calendar-type-label">Приоритет</InputLabel>
<Select <Select
variant="standard"
labelId="calendar-type-label" labelId="calendar-type-label"
id="calendar-type" id="calendar-type"
onChange={()=>{}} onChange={()=>{}}
label="Type" label="Приоритет"
sx={{width: '160px'}}
value={currentTask.priority}
name='priority'
// onChange={(e)=>{onChangeCurrentTaskHandler(e)}}
> >
<MenuItem value="">
<em>-- Выберите Приоритет --</em>
</MenuItem>
<MenuItem value={"C"}>C</MenuItem> <MenuItem value={"C"}>C</MenuItem>
<MenuItem value={"B"}>B</MenuItem> <MenuItem value={"B"}>B</MenuItem>
<MenuItem value={"A"}>A</MenuItem> <MenuItem value={"A"}>A</MenuItem>
</Select> </Select>
</FormControl> </FormControl>
<Button sx={{marginRight: '40px'}}>Сохранить</Button>
<Button>Удалить</Button>
</ModalTask> </ModalTask>
</> </>
); );
......
...@@ -9,14 +9,14 @@ export default function ModalTask({modal, handleClose, children}) { ...@@ -9,14 +9,14 @@ export default function ModalTask({modal, handleClose, children}) {
top: modal.yPage - modal.yDiv - modal.yDivClick, top: modal.yPage - modal.yDiv - modal.yDivClick,
left: modal.xPage + modal.xDiv - modal.xDivClick + 10, left: modal.xPage + modal.xDiv - modal.xDivClick + 10,
width: 250, width: 250,
height: 300, height: 350,
bgcolor: 'background.paper', bgcolor: 'background.paper',
border: '2px solid #000', border: '2px solid #000',
boxShadow: 24, boxShadow: 24,
p: 4, p: 4,
}; };
return ( return (
<div> <>
<Modal <Modal
open={modal.open} open={modal.open}
onClose={handleClose} onClose={handleClose}
...@@ -28,6 +28,6 @@ export default function ModalTask({modal, handleClose, children}) { ...@@ -28,6 +28,6 @@ export default function ModalTask({modal, handleClose, children}) {
{children} {children}
</Box> </Box>
</Modal> </Modal>
</div> </>
); );
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ function MonthCalendar() { ...@@ -14,7 +14,7 @@ function MonthCalendar() {
const [year, setYear] = useState('') const [year, setYear] = useState('')
const [worker, setWorker] = useState(''); const [worker, setWorker] = useState('');
const [calendarType, setCalendarType] = useState('Месяц'); const [calendarType, setCalendarType] = useState('Месяц');
const [currentTask, setCurrentTask] = useState({}) const [currentTask, setCurrentTask] = useState({title: '', description: '', priority: ''})
useEffect(()=>{ useEffect(()=>{
setMonth(new Date().getMonth()) setMonth(new Date().getMonth())
...@@ -62,6 +62,16 @@ function MonthCalendar() { ...@@ -62,6 +62,16 @@ function MonthCalendar() {
return iso; return iso;
} }
const onChangeCurrentTaskHandler = (e) => {
const {name, value} = e.target;
setCurrentTask((prevState) => {
return {
...prevState,
[name]: value
}
});
};
const createTaskInCellHandler = (dayNumber, dayHour) => { const createTaskInCellHandler = (dayNumber, dayHour) => {
const hour = parseInt(dayHour.split(':')[0]) const hour = parseInt(dayHour.split(':')[0])
let hourDue let hourDue
...@@ -73,11 +83,11 @@ function MonthCalendar() { ...@@ -73,11 +83,11 @@ function MonthCalendar() {
const newTask = { const newTask = {
title:"Задача", title:"Задача",
description:"описание", description:"описание",
priority: "C",
dateTimeStart: dateToISOLikeButLocal(new Date(year, month, dayNumber, hour, 0)), dateTimeStart: dateToISOLikeButLocal(new Date(year, month, dayNumber, hour, 0)),
dateTimeDue: dateToISOLikeButLocal(new Date(year, month, dayNumber, hourDue, 59)), dateTimeDue: dateToISOLikeButLocal(new Date(year, month, dayNumber, hourDue, 59)),
} }
console.log(newTask) // dispatch(addTask(newTask))
dispatch(addTask(newTask))
setCurrentTask((newTask)) setCurrentTask((newTask))
} }
...@@ -90,7 +100,6 @@ function MonthCalendar() { ...@@ -90,7 +100,6 @@ function MonthCalendar() {
return ( return (
<> <>
<Container>
<MonthCalendarHeader <MonthCalendarHeader
month={month} month={month}
year={year} year={year}
...@@ -111,8 +120,9 @@ function MonthCalendar() { ...@@ -111,8 +120,9 @@ function MonthCalendar() {
setCurrentTask={setCurrentTask} setCurrentTask={setCurrentTask}
hourFormat={hourFormat} hourFormat={hourFormat}
setHourFormat={setHourFormat} setHourFormat={setHourFormat}
currentTask={currentTask}
onChangeCurrentTaskHandler={onChangeCurrentTaskHandler}
/> />
</Container>
</> </>
); );
} }
......
...@@ -56,7 +56,7 @@ const Register = () => { ...@@ -56,7 +56,7 @@ const Register = () => {
} }
}); });
}; };
console.log(state)
const submitHandler = async (e) => { const submitHandler = async (e) => {
e.preventDefault(); e.preventDefault();
const formData = new FormData(); const formData = new FormData();
......
...@@ -44,7 +44,7 @@ export const addTask = (task) => { ...@@ -44,7 +44,7 @@ export const addTask = (task) => {
try { try {
await axios.post("/tasks", task, { await axios.post("/tasks", task, {
headers: { headers: {
'Authorization': '5uJ4ub517ba9IReG6ltFR' 'Authorization': 'IwGVRaksGTWtnKlOZd7zJ'
} }
}); });
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
......
...@@ -3,7 +3,7 @@ import { FETCH_TASKS_FAILURE, FETCH_TASKS_REQUEST, FETCH_TASKS_SUCCESS} from ".. ...@@ -3,7 +3,7 @@ import { FETCH_TASKS_FAILURE, FETCH_TASKS_REQUEST, FETCH_TASKS_SUCCESS} from "..
const initialState = { const initialState = {
tasks: [], tasks: [],
loading: false, loading: false,
error: null error: null,
}; };
const tasksReduсer = (state = initialState, action) => { const tasksReduсer = (state = initialState, action) => {
...@@ -14,7 +14,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -14,7 +14,7 @@ const tasksReduсer = (state = initialState, action) => {
const newArr = [] const newArr = []
action.tasks.forEach((task)=>{ action.tasks.forEach((task)=>{
if (task.dateTimeStart && task.dateTimeDue) { if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (4 * 3600000)) { if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (10 * 3600000)) {
const dateStart = task.dateTimeStart.split('T')[0] const dateStart = task.dateTimeStart.split('T')[0]
const timeStart = task.dateTimeStart.split('T')[1] const timeStart = task.dateTimeStart.split('T')[1]
const timeEnd = task.dateTimeDue.split('T')[1] const timeEnd = task.dateTimeDue.split('T')[1]
......
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