настроила Датапикеры на редактируемый и нередактируемый режим, доработала…

настроила Датапикеры на редактируемый и нередактируемый режим, доработала функции второго датапикера
parent 0e93993f
...@@ -11,12 +11,14 @@ export default function MaterialUIPickers(props) { ...@@ -11,12 +11,14 @@ export default function MaterialUIPickers(props) {
console.log(props) console.log(props)
if (props.task.dateTimeStart!==undefined)
return ( return (
<LocalizationProvider dateAdapter={AdapterMoment}> <LocalizationProvider dateAdapter={AdapterMoment} sx={{ width: "auto", fontSize:"9px",fontWeight: "200" }}>
<DateTimePicker <DateTimePicker
readOnly={props.readOnly}
renderInput={(params) => ( renderInput={(params) => (
<TextField {...params} name="dateCreated" /> <TextField {...params}
sx={{ width: "auto",fontWeight: "200",fontSize: '9 px' }}
name="dateCreated" />
)} )}
value={ value={
props.newStartedDate && props.newStartedDate.id === props.task.id? props.newStartedDate.date props.newStartedDate && props.newStartedDate.id === props.task.id? props.newStartedDate.date
...@@ -32,25 +34,4 @@ if (props.task.dateTimeStart!==undefined) ...@@ -32,25 +34,4 @@ if (props.task.dateTimeStart!==undefined)
</LocalizationProvider> </LocalizationProvider>
); );
else if(props.task.dateTimeDue!==undefined) {
return (
<LocalizationProvider dateAdapter={AdapterMoment}>
<DateTimePicker
renderInput={(params) => (
<TextField {...params} name="dateCreated" />
)}
value={
props.newDueDate && props.newDueDate.id === props.task.id? props.newDueDate.date
: props.task.dateTimeDue
}
onChange={(newValue) => {
props.setNewDueDate({
id: props.task.id,
date: newValue,
});
}}
/>
</LocalizationProvider>
);
}
} }
\ No newline at end of file
import * as React from 'react';
import TextField from '@mui/material/TextField';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
import { useState, useEffect } from "react";
import dayjs from 'dayjs';
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
export default function MaterialUIPickersDue(props) {
console.log(props)
return (
<LocalizationProvider dateAdapter={AdapterMoment}>
<DateTimePicker
readOnly={props.readOnly}
renderInput={(params) => (
<TextField {...params} name="dateCreated" />
)}
value={
props.newDueDate && props.newDueDate.id === props.task.id? props.newDueDate.date
: props.task.dateTimeDue
}
onChange={(newValue) => {
props.setNewDueDate({
id: props.task.id,
date: newValue,
});
}}
/>
</LocalizationProvider>
);
}
\ No newline at end of file
...@@ -26,13 +26,13 @@ import moment from "moment"; ...@@ -26,13 +26,13 @@ import moment from "moment";
import MyTaskToolBar from '../../components/MyTasksCompoments/MyTaskToolBar'; import MyTaskToolBar from '../../components/MyTasksCompoments/MyTaskToolBar';
import CustomTableCell from "../../components/MyTasksCompoments/CustomTableCell"; import CustomTableCell from "../../components/MyTasksCompoments/CustomTableCell";
import MaterialUIPickers from "../../components/UI/DateTimePicker/DateTimePicker"; import MaterialUIPickers from "../../components/UI/DateTimePicker/DateTimePicker";
import MaterialUIPickersDue from "../../components/UI/DateTimePicker/DateTimePickerDue";
function descendingComparator(a, b, orderBy) { function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) { if (b[orderBy] < a[orderBy]) {
return -1; return -1;
} }
if (b[orderBy] > a[orderBy]) { if (b[orderBy] > a[orderBy]) {
return 1;
} }
return 0; return 0;
} }
...@@ -65,6 +65,7 @@ export default function EnhancedTable() { ...@@ -65,6 +65,7 @@ export default function EnhancedTable() {
const [rowsPerPage, setRowsPerPage] = React.useState(5); const [rowsPerPage, setRowsPerPage] = React.useState(5);
const [newStartedDate, setNewStartedDate] = React.useState(); const [newStartedDate, setNewStartedDate] = React.useState();
const [newDueDate, setNewDueDate] = React.useState(); const [newDueDate, setNewDueDate] = React.useState();
const [readOnly, setReadOnly]=React.useState(true);
const handleChange = (id, newDate) => { const handleChange = (id, newDate) => {
setNewStartedDate({ id: id, date: newDate }); setNewStartedDate({ id: id, date: newDate });
...@@ -113,22 +114,22 @@ export default function EnhancedTable() { ...@@ -113,22 +114,22 @@ export default function EnhancedTable() {
useEffect(() => { useEffect(() => {
if (newStartedDate) { if (newStartedDate) {
let updatedTasks = [...tasks].filter((t) => t.id !== newStartedDate.id); let updatedTasks = [...tasks].filter((t) => t.id !== newStartedDate.id);
const currentTask = tasks.find((t) => t.id === newStartedDate.id); const currentTask = tasks.find((t) => t.id === newStartedDate.id);
delete currentTask.dateTimeStart; delete currentTask.dateTimeStart;
console.log(newStartedDate.date)
const updatedTask = { const updatedTask = {
...currentTask, ...currentTask,
dateTimeStart: moment.parseZone(newStartedDate.date, 'DD/MM/YYYY', true).format() dateTimeStart: moment.parseZone(newStartedDate.date, 'DD/MM/YYYY', true).format(),
};
};
updatedTasks.push(updatedTask); updatedTasks.push(updatedTask);
setTasks(updatedTasks); setTasks(updatedTasks);
} }
else if (newDueDate){ }, [newStartedDate]);
useEffect(() => {
if (newDueDate) {
let updatedTasks = [...tasks].filter((t) => t.id !== newDueDate.id); let updatedTasks = [...tasks].filter((t) => t.id !== newDueDate.id);
const currentTask = tasks.find((t) => t.id === newDueDate.id); const currentTask = tasks.find((t) => t.id === newDueDate.id);
delete currentTask.dateTimeDue; delete currentTask.dateTimeDue;
...@@ -136,17 +137,14 @@ export default function EnhancedTable() { ...@@ -136,17 +137,14 @@ export default function EnhancedTable() {
const updatedTask = { const updatedTask = {
...currentTask, ...currentTask,
dateTimeDue: moment.parseZone(newDueDate.date, 'DD/MM/YYYY', true).format() dateTimeDue: moment.parseZone(newDueDate.date, 'DD/MM/YYYY', true).format()
}; };
updatedTasks.push(updatedTask); updatedTasks.push(updatedTask);
setTasks(updatedTasks); setTasks(updatedTasks);
} }
}, [newStartedDate || newDueDate]); }, [newDueDate]);
const onToggleEditMode = id => { const onToggleEditMode = id => {
if (readOnly==true) {setReadOnly(false)} else {setReadOnly(true)}
setTasks(state => { setTasks(state => {
return tasks.map(task => { return tasks.map(task => {
if (task.id === id) { if (task.id === id) {
...@@ -268,27 +266,25 @@ export default function EnhancedTable() { ...@@ -268,27 +266,25 @@ export default function EnhancedTable() {
<CustomTableCell {...{ task, name: "title", onChange, onModalOpen}} /> <CustomTableCell {...{ task, name: "title", onChange, onModalOpen}} />
<CustomTableCell {...{ task, name: "author", onChange }} /> <CustomTableCell {...{ task, name: "author", onChange }} />
{task.isEditMode ? (
<TableCell key={task.id}> <TableCell key={task.id} >
<MaterialUIPickers <MaterialUIPickers
newStartedDate={newStartedDate} newStartedDate={newStartedDate}
task={task} task={task}
setNewStartedDate={setNewStartedDate} setNewStartedDate={setNewStartedDate}
readOnly={readOnly}
/> />
</TableCell>) </TableCell>
: <CustomTableCell {...{ task, name: "dateTimeStart", onChange}} />
}
{task.isEditMode ? (
<TableCell key={task.id}> <TableCell key={task.id}>
<MaterialUIPickers <MaterialUIPickersDue
newDueDate={newDueDate} newDueDate={newDueDate}
task={task} task={task}
setNewDueDate={setNewDueDate} setNewDueDate={setNewDueDate}
readOnly={readOnly}
/> />
</TableCell>) </TableCell>
: <CustomTableCell {...{ task, name: "dateTimeDue", onChange}} />
}
<CustomTableCell {...{ task, name: "done", onChange }} /> <CustomTableCell {...{ task, name: "done", onChange }} />
......
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