Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToDoList
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IHM-WEB
ToDoList
Commits
5df1b3f9
Commit
5df1b3f9
authored
4 months ago
by
OUKASSOU Anas
Browse files
Options
Downloads
Patches
Plain Diff
Refactor Modal
parent
840225aa
No related branches found
No related tags found
1 merge request
!16
Feature/manage tasks
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/todolist/Modal.jsx
+75
-66
75 additions, 66 deletions
src/components/todolist/Modal.jsx
src/pages/Todolist.jsx
+11
-1
11 additions, 1 deletion
src/pages/Todolist.jsx
with
86 additions
and
67 deletions
src/components/todolist/Modal.jsx
+
75
−
66
View file @
5df1b3f9
...
@@ -2,76 +2,85 @@ import { useState } from "react";
...
@@ -2,76 +2,85 @@ import { useState } from "react";
import
DatePicker
from
"
react-datepicker
"
;
import
DatePicker
from
"
react-datepicker
"
;
import
"
react-datepicker/dist/react-datepicker.css
"
;
import
"
react-datepicker/dist/react-datepicker.css
"
;
export
default
function
Modal
({
isOpen
,
closeModal
,
saveTask
})
{
export
default
function
Modal
({
task
,
isOpen
,
closeModal
,
saveTask
})
{
if
(
!
isOpen
)
return
null
;
if
(
!
isOpen
)
return
null
;
const
[
taskName
,
setTaskName
]
=
useState
(
""
);
const
[
editedTask
,
setEditedTask
]
=
useState
({...
task
});
const
[
dueDate
,
setDueDate
]
=
useState
(
new
Date
());
const
createTask
=
()
=>
{
const
handleSave
=
()
=>
{
return
{
saveTask
(
editedTask
)
id
:
crypto
.
randomUUID
(),
name
:
taskName
,
isCompleted
:
false
,
dueDate
:
dueDate
}
}
const
handleSaveTask
=
()
=>
{
const
task
=
createTask
()
saveTask
(
task
)
closeModal
()
closeModal
()
}
}
const
handleInputChange
=
(
e
)
=>
{
const
handleChange
=
(
e
)
=>
{
setTaskName
(
e
.
target
.
value
);
const
{
name
,
value
,
type
,
checked
}
=
e
.
target
;
setEditedTask
({
...
editedTask
,
[
name
]:
type
===
'
checkbox
'
?
checked
:
value
});
};
};
return
(
return
(
<
div
className
=
"fixed inset-0 bg-black bg-opacity-25 flex items-center justify-center z-50"
>
<
div
<
div
className
=
"absolute top-0 left-0 right-0 bottom-0 flex justify-center items-center z-50"
className
=
"bg-white rounded-lg shadow-xl p-6 w-full max-w-md mx-4"
style
=
{
{
pointerEvents
:
'
none
'
}
}
>
>
<
div
<
div
className
=
"flex justify-between items-center mb-4"
>
className
=
"absolute inset-0 bg-gray-500 bg-opacity-50"
<
h3
className
=
"text-lg font-medium"
>
Edit Task
</
h3
>
style
=
{
{
pointerEvents
:
'
none
'
}
}
<
button
></
div
>
onClick
=
{
closeModal
}
className
=
"text-gray-400 hover:text-gray-500"
<
div
className
=
"relative bg-white p-6 rounded-lg shadow-lg w-1/3 z-10"
style
=
{
{
pointerEvents
:
'
auto
'
}
}
>
>
<
h2
className
=
"text-xl mb-4"
>
Add a New Task
</
h2
>
<
svg
className
=
"h-6 w-6"
fill
=
"none"
viewBox
=
"0 0 24 24"
stroke
=
"currentColor"
>
<
p
className
=
"mb-4"
>
Enter the task details below:
</
p
>
<
path
strokeLinecap
=
"round"
strokeLinejoin
=
"round"
strokeWidth
=
{
2
}
d
=
"M6 18L18 6M6 6l12 12"
/>
</
svg
>
</
button
>
</
div
>
<
div
className
=
"space-y-4"
>
<
div
>
<
label
htmlFor
=
"name"
className
=
"block text-sm font-medium text-gray-700 mb-1"
>
Task Name
</
label
>
<
input
<
input
type
=
"text
"
id
=
"name
"
className
=
"w-full p-2 mb-4 border border-gray-300 rounded-md
"
name
=
"name
"
placeholder
=
"Task Name
"
className
=
"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500
"
value
=
{
t
ask
N
ame
}
value
=
{
editedT
ask
.
n
ame
}
onChange
=
{
handle
Input
Change
}
onChange
=
{
handleChange
}
/>
/>
</
div
>
<
div
>
<
div
>
<
DatePicker
<
label
htmlFor
=
"dueDate"
className
=
"block text-sm font-medium text-gray-700 mb-1"
>
showIcon
Due Date
selected
=
{
dueDate
}
</
label
>
onChange
=
{
(
date
)
=>
setDueDate
(
date
)
}
<
input
id
=
"dueDate"
name
=
"dueDate"
type
=
"date"
className
=
"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500"
value
=
{
editedTask
.
dueDate
}
onChange
=
{
handleChange
}
/>
/>
</
div
>
</
div
>
</
div
>
<
div
className
=
"flex justify-
between
"
>
<
div
className
=
"
mt-6
flex justify-
end space-x-3
"
>
<
button
<
button
type
=
"button"
className
=
"px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
onClick
=
{
closeModal
}
onClick
=
{
closeModal
}
className
=
"px-4 py-2 bg-red-500 text-white rounded-md"
>
>
C
lose
C
ancel
</
button
>
</
button
>
<
button
<
button
className
=
"px-4 py-2 bg-blue-500 text-white rounded-md"
type
=
"button"
onClick
=
{
handleSaveTask
}
className
=
"px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
onClick
=
{
handleSave
}
>
>
Save
Task
Save
</
button
>
</
button
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
This diff is collapsed.
Click to expand it.
src/pages/Todolist.jsx
+
11
−
1
View file @
5df1b3f9
...
@@ -6,6 +6,16 @@ import { useTasks } from "@context/TasksContext";
...
@@ -6,6 +6,16 @@ import { useTasks } from "@context/TasksContext";
export
default
function
Todolist
()
{
export
default
function
Todolist
()
{
const
{
tasks
,
setTasks
}
=
useTasks
()
const
{
tasks
,
setTasks
}
=
useTasks
()
const
newTask
=
()
=>
{
return
{
id
:
crypto
.
randomUUID
(),
name
:
""
,
isCompleted
:
false
,
dueDate
:
""
}
}
const
saveTask
=
(
task
)
=>
{
const
saveTask
=
(
task
)
=>
{
const
newTask
=
{
const
newTask
=
{
...
task
,
...
task
,
...
@@ -36,7 +46,7 @@ export default function Todolist() {
...
@@ -36,7 +46,7 @@ export default function Todolist() {
</
div
>
</
div
>
</
div
>
</
div
>
<
Modal
isOpen
=
{
isModalOpen
}
closeModal
=
{
closeModal
}
saveTask
=
{
saveTask
}
/>
<
Modal
task
=
{
newTask
()
}
isOpen
=
{
isModalOpen
}
closeModal
=
{
closeModal
}
saveTask
=
{
saveTask
}
/>
</
div
>
</
div
>
)
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment