prettier fixed

This commit is contained in:
MaxOvs19 2023-06-22 14:56:31 +03:00
parent 9bc60434cc
commit 5ab7e65905
5 changed files with 228 additions and 185 deletions

View File

@ -1,13 +1,10 @@
import React from "react";
import "./basebutton.scss"
import "./basebutton.scss";
export const BaseButton = ({ children, styles, ...props }) => {
return (
<button
className={styles ? `${styles} button` : "button"}
{...props}
>
<button className={styles ? `${styles} button` : "button"} {...props}>
{children}
</button>
);

View File

@ -1,24 +1,23 @@
import React, {useEffect, useState} from "react";
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { apiRequest } from "../../../api/request";
import { urlForLocal } from '../../../utils/helper'
import arrowDown from "../../../assets/icons/arrows/selectArrow.png";
import {
setColumnName,
setColumnPriority,
addPersonToProject,
editColumnName,
editProjectName,
getColumnId,
getColumnName,
getColumnPriority,
getProjectBoard,
getValueModalType,
setColumnName,
setColumnPriority,
setProject,
setProjectBoardFetch,
editProjectName,
editColumnName,
getColumnName,
getColumnId,
addPersonToProject, getColumnPriority
} from "../../../redux/projectsTrackerSlice";
import arrowDown from "../../../assets/icons/arrows/selectArrow.png"
import { urlForLocal } from "../../../utils/helper";
import "./trackerModal.scss";
export const TrackerModal = ({
@ -33,8 +32,8 @@ export const TrackerModal = ({
const dispatch = useDispatch();
const projectBoard = useSelector(getProjectBoard);
const columnName = useSelector(getColumnName);
const columnId = useSelector(getColumnId)
const columnPriority = useSelector(getColumnPriority)
const columnId = useSelector(getColumnId);
const columnPriority = useSelector(getColumnPriority);
const modalType = useSelector(getValueModalType);
const [projectName, setProjectName] = useState(defautlInput);
@ -42,9 +41,9 @@ export const TrackerModal = ({
const [nameProject, setNameProject] = useState("");
const [valueTiket, setValueTiket] = useState("");
const [descriptionTicket, setDescriptionTicket] = useState("");
const [workers, setWorkers] = useState([])
const [selectWorkersOpen, setSelectWorkersOpen] = useState(false)
const [selectedWorker, setSelectedWorker] = useState(null)
const [workers, setWorkers] = useState([]);
const [selectWorkersOpen, setSelectWorkersOpen] = useState(false);
const [selectedWorker, setSelectedWorker] = useState(null);
function createTab() {
if (!valueColumn) {
@ -55,7 +54,9 @@ export const TrackerModal = ({
method: "POST",
data: {
project_id: projectBoard.id,
priority: projectBoard.columns.length ? projectBoard.columns.at(-1).priority + 1 : 1,
priority: projectBoard.columns.length
? projectBoard.columns.at(-1).priority + 1
: 1,
title: valueColumn,
},
}).then(() => {
@ -106,36 +107,38 @@ export const TrackerModal = ({
function changeColumnParams() {
projectBoard.columns.forEach((column) => {
if (column.id === columnId && column.priority !== columnPriority) {
const priorityColumns = [{
const priorityColumns = [
{
column_id: column.id,
priority: Number(columnPriority)
}]
priority: Number(columnPriority),
},
];
for (let i = column.priority; i < columnPriority; i++) {
const currentColumn = {
column_id: projectBoard.columns[i].id,
priority: i
}
priorityColumns.push(currentColumn)
priority: i,
};
priorityColumns.push(currentColumn);
}
for (let i = column.priority; i > columnPriority; i--) {
const currentColumn = {
column_id: projectBoard.columns[i - 2].id,
priority: i
}
priorityColumns.push(currentColumn)
priority: i,
};
priorityColumns.push(currentColumn);
}
apiRequest("/project-column/set-priority", {
method: "POST",
data: {
project_id: projectBoard.id,
data: JSON.stringify(priorityColumns)
}
data: JSON.stringify(priorityColumns),
},
}).then(() => {
dispatch(setProjectBoardFetch(projectBoard.id));
})
});
}
})
changeColumnTitle()
});
changeColumnTitle();
}
function changeColumnTitle() {
@ -377,9 +380,9 @@ export const TrackerModal = ({
<div className="input-container">
<input
className="name-project"
placeholder='Приоритет колонки'
type='number'
step='1'
placeholder="Приоритет колонки"
type="number"
step="1"
value={columnPriority}
onChange={(e) => dispatch(setColumnPriority(e.target.value))}
/>

View File

@ -1,34 +1,34 @@
import React, { useState } from "react";
import TrackerTaskSubComment from "../TrackerTaskComment/TrackerTaskComment";
import { apiRequest } from "../../api/request";
import {urlForLocal} from '../../utils/helper';
import {getCorrectDate} from "../Calendar/calendarHelper";
import edit from "../../assets/icons/edit.svg";
import del from "../../assets/icons/delete.svg";
import edit from "../../assets/icons/edit.svg";
import accept from "../../assets/images/accept.png";
import { urlForLocal } from "../../utils/helper";
import { getCorrectDate } from "../Calendar/calendarHelper";
import TrackerTaskSubComment from "../TrackerTaskComment/TrackerTaskComment";
export const TrackerTaskComment = ({
taskId,
comment,
commentDelete,
addSubComment,
subCommentDelete
subCommentDelete,
}) => {
const [commentsEditOpen, setCommentsEditOpen] = useState(false)
const [commentsEditText, setCommentsEditText] = useState(comment.text)
const [subCommentsCreateOpen, setSubCommentsCreateOpen] = useState(false)
const [subCommentsCreateText, setSubCommentsCreateText] = useState('')
const [commentsEditOpen, setCommentsEditOpen] = useState(false);
const [commentsEditText, setCommentsEditText] = useState(comment.text);
const [subCommentsCreateOpen, setSubCommentsCreateOpen] = useState(false);
const [subCommentsCreateText, setSubCommentsCreateText] = useState("");
function editComment() {
if (commentsEditText === comment.text) return
if (commentsEditText === comment.text) return;
apiRequest("/comment/update", {
method: "PUT",
data: {
comment_id: comment.id,
text: commentsEditText
}
}).then(() => {
})
text: commentsEditText,
},
}).then(() => {});
}
function deleteComment() {
@ -36,94 +36,126 @@ export const TrackerTaskComment = ({
method: "PUT",
data: {
comment_id: comment.id,
status: 0
}
status: 0,
},
}).then(() => {
if (comment.parent_id) {
subCommentDelete(comment)
subCommentDelete(comment);
} else {
commentDelete(comment)
commentDelete(comment);
}
})
});
}
function createSubComment() {
setSubCommentsCreateOpen(false)
if(!subCommentsCreateText) return
setSubCommentsCreateOpen(false);
if (!subCommentsCreateText) return;
apiRequest("/comment/create", {
method: "POST",
data: {
text: subCommentsCreateText,
entity_type: 2,
entity_id: taskId,
parent_id: comment.id
}
parent_id: comment.id,
},
}).then((res) => {
let newSubComment = res
newSubComment.created_at = new Date()
setSubCommentsCreateText('')
addSubComment(comment.id, newSubComment)
})
let newSubComment = res;
newSubComment.created_at = new Date();
setSubCommentsCreateText("");
addSubComment(comment.id, newSubComment);
});
}
return (
<div className={[!comment.parent_id && comment.subComments.length ? 'comments__list__item__main': '',
'comments__list__item',
comment.parent_id ? 'comments__list__item__subComment' : ''].join(' ')}>
<div className='comments__list__item__info'>
<div className='comments__list__item__fio'>
<img src={urlForLocal(comment.user.avatar)} alt='avatar' />
<div
className={[
!comment.parent_id && comment.subComments.length
? "comments__list__item__main"
: "",
"comments__list__item",
comment.parent_id ? "comments__list__item__subComment" : "",
].join(" ")}
>
<div className="comments__list__item__info">
<div className="comments__list__item__fio">
<img src={urlForLocal(comment.user.avatar)} alt="avatar" />
<p>{comment.user.fio}</p>
</div>
<div className='comments__list__item__date'>
<div className="comments__list__item__date">
<span>{getCorrectDate(comment.created_at)}</span>
{comment.user_id === Number(localStorage.getItem('id')) &&
{comment.user_id === Number(localStorage.getItem("id")) && (
<>
<div className={commentsEditOpen ? 'edit edit__open' : 'edit'} >
<img src={edit} alt='edit' onClick={() => {
if (commentsEditOpen) {
editComment()
}
setCommentsEditOpen(!commentsEditOpen)
}} />
</div>
<img src={del} alt='delete' onClick={() => deleteComment()} />
</>
}
</div>
</div>
{commentsEditOpen ?
<input className='comments__list__item__text' value={commentsEditText} onChange={(e) => {
setCommentsEditText(e.target.value)
}} /> :
<p className='comments__list__item__text'>{commentsEditText}</p>}
{!comment.parent_id &&
<>
{
subCommentsCreateOpen ?
<div className='comments__list__item__answer__new'>
<input value={subCommentsCreateText} onChange={(e) => {
setSubCommentsCreateText(e.target.value)
}}/>
<img src={accept} alt='accept'
<div className={commentsEditOpen ? "edit edit__open" : "edit"}>
<img
src={edit}
alt="edit"
onClick={() => {
createSubComment()
if (commentsEditOpen) {
editComment();
}
setCommentsEditOpen(!commentsEditOpen);
}}
/>
</div>
:
<span onClick={() => {
setSubCommentsCreateOpen(true)
}} className='comments__list__item__answer'>Ответить</span>
}
<img src={del} alt="delete" onClick={() => deleteComment()} />
</>
}
{Boolean(comment.subComments?.length) && comment.subComments.map((subComment) => {
return <TrackerTaskSubComment key={subComment.id} taskId={taskId} comment={subComment} subCommentDelete={subCommentDelete}/>
})
}
)}
</div>
)
}
</div>
{commentsEditOpen ? (
<input
className="comments__list__item__text"
value={commentsEditText}
onChange={(e) => {
setCommentsEditText(e.target.value);
}}
/>
) : (
<p className="comments__list__item__text">{commentsEditText}</p>
)}
{!comment.parent_id && (
<>
{subCommentsCreateOpen ? (
<div className="comments__list__item__answer__new">
<input
value={subCommentsCreateText}
onChange={(e) => {
setSubCommentsCreateText(e.target.value);
}}
/>
<img
src={accept}
alt="accept"
onClick={() => {
createSubComment();
}}
/>
</div>
) : (
<span
onClick={() => {
setSubCommentsCreateOpen(true);
}}
className="comments__list__item__answer"
>
Ответить
</span>
)}
</>
)}
{Boolean(comment.subComments?.length) &&
comment.subComments.map((subComment) => {
return (
<TrackerTaskSubComment
key={subComment.id}
taskId={taskId}
comment={subComment}
subCommentDelete={subCommentDelete}
/>
);
})}
</div>
);
};
export default TrackerTaskComment
export default TrackerTaskComment;

View File

@ -10,7 +10,7 @@ const initialState = {
boardLoader: false,
columnName: "",
columnId: 0,
columnPriority: 0
columnPriority: 0,
};
export const setProjectBoardFetch = createAsyncThunk("userInfo", (id) =>
@ -51,13 +51,16 @@ export const projectsTrackerSlice = createSlice({
moveProjectTask: (state, action) => {
state.projectBoard.columns.forEach((column, index) => {
if (column.id === action.payload.columnId) {
column.tasks.push({...action.payload.startWrapperIndex.task, column_id: column.id});
column.tasks.push({
...action.payload.startWrapperIndex.task,
column_id: column.id,
});
apiRequest(`/task/update-task`, {
method: "PUT",
data: {
task_id: action.payload.startWrapperIndex.task.id,
column_id: column.id,
priority: column.tasks.length - 1
priority: column.tasks.length - 1,
},
}).then(() => {});
}
@ -71,10 +74,15 @@ export const projectsTrackerSlice = createSlice({
movePositionProjectTask: (state, action) => {
state.projectBoard.columns.forEach((column, index) => {
if (column.id === action.payload.startTask.column_id) {
state.projectBoard.columns[index].tasks = column.tasks.filter((task) => task.id !== action.payload.startTask.id)
state.projectBoard.columns[index].tasks = column.tasks.filter(
(task) => task.id !== action.payload.startTask.id
);
}
if (column.id === action.payload.finishTask.column_id) {
column.tasks.splice(action.payload.finishIndex, 0, {...action.payload.startTask, column_id: column.id})
column.tasks.splice(action.payload.finishIndex, 0, {
...action.payload.startTask,
column_id: column.id,
});
apiRequest(`/task/update-task`, {
method: "PUT",
data: {
@ -82,14 +90,14 @@ export const projectsTrackerSlice = createSlice({
column_id: column.id,
},
}).then(() => {});
const priorityTasks = []
const priorityTasks = [];
column.tasks.forEach((task, index) => {
const curTask = {
task_id: task.id,
priority: index
}
priorityTasks.push(curTask)
})
priority: index,
};
priorityTasks.push(curTask);
});
apiRequest(`/task/set-priority`, {
method: "POST",
data: {
@ -98,17 +106,21 @@ export const projectsTrackerSlice = createSlice({
},
}).then(() => {});
}
})
});
},
filterCreatedByMe: (state, action) => {
state.projectBoard.columns.forEach((column) => {
column.tasks = column.tasks.filter((task) => task.user_id === action.payload)
})
column.tasks = column.tasks.filter(
(task) => task.user_id === action.payload
);
});
},
filteredParticipateTasks: (state, action) => {
state.projectBoard.columns.forEach((column) => {
column.tasks = column.tasks.filter((task) => task.taskUsers.some((person) => person.user_id === action.payload))
})
column.tasks = column.tasks.filter((task) =>
task.taskUsers.some((person) => person.user_id === action.payload)
);
});
},
setColumnName: (state, action) => {
state.columnName = action.payload;
@ -117,7 +129,7 @@ export const projectsTrackerSlice = createSlice({
state.columnId = action.payload;
},
setColumnPriority: (state, action) => {
state.columnPriority = action.payload
state.columnPriority = action.payload;
},
editProjectName: (state, action) => {
state.projects.forEach((project) => {
@ -162,7 +174,7 @@ export const {
addPersonToProject,
filterCreatedByMe,
filteredParticipateTasks,
movePositionProjectTask
movePositionProjectTask,
} = projectsTrackerSlice.actions;
export const getProjects = (state) => state.tracker.projects;
@ -172,6 +184,6 @@ export const getValueModalType = (state) => state.tracker.modalType;
export const getBoarderLoader = (state) => state.tracker.boardLoader;
export const getColumnName = (state) => state.tracker.columnName;
export const getColumnId = (state) => state.tracker.columnId;
export const getColumnPriority = (state) => state.tracker.columnPriority
export const getColumnPriority = (state) => state.tracker.columnPriority;
export default projectsTrackerSlice.reducer;

View File

@ -53,12 +53,11 @@ export function scrollToForm() {
}
export function getCorrectRequestDate(date) {
const yyyy = String(date.getUTCFullYear())
const yyyy = String(date.getUTCFullYear());
const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
const dd = String(date.getUTCDate()).padStart(2, "0");
const hh = String(date.getUTCHours())
const min = String(date.getUTCMinutes())
const sec = String(date.getUTCSeconds())
return `${yyyy}-${mm}-${dd} ${hh}:${min}:${sec}`
const hh = String(date.getUTCHours());
const min = String(date.getUTCMinutes());
const sec = String(date.getUTCSeconds());
return `${yyyy}-${mm}-${dd} ${hh}:${min}:${sec}`;
}