Commit 53b62eba authored by Ermolaev Timur's avatar Ermolaev Timur

#30 Реализовал оторажение модального окна рядом с задачей

parent bd90d3e8
import { Grid, TextField } from "@mui/material"; 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}) => { 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
let hourDiffStart
if (hourFormat) { if (hourFormat) {
hourDiffEnd = hour + 1 hourDiffEnd = hour + 1
} else { } else {
hourDiffEnd = hour + 2 hourDiffEnd = hour + 2
} }
if (hourFormat) {
hourDiffStart = hour - 1
} else {
hourDiffStart = hour - 2
}
const tasksCell = tasks.filter(task=> { const tasksCell = tasks.filter(task=> {
if (year === task.infoForCell.startYear) { if (year === task.infoForCell.startYear) {
if (month + 1 === task.infoForCell.startMonth) { if (month + 1 === task.infoForCell.startMonth) {
...@@ -39,17 +34,22 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange, ...@@ -39,17 +34,22 @@ const CalendarTask = ({year, month, tasks, day, hours, setCurrentTask, onChange,
{tasksCell.length ? tasksCell.map((task, i)=> {tasksCell.length ? tasksCell.map((task, i)=>
{ {
return ( return (
<Grid key={task.id} sx={{backgroundColor: 'lightgreen'}}> <Grid
<TextField key={task.id}
id={task.title} sx={{backgroundColor: 'lightgreen'}}
variant="standard" onClick={(e)=>{e.stopPropagation(); setCurrentTask(task); handleOpen(e)}}
value={task.title} >
name='title' <TextField
onClick={(e)=>{e.stopPropagation(); setCurrentTask(task)}} id={task.title}
onChange={onChange}> variant="standard"
</TextField> value={task.title}
</Grid>)} name='title'
onChange={onChange}>
</TextField>
</Grid>
)}
) : null } ) : null }
</>) </>)
}; };
......
...@@ -4,12 +4,29 @@ import CalendarRow from "./CalendarRow/CalendarRow"; ...@@ -4,12 +4,29 @@ 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";
function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, setCurrentTask, hourFormat, setHourFormat}) { function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChangeCellTaskTitle, setCurrentTask, hourFormat, setHourFormat}) {
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 handleOpen = (e) => {
console.log(e.nativeEvent.offsetX)
setModal( {...modal,
open: true,
yPage: e.pageY,
xPage: e.pageX,
yDivClick: e.nativeEvent.offsetY,
xDivClick: e.nativeEvent.offsetX,
yDiv: e.target.offsetHeight,
xDiv: e.target.offsetWidth,
})
};
const handleClose = () => setModal({...modal, open: false});
useEffect(()=>{ useEffect(()=>{
const cells = hoursInDay.length const cells = hoursInDay.length
const xs = 10.8/cells const xs = 10.8/cells
...@@ -105,13 +122,18 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang ...@@ -105,13 +122,18 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, onChang
day={day} day={day}
hours={hours} hours={hours}
hourFormat={hourFormat} hourFormat={hourFormat}
/> handleOpen={handleOpen}
/>
</CalendarStandartCell> </CalendarStandartCell>
) )
})} })}
</CalendarRow> </CalendarRow>
) )
})} })}
<ModalTask
modal={modal}
handleClose={()=>{handleClose()}}
/>
</> </>
); );
} }
......
import Box from '@mui/material/Box';
import Modal from '@mui/material/Modal';
export default function ModalTask({modal, handleClose, children}) {
const style = {
position: 'absolute',
top: modal.yPage - modal.yDiv - modal.yDivClick,
left: modal.xPage + modal.xDiv - modal.xDivClick + 10,
width: 250,
height: 300,
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};
return (
<div>
<Modal
open={modal.open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
BackdropProps={{ style: { backgroundColor: 'rgba(255,255,255, 0)' } }}
>
<Box sx={style}>
{children}
</Box>
</Modal>
</div>
);
}
\ No newline at end of file
...@@ -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': 'yjBjcPCQwytwrYo9rRuiK' 'Authorization': '5uJ4ub517ba9IReG6ltFR'
} }
}); });
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
......
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