Skip to content

Commit

Permalink
Merge b08a08a into 60c0083
Browse files Browse the repository at this point in the history
  • Loading branch information
kumsil1006 authored Dec 15, 2022
2 parents 60c0083 + b08a08a commit 1c1c859
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
28 changes: 12 additions & 16 deletions client/src/hooks/useModalComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toast } from 'react-toastify';
import { InputTodo } from '@todo/todo.type';
import { TodoList } from '@todo/todoList';

import { elapsedTimeAtom, todoList } from '@util/GlobalState';
import { asyncActiveTodo, elapsedTimeAtom, todoList } from '@util/GlobalState';
import { getCheckedInputData } from '@util/modal.util';

import 'react-toastify/dist/ReactToastify.css';
Expand All @@ -27,30 +27,26 @@ const COMPLETE_MESSAGE = {
const useModalComplete = (type: string): any[] => {
const [todoListAtom, setTodoListAtom] = useAtom(todoList);
const elapsedTime = useAtomValue(elapsedTimeAtom);
const activeTodo = useAtomValue(asyncActiveTodo);

const setComplete = async (
inputData: any[],
setHasModal: Dispatch<SetStateAction<boolean>>,
editingTodoId: string,
): Promise<void> => {
todoListAtom
.updateElapsedTime(elapsedTime)
.then((newTodoList) => {
return newTodoList;
})
.then(async (newTodoList) => {
return await MODAL_COMPLETE_ACTIONS[type as keyof typeof MODAL_COMPLETE_ACTIONS](
newTodoList,
getCheckedInputData(type, inputData),
editingTodoId,
);
})
.then((data) => {
setTodoListAtom(data);
const newTodoList = activeTodo !== undefined ? await todoListAtom.updateElapsedTime(elapsedTime) : todoListAtom;

MODAL_COMPLETE_ACTIONS[type as keyof typeof MODAL_COMPLETE_ACTIONS](
newTodoList,
getCheckedInputData(type, inputData),
editingTodoId,
)
.then((updatedTodoList) => {
setTodoListAtom(updatedTodoList);
setHasModal(false);
toast.success(COMPLETE_MESSAGE[type as keyof typeof COMPLETE_MESSAGE]);
})
.catch((err: any) => {
.catch((err) => {
toast.error(err.message);
});
};
Expand Down
4 changes: 2 additions & 2 deletions client/src/util/modal.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ interface ModalValues {
const MODAL_CREATE = 'create';

interface CheckedInputData {
newData: any;
prev: string[];
next: string[];
}

export const getCheckedInputData = (type: string, inputData: ModalValues[]): CheckedInputData => {
let newData = {};
const prevTodoIdList: string[] = [];
Expand Down Expand Up @@ -78,5 +78,5 @@ export const getCheckedInputData = (type: string, inputData: ModalValues[]): Che
newData = { ...newData, [id]: value };
});

return { newData, prev: prevTodoIdList, next: nextTodoIdList };
return { ...newData, prev: prevTodoIdList, next: nextTodoIdList };
};

0 comments on commit 1c1c859

Please sign in to comment.