diff --git a/src/components/Home/HomePage.jsx b/src/components/Home/HomePage.jsx index 3795fb4..2b5e70c 100644 --- a/src/components/Home/HomePage.jsx +++ b/src/components/Home/HomePage.jsx @@ -18,7 +18,6 @@ const Home = () => { const navigate = useNavigate(); const projects = useSelector((state) => state.projects.data); const inboxProjectId = useSelector((state) => state.projects.inboxProjectId); - const tasks = useSelector((state) => state.tasks.data); const dispatch = useDispatch(); const { projectId: projectIdParam } = useParams(); const [projectModalType, setProjectModalType] = useState(null); @@ -60,24 +59,12 @@ const Home = () => { dispatch(DELETE_PROJECT(projectId)); }; - const getProjectById = (id) => { - return projects.find((project) => project.id == id); - }; - - const selectedProject = () => { - return projects.find((project) => project.id == selectedProjectId); - }; - - const tasksOfSelectedProject = () => { - return tasks.filter((task) => task.projectId == selectedProjectId); - }; - useEffect(() => { if (inboxProjectId != null && projectIdParam == undefined) { dispatch(TOGGLE_SELECTED_PROJECT(inboxProjectId)); return; } - if (projectIdParam != undefined && getProjectById(projectIdParam) != null) { + if (projectIdParam != undefined && findProjectById(projectIdParam) != null) { dispatch(TOGGLE_SELECTED_PROJECT(projectIdParam)); } }, [projectIdParam, inboxProjectId]); @@ -100,10 +87,7 @@ const Home = () => { onDeleteProjectClick={handleDeleteProjectClick} /> - + {projectModalType && ( diff --git a/src/components/LeftMenu/LeftMenu.jsx b/src/components/LeftMenu/LeftMenu.jsx index d08f4aa..6bc9935 100644 --- a/src/components/LeftMenu/LeftMenu.jsx +++ b/src/components/LeftMenu/LeftMenu.jsx @@ -223,10 +223,11 @@ const LeftMenu = ({ anchorEl={projectMenuAnchorEl} open={isProjectMenuOpen} onClose={handleProjectMenuClose} + sx={{ color: "gray" }} > handleProjectEditClick(projectMenuProjectId)}> - + Editar projeto @@ -235,7 +236,7 @@ const LeftMenu = ({ onClick={() => handleProjectDeleteClick(projectMenuProjectId)} > - + Excluir projeto diff --git a/src/components/ProjectViewer/ProjectViewer.jsx b/src/components/ProjectViewer/ProjectViewer.jsx index 330b1ad..e5c6169 100644 --- a/src/components/ProjectViewer/ProjectViewer.jsx +++ b/src/components/ProjectViewer/ProjectViewer.jsx @@ -1,53 +1,131 @@ -import { useContext } from "react"; +import { useContext, useState } from "react"; import { LeftMenuContext } from "@/providers/LeftMenuProvider"; +import { useSelector, useDispatch } from "react-redux"; import { Main } from "./styles"; -import { Typography, Divider, Box, Checkbox, Container } from "@mui/material"; +import { + MoreHoriz as MoreHorizIcon, + BorderColorOutlined as BorderColorIcon, +} from "@mui/icons-material"; +import { + Typography, + Divider, + Box, + Checkbox, + Container, + List, + ListItem, + ListItemButton, + ListItemText, + IconButton, +} from "@mui/material"; -const ProjectViewer = ({ project, tasks }) => { +const ProjectViewer = () => { const { isOpen, setIsOpen } = useContext(LeftMenuContext); + const [checked, setChecked] = useState([0]); + const [hoveredTaskId, setHoveredTaskId] = useState(null); + const dispatch = useDispatch(); + const selectedProjectId = useSelector( + (state) => state.projects.selectedProjectId + ); + const selectedProject = useSelector((state) => state.projects.data).find( + (project) => project.id == selectedProjectId + ); + const tasks = useSelector((state) => state.tasks.data).filter( + (task) => task.projectId == selectedProjectId + ); const normalizeProjectName = (projectName) => { return projectName == "Inbox" ? "Entrada" : projectName; }; - if (!project) return null; + const handleTaskCheckToggle = (taskId) => { + const currentIndex = checked.indexOf(taskId); + const newChecked = [...checked]; + if (currentIndex === -1) { + newChecked.push(taskId); + } else { + newChecked.splice(currentIndex, 1); + } + setChecked(newChecked); + }; + + const handleTaskClick = (taskId) => {}; + + const handleTaskEditClick = (taskId) => {}; + + const handleTaskOptionsClick = (taskId) => {}; + + if (!selectedProject) return null; return (
- {normalizeProjectName(project?.name)} + {normalizeProjectName(selectedProject?.name)} - {tasks.map((task) => ( - - - - - - - - Título: {task.content} - - + {tasks + .sort((a, b) => a.order > b.order) + .map((task) => ( + setHoveredTaskId(task.id)} + onMouseLeave={() => setHoveredTaskId(null)} + > + + + + + + + + + } > - Descrição: {task.description} - + handleTaskCheckToggle(task.id)} + disableRipple + /> + + + + + - - - - ))} + ))} + - {!project && Nenhum projeto selecionado} + {!selectedProject && ( + Nenhum projeto selecionado + )}
); diff --git a/src/state/slices/authSlice.js b/src/state/slices/authSlice.js index efe2044..65ca1da 100644 --- a/src/state/slices/authSlice.js +++ b/src/state/slices/authSlice.js @@ -4,8 +4,9 @@ import { tokenRequest } from "@/api/request.js"; import { clearAllParamsFromActualURL } from "@/lib/util.js"; export function* onRequestToken(action) { + const code = action.payload; try { - const response = yield call(tokenRequest, [action.payload]); + const response = yield call(tokenRequest, [code]); const token = response.data.access_token; yield localStorage.setItem("token", token); yield put(FETCH_TOKEN_SUCCESS(token)); @@ -16,13 +17,13 @@ export function* onRequestToken(action) { } export function* onReceiveToken(action) { - yield put(AUTHORIZED(action.payload)); + const token = action.payload; + yield put(AUTHORIZED(token)); } export function* onAuthorized(action) { - yield window.dispatchEvent( - new CustomEvent("new_token", { detail: action.payload }) - ); + const token = action.payload; + yield window.dispatchEvent(new CustomEvent("new_token", { detail: token })); } const initialState = { diff --git a/src/state/slices/projectsSlice.js b/src/state/slices/projectsSlice.js index 48a2533..1d610b5 100644 --- a/src/state/slices/projectsSlice.js +++ b/src/state/slices/projectsSlice.js @@ -12,8 +12,9 @@ export function* onRequestProjects() { } export function* onAddProject(action) { + const project = action.payload; try { - const response = yield call(() => getApi().addProject(action.payload)); + const response = yield call(() => getApi().addProject(project)); yield put(ADD_PROJECT_SUCCESS(response)); } catch (error) { yield put(ADD_PROJECT_ERROR()); @@ -21,18 +22,20 @@ export function* onAddProject(action) { } export function* onUpdateProject(action) { + const project = action.payload; try { - yield call(() => getApi().updateProject(action.payload.id, action.payload)); - yield put(UPDATE_PROJECT_SUCCESS(action.payload)); + yield call(() => getApi().updateProject(project.id, project)); + yield put(UPDATE_PROJECT_SUCCESS(project)); } catch (error) { yield put(UPDATE_PROJECT_ERROR()); } } export function* onDeleteProject(action) { + const projectId = action.payload; try { - yield call(() => getApi().deleteProject(action.payload)); - yield put(DELETE_PROJECT_SUCCESS(action.payload)); + yield call(() => getApi().deleteProject(projectId)); + yield put(DELETE_PROJECT_SUCCESS(projectId)); } catch (error) { yield put(DELETE_PROJECT_ERROR()); } diff --git a/src/state/slices/tasksSlice.js b/src/state/slices/tasksSlice.js index 5180365..9e38859 100644 --- a/src/state/slices/tasksSlice.js +++ b/src/state/slices/tasksSlice.js @@ -11,6 +11,16 @@ export function* onRequestTasks() { } } +export function* onCloseTasks(action) { + const taskId = action.payload; + try { + const response = yield call(() => getApi().closeTask(taskId)); + yield put(CLOSE_TASK_SUCCESS(response)); + } catch (error) { + yield put(CLOSE_TASK_ERROR()); + } +} + const initialState = { data: [], loading: false, @@ -33,9 +43,27 @@ export const tasksSlice = createSlice({ state.loading = false; state.error = true; }, + CLOSE_TASK: (state) => { + state.loading = true; + state.error = false; + }, + CLOSE_TASK_SUCCESS: (state, action) => { + state.loading = false; + //state.data = action.payload; + }, + CLOSE_TASK_ERROR: (state) => { + state.loading = false; + state.error = true; + }, }, }); -export const { FETCH_TASKS, FETCH_TASKS_SUCCESS, FETCH_TASKS_ERROR } = - tasksSlice.actions; +export const { + FETCH_TASKS, + FETCH_TASKS_SUCCESS, + FETCH_TASKS_ERROR, + CLOSE_TASK, + CLOSE_TASK_SUCCESS, + CLOSE_TASK_ERROR, +} = tasksSlice.actions; export default tasksSlice.reducer;