Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samarth B - lint fix reducer #3030

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ src/App.css
src/config.json

src/index.js
src/reducers/**
src/styles.js
src/__tests__/**

Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ src/config.json

src/index.js
src/languages/**
src/reducers/**
src/registerServiceWorker.js
src/routes.js
src/setupTests.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
authorizeWeeklySummaries,
authorizeWeeklySummariesReportError,
} from '../../actions/weeklySummariesReportRecepients';
import { weeklySummaryRecipientsReducer } from '../../reducers/weeklySummaryRecipientsReducer';
import weeklySummaryRecipientsReducer from '../../reducers/weeklySummaryRecipientsReducer';

export default function PasswordInputModal({
onClose,
Expand Down
3 changes: 3 additions & 0 deletions src/reducers/actionItemsReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// eslint-disable-next-line default-param-last
export const actionItemsReducer = (actionItems = null, action) => {
if (action.type === 'GET_ACTION_ITEMS') {
return action.payload;
}

return actionItems;
};

export default actionItemsReducer;
69 changes: 41 additions & 28 deletions src/reducers/allProjectsReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as types from "../constants/projects";
import * as types from '../constants/projects';

const allProjectsInital = {
fetching: false,
Expand All @@ -8,61 +8,74 @@ const allProjectsInital = {
error: null,
};

// eslint-disable-next-line default-param-last
export const allProjectsReducer = (allProjects = allProjectsInital, action) => {
const updateState = (updatedProperties) => {
return {
...allProjects,
...updatedProperties,
};
};
const updateState = updatedProperties => ({
...allProjects,
...updatedProperties,
});

const { status, error = null } = action;
let index, projects;

switch (action.type) {
case types.FETCH_PROJECTS_START:
case types.FETCH_PROJECTS_START: {
return updateState({ fetching: true });
case types.FETCH_PROJECTS_ERROR:
}

case types.FETCH_PROJECTS_ERROR: {
return updateState({ fetching: false, status, error });
case types.FETCH_PROJECTS_SUCCESS:
}

case types.FETCH_PROJECTS_SUCCESS: {
return updateState({
fetching: false,
fetched: true,
projects: action.projects,
status,
});
case types.ADD_NEW_PROJECT:
}

case types.ADD_NEW_PROJECT: {
if (status !== 201) return updateState({ status, error });
const { newProject } = action;
return updateState({
projects: [...allProjects.projects, newProject],
status,
});
case types.UPDATE_PROJECT:
}

case types.UPDATE_PROJECT: {
if (status !== 200) return updateState({ status, error });
const { updatedProject } = action;
index = allProjects.projects.findIndex(project => project._id === updatedProject._id);
const index = allProjects.projects.findIndex(project => project._id === updatedProject._id);

if (index !== -1) {
projects = [
const updatedProjects = [
...allProjects.projects.slice(0, index),
updatedProject,
...allProjects.projects.slice(index + 1),
];
return updateState({ projects, status });
}
else {
return updateState({ status:404, error: "Project not found." });
return updateState({ projects: updatedProjects, status });
}
case types.DELETE_PROJECT:

return updateState({ status: 404, error: 'Project not found.' });
}

case types.DELETE_PROJECT: {
if (status !== 200) return updateState({ status, error });
const { projectId } = action;
index = allProjects.projects.findIndex(project => project._id === projectId);
projects = Object.assign([
...allProjects.projects.slice(0, index),
...allProjects.projects.slice(index + 1),
]);
return updateState({ projects, status });
case types.CLEAR_ERROR:
const updatedProjects = allProjects.projects.filter(project => project._id !== projectId);
return updateState({ projects: updatedProjects, status });
}

case types.CLEAR_ERROR: {
return updateState({ status: 200, error: null });
default:
}

default: {
return allProjects;
}
}
};

export default allProjectsReducer;
116 changes: 68 additions & 48 deletions src/reducers/allTasksReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createOrUpdateTaskNotificationHTTP } from 'actions/taskNotification';
import { fetchTeamMembersTaskSuccess } from 'components/TeamMemberTasks/actions';
import * as types from "../constants/task";
import * as types from '../constants/task';

const allTasksInital = {
fetching: false,
Expand All @@ -15,7 +14,7 @@ const filterAndSort = (tasks, level) => {
return tasks.sort((a, b) => {
const aArr = a.num.split('.');
const bArr = b.num.split('.');
for (let i = 0; i < level; i++) {
for (let i = 0; i < level; i += 1) {
if (+aArr[i] !== +bArr[i]) return +aArr[i] - +bArr[i];
}
return 0;
Expand Down Expand Up @@ -46,58 +45,71 @@ const sortByNum = tasks => {
return filterAndSort(appendTasks, 4);
};

// eslint-disable-next-line default-param-last
export const taskReducer = (allTasks = allTasksInital, action) => {
let newTaskItems;
switch (action.type) {
case types.FETCH_TASKS_START:
case types.FETCH_TASKS_START: {
return { ...allTasks, fetched: false, fetching: true, error: 'none' };
case types.FETCH_TASKS_ERROR:
}

case types.FETCH_TASKS_ERROR: {
return { ...allTasks, fetched: true, fetching: false, error: action.err };
case types.RECEIVE_TASKS:
allTasks.fetchedData[action.level] = action.taskItems;
newTaskItems = allTasks.fetchedData.flat();
}

case types.RECEIVE_TASKS: {
const updatedFetchedData = [...allTasks.fetchedData];
updatedFetchedData[action.level] = action.taskItems;

const newTaskItems = updatedFetchedData.flat();
return {
...allTasks,
fetchedData: [...allTasks.fetchedData],
fetchedData: updatedFetchedData,
taskItems: sortByNum(newTaskItems),
fetched: true,
fetching: false,
error: 'none',
};
case types.ADD_NEW_TASK:
newTaskItems = [action.newTask, ...allTasks.taskItems];
}

case types.ADD_NEW_TASK: {
const newTaskItems = [action.newTask, ...allTasks.taskItems];
return {
...allTasks,
taskItems: sortByNum(newTaskItems),
fetched: true,
fetching: false,
error: 'none',
};
case types.DELETE_TASK:
const delIndexStart = allTasks.taskItems.findIndex(task => task._id === action.taskId);
let delIndexEnd = delIndexStart;
allTasks.taskItems.forEach((task, index) => {
if (task.parentId3 === action.taskId) {
delIndexEnd = index;
}
if (task.parentId2 === action.taskId) {
delIndexEnd = index;
}
if (task.parentId1 === action.taskId) {
delIndexEnd = index;
}

case types.DELETE_TASK: {
const startIndex = allTasks.taskItems.findIndex(task => task._id === action.taskId);
const endIndex = allTasks.taskItems.reduce((lastIndex, task, index) => {
if (
task.parentId1 === action.taskId ||
task.parentId2 === action.taskId ||
task.parentId3 === action.taskId
) {
return index;
}
});
return lastIndex;
}, startIndex);

const updatedTasks = [
...allTasks.taskItems.slice(0, startIndex),
...allTasks.taskItems.slice(endIndex + 1),
];

return {
...allTasks,
taskItems: [
...allTasks.taskItems.slice(0, delIndexStart),
...allTasks.taskItems.slice(delIndexEnd + 1),
],
taskItems: updatedTasks,
fetched: true,
fetching: false,
error: 'none',
};
case types.EMPTY_TASK_ITEMS:
}

case types.EMPTY_TASK_ITEMS: {
return {
...allTasks,
taskItems: [],
Expand All @@ -106,31 +118,39 @@ export const taskReducer = (allTasks = allTasksInital, action) => {
fetching: false,
error: 'none',
};
case types.UPDATE_TASK:
const updIndexStart = allTasks.taskItems.findIndex(task => task._id === action.taskId);
const updIndexEnd = updIndexStart;
let updatedTask = allTasks.taskItems.filter(task => task._id === action.taskId)[0];
updatedTask = { ...updatedTask, ...action.updatedTask };
}

case types.UPDATE_TASK: {
const updatedTasks = allTasks.taskItems.map(task =>
task._id === action.taskId ? { ...task, ...action.updatedTask } : task,
);

return {
...allTasks,
taskItems: [
...allTasks.taskItems.slice(0, updIndexStart),
updatedTask,
...allTasks.taskItems.slice(updIndexEnd + 1),
],
taskItems: updatedTasks,
fetched: true,
fetching: false,
error: 'none',
};
case types.COPY_TASK:
const copiedTask = allTasks.taskItems.find(item => item._id === action.taskId);
}

case types.COPY_TASK: {
const copiedTask = allTasks.taskItems.find(task => task._id === action.taskId);
return { ...allTasks, copiedTask };
case types.ADD_NEW_TASK_ERROR:
const error = action.err;
return { ...allTasks, error };
case fetchTeamMembersTaskSuccess.type:
return { ...allTasks, ...action.tasks }; // change that when there will be backend
default:
}

case types.ADD_NEW_TASK_ERROR: {
return { ...allTasks, error: action.err };
}

case fetchTeamMembersTaskSuccess.type: {
return { ...allTasks, ...action.tasks }; // Placeholder for backend integration
}

default: {
return allTasks;
}
}
};

export default taskReducer;
Loading
Loading