Skip to content

Commit 727b203

Browse files
committed
fix: Edit form button.
1 parent 9f0a76c commit 727b203

File tree

10 files changed

+89
-46
lines changed

10 files changed

+89
-46
lines changed

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"eslint-plugin-jsx-a11y": "^6.5.1",
5151
"eslint-plugin-react": "^7.28.0",
5252
"eslint-plugin-react-hooks": "^4.3.0",
53+
"jest": "^27.5.1",
5354
"postcss": "^8.4.20",
5455
"prettier-eslint": "^15.0.1",
5556
"tailwindcss": "^3.2.4",

public/manifest.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
{
22
"short_name": "React App",
33
"name": "Create React App Sample",
4-
"icons": [
5-
{
6-
"src": "favicon.ico",
7-
"sizes": "64x64 32x32 24x24 16x16",
8-
"type": "image/x-icon"
9-
},
10-
{
11-
"src": "logo192.png",
12-
"type": "image/png",
13-
"sizes": "192x192"
14-
},
15-
{
16-
"src": "logo512.png",
17-
"type": "image/png",
18-
"sizes": "512x512"
19-
}
20-
],
214
"start_url": ".",
225
"display": "standalone",
236
"theme_color": "#000000",

src/blocks/Modals/EditTask.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Props = {
88
memo: string;
99
title: string;
1010
priority: string;
11+
currentId?: string;
1112
openModal: boolean;
1213
description: string;
1314
closeModal: () => void;

src/blocks/Tasks/index.tsx

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@ import Item from '../../components/Item';
66
import TasksDetails from '../Modals/TasksDetails';
77

88
import { nanoid } from 'nanoid';
9+
import EditTask from '../Modals/EditTask';
910
import { ITodo, useTodoContext } from '../../Context/TodoProvider';
1011

1112
const Tasks = () => {
12-
const [modalopen, setModalopen] = useState(false);
13-
const [modal2open, setModal2open] = useState(false);
13+
const [createModal, setCreateModal] = useState(false);
14+
const [detailModal, setDetailModal] = useState(false);
15+
const [editFormModal, setEditFormModal] = useState(false);
16+
1417
const [currentId, setCurrentId] = useState('');
1518

16-
const { todoList, setDone, addTodo } = useTodoContext();
19+
const { todoList, setDone, addTodo, editTodo } = useTodoContext();
1720

1821
const onGoingTodos = todoList.filter(
1922
(todo) => todo.status === 'ongoing',
2023
);
2124

22-
const openEditModal = (id: string) => {
25+
const openDetailModal = (id: string) => {
2326
setCurrentId(id);
2427
setTimeout(() => {
25-
setModal2open(true);
28+
setDetailModal(true);
2629
}, 50);
2730
};
2831

@@ -35,8 +38,21 @@ const Tasks = () => {
3538
};
3639

3740
const modalClose = () => {
38-
setModalopen(false);
39-
setModal2open(false);
41+
setCreateModal(false);
42+
setDetailModal(false);
43+
setEditFormModal(false);
44+
};
45+
46+
const editForm = (id: string) => {
47+
setCurrentId(id);
48+
setEditFormModal(true);
49+
};
50+
51+
const index = todoList.findIndex((x) => x.id === currentId);
52+
53+
const onFinishEdit = (values: ITodo) => {
54+
editTodo(todoList[index].id, values);
55+
setEditFormModal(false);
4056
};
4157

4258
return (
@@ -50,8 +66,8 @@ const Tasks = () => {
5066
priority={todo.priority}
5167
description={todo.description}
5268
handleIsDone={() => setDone(todo.id)}
53-
onClick={() => openEditModal(todo.id)}
54-
handleEdit={() => openEditModal(todo.id)}
69+
onClick={() => openDetailModal(todo.id)}
70+
handleEdit={() => editForm(todo.id)}
5571
/>
5672
</div>
5773
))}
@@ -60,21 +76,33 @@ const Tasks = () => {
6076
type="primary"
6177
className="bg-blue-600 absolute bottom-4 right-4 w-10 h-10"
6278
shape="circle"
63-
onClick={() => setModalopen(true)}
79+
onClick={() => setCreateModal(true)}
6480
content="+"
6581
/>
6682

6783
<CreateTask
68-
openModal={modalopen}
84+
openModal={createModal}
6985
closeModal={modalClose}
7086
onFinish={onFinish}
7187
/>
7288

7389
<TasksDetails
7490
currentId={currentId}
75-
openModal={modal2open}
91+
openModal={detailModal}
7692
closeModal={modalClose}
7793
/>
94+
95+
{index !== -1 && (
96+
<EditTask
97+
onFinish={onFinishEdit}
98+
closeModal={modalClose}
99+
openModal={editFormModal}
100+
memo={todoList[index].memo}
101+
title={todoList[index].title}
102+
priority={todoList[index].priority}
103+
description={todoList[index].description}
104+
/>
105+
)}
78106
</>
79107
);
80108
};

src/components/Item/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ import Primary from './models/primary';
33
import Secondary from './models/secondary';
44

55
type Props = {
6-
type: 'primary' | 'secondary';
76
id: string;
87
title: string;
98
priority: string;
9+
minimized?: boolean;
1010
description: string;
1111
hasButtons?: boolean;
1212
onClick?: () => void;
1313
handleEdit: () => void;
1414
handleIsDone: () => void;
1515
handleDelete?: () => void;
16+
type: 'primary' | 'secondary';
1617
};
1718
const Item = ({
1819
type,
1920
id,
2021
title,
2122
onClick,
2223
priority,
24+
minimized,
2325
hasButtons,
2426
handleEdit,
2527
description,
@@ -33,6 +35,7 @@ const Item = ({
3335
id={id}
3436
title={title}
3537
priority={priority}
38+
minimized={minimized}
3639
handleEdit={handleEdit}
3740
description={description}
3841
handleIsDone={handleIsDone}
@@ -56,6 +59,7 @@ const Item = ({
5659

5760
Item.defaultProps = {
5861
hasButtons: true,
62+
minimized: false,
5963
onClick: () => {},
6064
handleDelete: () => {},
6165
};

src/components/Item/models/primary.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Props = {
88
title: string;
99
priority: string;
1010
description: string;
11+
minimized?: boolean;
1112
hasButtons?: boolean;
1213
onClick?: () => void;
1314
handleEdit: () => void;
@@ -19,20 +20,28 @@ const Item = ({
1920
title,
2021
onClick,
2122
priority,
23+
minimized,
2224
hasButtons,
2325
handleEdit,
2426
description,
2527
handleIsDone,
2628
}: Props) => {
2729
return (
2830
<div
29-
onClick={onClick}
30-
className="center my-4 lg:mx-20 mx-5 cursor-pointer"
31+
className={`${
32+
minimized ? 'mx-4' : 'lg:mx-[150px] mx-5'
33+
} center my-4 cursor-pointer`}
3134
>
3235
<div className="container flex justify-between items-center">
33-
<div>
36+
<div onClick={onClick}>
3437
<p className="title">{title}</p>
35-
<p className="description my-2">{description}</p>
38+
<p
39+
className={`${
40+
minimized ? 'mindecription' : 'description'
41+
} my-2`}
42+
>
43+
{description}
44+
</p>
3645
</div>
3746
<div className="flex flex-col">
3847
<p className="priority">
@@ -74,6 +83,10 @@ const Item = ({
7483
</div>
7584
);
7685
};
77-
Item.defaultProps = { hasButtons: true, onClick: () => {} };
86+
Item.defaultProps = {
87+
hasButtons: true,
88+
onClick: () => {},
89+
minimized: false,
90+
};
7891

7992
export default Item;

src/components/Item/models/styles.scss

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@
88
}
99
}
1010
.description {
11-
width: 300px;
11+
width: 900px;
12+
@media (max-width: 1290px) and (min-width: 670px) {
13+
width: 400px;
14+
}
15+
@media (max-width: 670px) and (min-width: 515px) {
16+
width: 250px;
17+
}
18+
@media (max-width: 515px) {
19+
width: 100px;
20+
}
21+
}
22+
23+
.mindecription,
24+
.description {
1225
font-size: 18px;
1326
overflow: hidden;
1427
text-overflow: ellipsis;
1528
line-height: 18px;
16-
@media (max-width: 600px) {
17-
width: 100px;
18-
}
1929
}
2030
.title {
2131
font-size: 24px;

src/components/contents/DoneTasks.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DoneTasks = () => {
1818
<div key={i}>
1919
<Item
2020
type="primary"
21+
minimized
2122
id={todo.id}
2223
hasButtons={false}
2324
title={todo.title}

src/components/contents/Form.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ const FormComponent = ({
4242
name="nest-messages"
4343
onFinish={onCheck}
4444
validateMessages={validateMessages}
45+
initialValues={{ name: 'hey' }}
4546
>
46-
<Form.Item name={['title']} rules={[{ required: true }]}>
47+
<Form.Item name={'title'} rules={[{ required: true }]}>
4748
<Input
4849
placeholder="Enter Title"
4950
onChange={() => {}}
@@ -52,7 +53,7 @@ const FormComponent = ({
5253
defaultValue={titleValue}
5354
/>
5455
</Form.Item>
55-
<Form.Item name={['description']} rules={[{ required: true }]}>
56+
<Form.Item name={'description'} rules={[{ required: true }]}>
5657
<Input
5758
placeholder="Enter Description"
5859
onChange={() => {}}
@@ -61,7 +62,7 @@ const FormComponent = ({
6162
defaultValue={descriptionValue}
6263
/>
6364
</Form.Item>
64-
<Form.Item name={['memo']} rules={[{ required: true }]}>
65+
<Form.Item name={'memo'} rules={[{ required: true }]}>
6566
<Input
6667
placeholder="Enter what you like"
6768
onChange={() => {}}
@@ -70,7 +71,7 @@ const FormComponent = ({
7071
defaultValue={memoValue}
7172
/>
7273
</Form.Item>
73-
<Form.Item name={['priority']} rules={[{ required: true }]}>
74+
<Form.Item name={'priority'} rules={[{ required: true }]}>
7475
<Radio.Group
7576
className="flex justify-between items-center"
7677
defaultValue={priorityValue}

0 commit comments

Comments
 (0)