@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +6 -6
- package/.storybook/main.js +93 -93
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.js +26 -26
- package/.storybook/preview.tsx +18 -18
- package/README.md +5 -5
- package/commitlint.config.js +23 -23
- package/package.json +1 -1
- package/rollup.config.js +65 -65
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -77
- package/src/components/BaseCalendar/index.tsx +63 -63
- package/src/components/BaseCalendar/styles.module.scss +15 -15
- package/src/components/Button/Button.stories.tsx +16 -0
- package/src/components/Button/Button.tsx +14 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Button/styles.module.scss +3 -0
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -11
- package/src/components/CalendarGrid/index.tsx +19 -19
- package/src/components/CalendarGrid/types.ts +26 -26
- package/src/components/Clear/Clear.stories.tsx +16 -16
- package/src/components/Clear/index.tsx +12 -12
- package/src/components/Clear/styles.module.scss +34 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +127 -127
- package/src/components/DatePicker/index.tsx +72 -72
- package/src/components/DatePicker/styles.module.scss +10 -10
- package/src/components/Day/Day.stories.tsx +75 -75
- package/src/components/Day/index.tsx +95 -95
- package/src/components/Day/styles.module.scss +97 -97
- package/src/components/Input/Input.stories.tsx +37 -37
- package/src/components/Input/index.tsx +64 -64
- package/src/components/Input/styles.module.scss +79 -79
- package/src/components/Modal/CrudModal/index.tsx +43 -43
- package/src/components/Modal/CrudModal/styles.module.scss +44 -44
- package/src/components/Modal/index.tsx +66 -66
- package/src/components/Modal/styles.module.scss +40 -40
- package/src/components/Modal/types.ts +13 -13
- package/src/components/Month/Month.stories.tsx +19 -19
- package/src/components/Month/index.tsx +31 -31
- package/src/components/Month/styles.module.scss +30 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +134 -134
- package/src/components/RangePicker/index.tsx +144 -144
- package/src/components/RangePicker/styles.module.scss +19 -19
- package/src/components/TasksManager/AddModal/index.tsx +62 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +22 -22
- package/src/components/TasksManager/EditModal/index.tsx +96 -96
- package/src/components/TasksManager/index.tsx +112 -112
- package/src/components/TasksManager/styles.module.scss +62 -62
- package/src/components/Week/Week.stories.tsx +49 -49
- package/src/components/Week/index.tsx +68 -68
- package/src/components/Week/styles.module.scss +7 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +38 -38
- package/src/components/WeekDay/index.tsx +35 -35
- package/src/components/WeekDay/styles.module.scss +19 -19
- package/src/constants/dateMask.ts +23 -23
- package/src/constants/firstDayOfWeek.ts +7 -7
- package/src/constants/holidays.ts +32 -32
- package/src/constants/modes.ts +6 -6
- package/src/constants/monthsNames.ts +14 -14
- package/src/constants/weekdaysNames.ts +1 -1
- package/src/hooks/useCalendar.ts +62 -62
- package/src/hooks/useLockBodyScroll.ts +19 -19
- package/src/hooks/useModal.ts +45 -45
- package/src/hooks/useTooltip.ts +41 -41
- package/src/hooks/useValidate.ts +80 -80
- package/src/index.ts +15 -15
- package/src/services/calendarService.ts +62 -62
- package/src/services/decorators/withHolidays.ts +12 -12
- package/src/services/decorators/withMinMax.test.ts +77 -77
- package/src/services/decorators/withMinMax.ts +19 -19
- package/src/services/holidayService.ts +56 -56
- package/src/store/localStorage.ts +33 -33
- package/src/store/tasksStore.tsx +146 -146
- package/src/store/types.ts +22 -22
- package/src/stories/Button.stories.ts +54 -0
- package/src/stories/Button.tsx +37 -0
- package/src/stories/Configure.mdx +388 -0
- package/src/stories/Header.stories.ts +34 -0
- package/src/stories/Header.tsx +56 -0
- package/src/stories/Page.stories.ts +33 -0
- package/src/stories/Page.tsx +73 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/page.css +68 -0
- package/src/styles/_border.scss +9 -9
- package/src/styles/_colors.scss +53 -53
- package/src/styles/_gap.scss +4 -4
- package/src/styles/_globals.scss +61 -61
- package/src/styles/_grid.scss +9 -9
- package/src/styles/_mixins.scss +6 -6
- package/src/styles/_reset.scss +98 -98
- package/src/styles/_theme-mixins.scss +51 -51
- package/src/styles/_typography.scss +10 -10
- package/src/styles/_variables.scss +8 -8
- package/src/styles/main.scss +3 -3
- package/src/types/types.d.ts +15 -15
- package/src/utils/calendar.test.ts +154 -154
- package/src/utils/calendar.ts +82 -82
- package/src/utils/controlDate.ts +3 -3
- package/src/utils/dateChecks.test.ts +216 -216
- package/src/utils/dateChecks.ts +75 -75
- package/src/utils/formatDate.ts +27 -27
- package/src/utils/schema.test.ts +40 -40
- package/src/utils/schema.ts +8 -8
- package/src/utils/weekdayOrder.test.ts +11 -11
- package/src/utils/weekdayOrder.ts +7 -7
- package/vitest.config.ts +38 -38
- package/vitest.shims.d.ts +1 -1
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
-
import { useForm } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
import { Input } from '@/components/Input';
|
|
5
|
-
import { ModalProps } from '@/components/Modal';
|
|
6
|
-
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
7
|
-
import { useTasks } from '@/store/tasksStore';
|
|
8
|
-
import { formatDate } from '@/utils/formatDate';
|
|
9
|
-
import { FormData } from '@/utils/schema';
|
|
10
|
-
import { formSchema } from '@/utils/schema';
|
|
11
|
-
|
|
12
|
-
interface AddModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
13
|
-
date: Date;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const AddModal = ({ isOpen, onClose, date }: AddModalProps) => {
|
|
17
|
-
const { addTask } = useTasks();
|
|
18
|
-
const {
|
|
19
|
-
register,
|
|
20
|
-
handleSubmit,
|
|
21
|
-
reset,
|
|
22
|
-
formState: { errors },
|
|
23
|
-
} = useForm<FormData>({
|
|
24
|
-
resolver: zodResolver(formSchema),
|
|
25
|
-
defaultValues: {
|
|
26
|
-
title: '',
|
|
27
|
-
date: formatDate(date),
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const onSubmit = (data: FormData) => {
|
|
32
|
-
addTask(date, data.title);
|
|
33
|
-
reset();
|
|
34
|
-
onClose();
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const handleClose = () => {
|
|
38
|
-
reset({
|
|
39
|
-
title: '',
|
|
40
|
-
});
|
|
41
|
-
onClose();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<CrudModal
|
|
46
|
-
isOpen={isOpen}
|
|
47
|
-
onClose={handleClose}
|
|
48
|
-
onConfirm={handleSubmit(onSubmit)}
|
|
49
|
-
showCloseButton={true}
|
|
50
|
-
confirmText="Add"
|
|
51
|
-
cancelText="Cancel"
|
|
52
|
-
title="Add task"
|
|
53
|
-
>
|
|
54
|
-
<Input
|
|
55
|
-
{...register('title')}
|
|
56
|
-
label="Title"
|
|
57
|
-
placeholder="Training name"
|
|
58
|
-
error={errors.title?.message}
|
|
59
|
-
/>
|
|
60
|
-
</CrudModal>
|
|
61
|
-
);
|
|
62
|
-
};
|
|
1
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
+
import { useForm } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Input } from '@/components/Input';
|
|
5
|
+
import { ModalProps } from '@/components/Modal';
|
|
6
|
+
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
7
|
+
import { useTasks } from '@/store/tasksStore';
|
|
8
|
+
import { formatDate } from '@/utils/formatDate';
|
|
9
|
+
import { FormData } from '@/utils/schema';
|
|
10
|
+
import { formSchema } from '@/utils/schema';
|
|
11
|
+
|
|
12
|
+
interface AddModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
13
|
+
date: Date;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const AddModal = ({ isOpen, onClose, date }: AddModalProps) => {
|
|
17
|
+
const { addTask } = useTasks();
|
|
18
|
+
const {
|
|
19
|
+
register,
|
|
20
|
+
handleSubmit,
|
|
21
|
+
reset,
|
|
22
|
+
formState: { errors },
|
|
23
|
+
} = useForm<FormData>({
|
|
24
|
+
resolver: zodResolver(formSchema),
|
|
25
|
+
defaultValues: {
|
|
26
|
+
title: '',
|
|
27
|
+
date: formatDate(date),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const onSubmit = (data: FormData) => {
|
|
32
|
+
addTask(date, data.title);
|
|
33
|
+
reset();
|
|
34
|
+
onClose();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const handleClose = () => {
|
|
38
|
+
reset({
|
|
39
|
+
title: '',
|
|
40
|
+
});
|
|
41
|
+
onClose();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<CrudModal
|
|
46
|
+
isOpen={isOpen}
|
|
47
|
+
onClose={handleClose}
|
|
48
|
+
onConfirm={handleSubmit(onSubmit)}
|
|
49
|
+
showCloseButton={true}
|
|
50
|
+
confirmText="Add"
|
|
51
|
+
cancelText="Cancel"
|
|
52
|
+
title="Add task"
|
|
53
|
+
>
|
|
54
|
+
<Input
|
|
55
|
+
{...register('title')}
|
|
56
|
+
label="Title"
|
|
57
|
+
placeholder="Training name"
|
|
58
|
+
error={errors.title?.message}
|
|
59
|
+
/>
|
|
60
|
+
</CrudModal>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { ModalProps } from '@/components/Modal';
|
|
2
|
-
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
3
|
-
import { useTasks } from '@/store/tasksStore';
|
|
4
|
-
|
|
5
|
-
interface DeleteModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
6
|
-
id: string;
|
|
7
|
-
}
|
|
8
|
-
export const DeleteModal = ({ id, isOpen, onClose }: DeleteModalProps) => {
|
|
9
|
-
const { deleteTask } = useTasks();
|
|
10
|
-
const handleDelete = () => {
|
|
11
|
-
deleteTask(id);
|
|
12
|
-
onClose();
|
|
13
|
-
};
|
|
14
|
-
return (
|
|
15
|
-
<CrudModal
|
|
16
|
-
isOpen={isOpen}
|
|
17
|
-
onClose={onClose}
|
|
18
|
-
onConfirm={handleDelete}
|
|
19
|
-
title="Are you sure you want to delete this task?"
|
|
20
|
-
/>
|
|
21
|
-
);
|
|
22
|
-
};
|
|
1
|
+
import { ModalProps } from '@/components/Modal';
|
|
2
|
+
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
3
|
+
import { useTasks } from '@/store/tasksStore';
|
|
4
|
+
|
|
5
|
+
interface DeleteModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export const DeleteModal = ({ id, isOpen, onClose }: DeleteModalProps) => {
|
|
9
|
+
const { deleteTask } = useTasks();
|
|
10
|
+
const handleDelete = () => {
|
|
11
|
+
deleteTask(id);
|
|
12
|
+
onClose();
|
|
13
|
+
};
|
|
14
|
+
return (
|
|
15
|
+
<CrudModal
|
|
16
|
+
isOpen={isOpen}
|
|
17
|
+
onClose={onClose}
|
|
18
|
+
onConfirm={handleDelete}
|
|
19
|
+
title="Are you sure you want to delete this task?"
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { useForm } from 'react-hook-form';
|
|
4
|
-
|
|
5
|
-
import { Input } from '@/components/Input';
|
|
6
|
-
import { ModalProps } from '@/components/Modal';
|
|
7
|
-
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
8
|
-
import { useTasks } from '@/store/tasksStore';
|
|
9
|
-
import { formatDate } from '@/utils/formatDate';
|
|
10
|
-
import { FormData } from '@/utils/schema';
|
|
11
|
-
import { formSchema } from '@/utils/schema';
|
|
12
|
-
|
|
13
|
-
interface EditModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
14
|
-
id: string;
|
|
15
|
-
date: Date;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const EditModal = ({ isOpen, onClose, id, date }: EditModalProps) => {
|
|
19
|
-
const { editTask, tasks } = useTasks();
|
|
20
|
-
const {
|
|
21
|
-
register,
|
|
22
|
-
handleSubmit,
|
|
23
|
-
reset,
|
|
24
|
-
formState: { errors },
|
|
25
|
-
} = useForm<FormData>({
|
|
26
|
-
resolver: zodResolver(formSchema),
|
|
27
|
-
defaultValues: {
|
|
28
|
-
title: '',
|
|
29
|
-
date: formatDate(date),
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const onSubmit = (data: FormData) => {
|
|
34
|
-
const taskData = {
|
|
35
|
-
title: data.title,
|
|
36
|
-
date: new Date(data.date),
|
|
37
|
-
};
|
|
38
|
-
editTask(id, taskData);
|
|
39
|
-
reset({
|
|
40
|
-
title: '',
|
|
41
|
-
date: formatDate(date),
|
|
42
|
-
});
|
|
43
|
-
onClose();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (isOpen && id) {
|
|
48
|
-
const task = tasks.find((task) => task.id === id);
|
|
49
|
-
if (task) {
|
|
50
|
-
reset({
|
|
51
|
-
title: task.title,
|
|
52
|
-
date: formatDate(task.date),
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
reset({
|
|
56
|
-
title: '',
|
|
57
|
-
date: formatDate(date),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, [isOpen, id, tasks, reset, date]);
|
|
62
|
-
|
|
63
|
-
const handleClose = () => {
|
|
64
|
-
reset({
|
|
65
|
-
title: '',
|
|
66
|
-
date: formatDate(date),
|
|
67
|
-
});
|
|
68
|
-
onClose();
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<CrudModal
|
|
73
|
-
isOpen={isOpen}
|
|
74
|
-
onClose={handleClose}
|
|
75
|
-
onConfirm={handleSubmit(onSubmit)}
|
|
76
|
-
showCloseButton={true}
|
|
77
|
-
confirmText="Edit"
|
|
78
|
-
cancelText="Cancel"
|
|
79
|
-
title="Edit task"
|
|
80
|
-
>
|
|
81
|
-
<Input
|
|
82
|
-
{...register('title')}
|
|
83
|
-
label="Title"
|
|
84
|
-
placeholder="Training name"
|
|
85
|
-
error={errors.title?.message}
|
|
86
|
-
/>
|
|
87
|
-
<Input
|
|
88
|
-
{...register('date')}
|
|
89
|
-
label="Date"
|
|
90
|
-
type="date"
|
|
91
|
-
placeholder="Training date"
|
|
92
|
-
error={errors.date?.message}
|
|
93
|
-
/>
|
|
94
|
-
</CrudModal>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
1
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
4
|
+
|
|
5
|
+
import { Input } from '@/components/Input';
|
|
6
|
+
import { ModalProps } from '@/components/Modal';
|
|
7
|
+
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
8
|
+
import { useTasks } from '@/store/tasksStore';
|
|
9
|
+
import { formatDate } from '@/utils/formatDate';
|
|
10
|
+
import { FormData } from '@/utils/schema';
|
|
11
|
+
import { formSchema } from '@/utils/schema';
|
|
12
|
+
|
|
13
|
+
interface EditModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
14
|
+
id: string;
|
|
15
|
+
date: Date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const EditModal = ({ isOpen, onClose, id, date }: EditModalProps) => {
|
|
19
|
+
const { editTask, tasks } = useTasks();
|
|
20
|
+
const {
|
|
21
|
+
register,
|
|
22
|
+
handleSubmit,
|
|
23
|
+
reset,
|
|
24
|
+
formState: { errors },
|
|
25
|
+
} = useForm<FormData>({
|
|
26
|
+
resolver: zodResolver(formSchema),
|
|
27
|
+
defaultValues: {
|
|
28
|
+
title: '',
|
|
29
|
+
date: formatDate(date),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const onSubmit = (data: FormData) => {
|
|
34
|
+
const taskData = {
|
|
35
|
+
title: data.title,
|
|
36
|
+
date: new Date(data.date),
|
|
37
|
+
};
|
|
38
|
+
editTask(id, taskData);
|
|
39
|
+
reset({
|
|
40
|
+
title: '',
|
|
41
|
+
date: formatDate(date),
|
|
42
|
+
});
|
|
43
|
+
onClose();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (isOpen && id) {
|
|
48
|
+
const task = tasks.find((task) => task.id === id);
|
|
49
|
+
if (task) {
|
|
50
|
+
reset({
|
|
51
|
+
title: task.title,
|
|
52
|
+
date: formatDate(task.date),
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
reset({
|
|
56
|
+
title: '',
|
|
57
|
+
date: formatDate(date),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [isOpen, id, tasks, reset, date]);
|
|
62
|
+
|
|
63
|
+
const handleClose = () => {
|
|
64
|
+
reset({
|
|
65
|
+
title: '',
|
|
66
|
+
date: formatDate(date),
|
|
67
|
+
});
|
|
68
|
+
onClose();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<CrudModal
|
|
73
|
+
isOpen={isOpen}
|
|
74
|
+
onClose={handleClose}
|
|
75
|
+
onConfirm={handleSubmit(onSubmit)}
|
|
76
|
+
showCloseButton={true}
|
|
77
|
+
confirmText="Edit"
|
|
78
|
+
cancelText="Cancel"
|
|
79
|
+
title="Edit task"
|
|
80
|
+
>
|
|
81
|
+
<Input
|
|
82
|
+
{...register('title')}
|
|
83
|
+
label="Title"
|
|
84
|
+
placeholder="Training name"
|
|
85
|
+
error={errors.title?.message}
|
|
86
|
+
/>
|
|
87
|
+
<Input
|
|
88
|
+
{...register('date')}
|
|
89
|
+
label="Date"
|
|
90
|
+
type="date"
|
|
91
|
+
placeholder="Training date"
|
|
92
|
+
error={errors.date?.message}
|
|
93
|
+
/>
|
|
94
|
+
</CrudModal>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import Delete from '@assets/actions/Delete.svg?react';
|
|
2
|
-
import Edit from '@assets/actions/Edit.svg?react';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
|
|
6
|
-
import { useModal } from '@/hooks/useModal';
|
|
7
|
-
import { useTasks } from '@/store/tasksStore';
|
|
8
|
-
import { Task } from '@/store/types';
|
|
9
|
-
|
|
10
|
-
import { Modal } from '../Modal';
|
|
11
|
-
import { AddModal } from './AddModal';
|
|
12
|
-
import { DeleteModal } from './DeleteModal';
|
|
13
|
-
import { EditModal } from './EditModal';
|
|
14
|
-
import styles from './styles.module.scss';
|
|
15
|
-
|
|
16
|
-
interface TasksManager {
|
|
17
|
-
tasks: Task[];
|
|
18
|
-
onClose: () => void;
|
|
19
|
-
isOpen: boolean;
|
|
20
|
-
selectedDate: Date;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const TasksManager = ({
|
|
24
|
-
onClose,
|
|
25
|
-
isOpen,
|
|
26
|
-
tasks,
|
|
27
|
-
selectedDate,
|
|
28
|
-
}: TasksManager) => {
|
|
29
|
-
const addModal = useModal();
|
|
30
|
-
const editModal = useModal();
|
|
31
|
-
const deleteModal = useModal();
|
|
32
|
-
const { toggleTask } = useTasks();
|
|
33
|
-
|
|
34
|
-
const [currentTaskId, setCurrentTaskId] = useState<string>('');
|
|
35
|
-
|
|
36
|
-
const handleAddTask = () => {
|
|
37
|
-
addModal.open();
|
|
38
|
-
};
|
|
39
|
-
const handleEditTask = (id: string) => () => {
|
|
40
|
-
setCurrentTaskId(id);
|
|
41
|
-
editModal.open();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleDeleteTask = (id: string) => () => {
|
|
45
|
-
setCurrentTaskId(id);
|
|
46
|
-
deleteModal.open();
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const handleToggle = (id: string) => () => {
|
|
50
|
-
toggleTask(id);
|
|
51
|
-
};
|
|
52
|
-
return (
|
|
53
|
-
<>
|
|
54
|
-
<Modal isOpen={isOpen} onClose={onClose}>
|
|
55
|
-
<div className={styles.tasksManager}>
|
|
56
|
-
<h1 className={styles.header}>Tasks for the day:</h1>
|
|
57
|
-
<button className={styles.add} onClick={handleAddTask}>
|
|
58
|
-
Add task
|
|
59
|
-
</button>
|
|
60
|
-
<ul className={styles.tasks}>
|
|
61
|
-
{tasks.length < 1 && (
|
|
62
|
-
<li>
|
|
63
|
-
<p>No tasks added</p>
|
|
64
|
-
</li>
|
|
65
|
-
)}
|
|
66
|
-
{tasks.map(({ id, title, completed }) => (
|
|
67
|
-
<li
|
|
68
|
-
key={id}
|
|
69
|
-
className={classNames(styles.task, {
|
|
70
|
-
[styles.checked]: completed,
|
|
71
|
-
})}
|
|
72
|
-
>
|
|
73
|
-
<input
|
|
74
|
-
type="checkbox"
|
|
75
|
-
checked={completed}
|
|
76
|
-
onChange={handleToggle(id)}
|
|
77
|
-
/>
|
|
78
|
-
<p className={styles.title}>{title}</p>
|
|
79
|
-
<button onClick={handleEditTask(id)} className={styles.action}>
|
|
80
|
-
<Edit />
|
|
81
|
-
</button>
|
|
82
|
-
<button
|
|
83
|
-
onClick={handleDeleteTask(id)}
|
|
84
|
-
className={classNames(styles.action, styles.delete)}
|
|
85
|
-
>
|
|
86
|
-
<Delete />
|
|
87
|
-
</button>
|
|
88
|
-
</li>
|
|
89
|
-
))}
|
|
90
|
-
</ul>
|
|
91
|
-
</div>
|
|
92
|
-
</Modal>
|
|
93
|
-
<AddModal
|
|
94
|
-
isOpen={addModal.isOpen}
|
|
95
|
-
onClose={addModal.close}
|
|
96
|
-
date={selectedDate}
|
|
97
|
-
/>
|
|
98
|
-
|
|
99
|
-
<EditModal
|
|
100
|
-
isOpen={editModal.isOpen}
|
|
101
|
-
onClose={editModal.close}
|
|
102
|
-
id={currentTaskId}
|
|
103
|
-
date={selectedDate}
|
|
104
|
-
/>
|
|
105
|
-
<DeleteModal
|
|
106
|
-
isOpen={deleteModal.isOpen}
|
|
107
|
-
onClose={deleteModal.close}
|
|
108
|
-
id={currentTaskId}
|
|
109
|
-
/>
|
|
110
|
-
</>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
1
|
+
import Delete from '@assets/actions/Delete.svg?react';
|
|
2
|
+
import Edit from '@assets/actions/Edit.svg?react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import { useModal } from '@/hooks/useModal';
|
|
7
|
+
import { useTasks } from '@/store/tasksStore';
|
|
8
|
+
import { Task } from '@/store/types';
|
|
9
|
+
|
|
10
|
+
import { Modal } from '../Modal';
|
|
11
|
+
import { AddModal } from './AddModal';
|
|
12
|
+
import { DeleteModal } from './DeleteModal';
|
|
13
|
+
import { EditModal } from './EditModal';
|
|
14
|
+
import styles from './styles.module.scss';
|
|
15
|
+
|
|
16
|
+
interface TasksManager {
|
|
17
|
+
tasks: Task[];
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
isOpen: boolean;
|
|
20
|
+
selectedDate: Date;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const TasksManager = ({
|
|
24
|
+
onClose,
|
|
25
|
+
isOpen,
|
|
26
|
+
tasks,
|
|
27
|
+
selectedDate,
|
|
28
|
+
}: TasksManager) => {
|
|
29
|
+
const addModal = useModal();
|
|
30
|
+
const editModal = useModal();
|
|
31
|
+
const deleteModal = useModal();
|
|
32
|
+
const { toggleTask } = useTasks();
|
|
33
|
+
|
|
34
|
+
const [currentTaskId, setCurrentTaskId] = useState<string>('');
|
|
35
|
+
|
|
36
|
+
const handleAddTask = () => {
|
|
37
|
+
addModal.open();
|
|
38
|
+
};
|
|
39
|
+
const handleEditTask = (id: string) => () => {
|
|
40
|
+
setCurrentTaskId(id);
|
|
41
|
+
editModal.open();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleDeleteTask = (id: string) => () => {
|
|
45
|
+
setCurrentTaskId(id);
|
|
46
|
+
deleteModal.open();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleToggle = (id: string) => () => {
|
|
50
|
+
toggleTask(id);
|
|
51
|
+
};
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<Modal isOpen={isOpen} onClose={onClose}>
|
|
55
|
+
<div className={styles.tasksManager}>
|
|
56
|
+
<h1 className={styles.header}>Tasks for the day:</h1>
|
|
57
|
+
<button className={styles.add} onClick={handleAddTask}>
|
|
58
|
+
Add task
|
|
59
|
+
</button>
|
|
60
|
+
<ul className={styles.tasks}>
|
|
61
|
+
{tasks.length < 1 && (
|
|
62
|
+
<li>
|
|
63
|
+
<p>No tasks added</p>
|
|
64
|
+
</li>
|
|
65
|
+
)}
|
|
66
|
+
{tasks.map(({ id, title, completed }) => (
|
|
67
|
+
<li
|
|
68
|
+
key={id}
|
|
69
|
+
className={classNames(styles.task, {
|
|
70
|
+
[styles.checked]: completed,
|
|
71
|
+
})}
|
|
72
|
+
>
|
|
73
|
+
<input
|
|
74
|
+
type="checkbox"
|
|
75
|
+
checked={completed}
|
|
76
|
+
onChange={handleToggle(id)}
|
|
77
|
+
/>
|
|
78
|
+
<p className={styles.title}>{title}</p>
|
|
79
|
+
<button onClick={handleEditTask(id)} className={styles.action}>
|
|
80
|
+
<Edit />
|
|
81
|
+
</button>
|
|
82
|
+
<button
|
|
83
|
+
onClick={handleDeleteTask(id)}
|
|
84
|
+
className={classNames(styles.action, styles.delete)}
|
|
85
|
+
>
|
|
86
|
+
<Delete />
|
|
87
|
+
</button>
|
|
88
|
+
</li>
|
|
89
|
+
))}
|
|
90
|
+
</ul>
|
|
91
|
+
</div>
|
|
92
|
+
</Modal>
|
|
93
|
+
<AddModal
|
|
94
|
+
isOpen={addModal.isOpen}
|
|
95
|
+
onClose={addModal.close}
|
|
96
|
+
date={selectedDate}
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
<EditModal
|
|
100
|
+
isOpen={editModal.isOpen}
|
|
101
|
+
onClose={editModal.close}
|
|
102
|
+
id={currentTaskId}
|
|
103
|
+
date={selectedDate}
|
|
104
|
+
/>
|
|
105
|
+
<DeleteModal
|
|
106
|
+
isOpen={deleteModal.isOpen}
|
|
107
|
+
onClose={deleteModal.close}
|
|
108
|
+
id={currentTaskId}
|
|
109
|
+
/>
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
};
|