@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.2
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/README.md +302 -302
- package/package.json +111 -106
- package/.babelrc.json +0 -7
- package/.github/workflows/chromatic.yml +0 -25
- package/.github/workflows/ci.yml +0 -56
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.prettierignore +0 -16
- package/.prettierrc +0 -6
- package/.storybook/main.js +0 -93
- package/.storybook/preview-head.html +0 -6
- package/.storybook/preview.js +0 -26
- package/.storybook/preview.tsx +0 -18
- package/commitlint.config.js +0 -23
- package/eslint.config.ts +0 -80
- package/jest.config.json +0 -21
- package/rollup.config.js +0 -65
- package/src/assets/actions/Delete.svg +0 -4
- package/src/assets/actions/Edit.svg +0 -3
- package/src/assets/arrows/Next.svg +0 -4
- package/src/assets/arrows/Prev.svg +0 -4
- package/src/assets/input/Calendar.svg +0 -3
- package/src/assets/input/Clear.svg +0 -3
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +0 -77
- package/src/components/BaseCalendar/index.tsx +0 -63
- package/src/components/BaseCalendar/styles.module.scss +0 -15
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +0 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +0 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +0 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +0 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.tsx +0 -223
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +0 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +0 -11
- package/src/components/CalendarGrid/index.tsx +0 -19
- package/src/components/CalendarGrid/types.ts +0 -26
- package/src/components/Clear/Clear.stories.tsx +0 -16
- package/src/components/Clear/index.tsx +0 -12
- package/src/components/Clear/styles.module.scss +0 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +0 -127
- package/src/components/DatePicker/index.tsx +0 -72
- package/src/components/DatePicker/styles.module.scss +0 -10
- package/src/components/Day/Day.stories.tsx +0 -75
- package/src/components/Day/index.tsx +0 -95
- package/src/components/Day/styles.module.scss +0 -97
- package/src/components/Input/Input.stories.tsx +0 -37
- package/src/components/Input/index.tsx +0 -64
- package/src/components/Input/styles.module.scss +0 -79
- package/src/components/Modal/CrudModal/index.tsx +0 -43
- package/src/components/Modal/CrudModal/styles.module.scss +0 -44
- package/src/components/Modal/index.tsx +0 -66
- package/src/components/Modal/styles.module.scss +0 -40
- package/src/components/Modal/types.ts +0 -13
- package/src/components/Month/Month.stories.tsx +0 -19
- package/src/components/Month/index.tsx +0 -31
- package/src/components/Month/styles.module.scss +0 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +0 -134
- package/src/components/RangePicker/index.tsx +0 -144
- package/src/components/RangePicker/styles.module.scss +0 -19
- package/src/components/TasksManager/AddModal/index.tsx +0 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +0 -22
- package/src/components/TasksManager/EditModal/index.tsx +0 -96
- package/src/components/TasksManager/index.tsx +0 -112
- package/src/components/TasksManager/styles.module.scss +0 -62
- package/src/components/Week/Week.stories.tsx +0 -49
- package/src/components/Week/index.tsx +0 -68
- package/src/components/Week/styles.module.scss +0 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +0 -38
- package/src/components/WeekDay/index.tsx +0 -35
- package/src/components/WeekDay/styles.module.scss +0 -19
- package/src/constants/dateMask.ts +0 -23
- package/src/constants/firstDayOfWeek.ts +0 -7
- package/src/constants/holidays.ts +0 -32
- package/src/constants/modes.ts +0 -6
- package/src/constants/monthsNames.ts +0 -14
- package/src/constants/weekdaysNames.ts +0 -1
- package/src/hooks/useCalendar.ts +0 -62
- package/src/hooks/useLockBodyScroll.ts +0 -19
- package/src/hooks/useModal.ts +0 -45
- package/src/hooks/useTooltip.ts +0 -41
- package/src/hooks/useValidate.ts +0 -80
- package/src/index.ts +0 -15
- package/src/services/calendarService.ts +0 -62
- package/src/services/decorators/withHolidays.test.ts +0 -64
- package/src/services/decorators/withHolidays.ts +0 -12
- package/src/services/decorators/withMinMax.test.ts +0 -77
- package/src/services/decorators/withMinMax.ts +0 -19
- package/src/services/holidayService.ts +0 -56
- package/src/setupTests.ts +0 -1
- package/src/store/localStorage.ts +0 -33
- package/src/store/tasksStore.test.tsx +0 -208
- package/src/store/tasksStore.tsx +0 -146
- package/src/store/types.ts +0 -22
- package/src/styles/_border.scss +0 -9
- package/src/styles/_colors.scss +0 -53
- package/src/styles/_gap.scss +0 -4
- package/src/styles/_globals.scss +0 -61
- package/src/styles/_grid.scss +0 -9
- package/src/styles/_mixins.scss +0 -6
- package/src/styles/_reset.scss +0 -98
- package/src/styles/_theme-mixins.scss +0 -51
- package/src/styles/_typography.scss +0 -10
- package/src/styles/_variables.scss +0 -8
- package/src/styles/main.scss +0 -3
- package/src/types/types.d.ts +0 -15
- package/src/utils/calendar.test.ts +0 -154
- package/src/utils/calendar.ts +0 -82
- package/src/utils/controlDate.ts +0 -3
- package/src/utils/dateChecks.test.ts +0 -216
- package/src/utils/dateChecks.ts +0 -75
- package/src/utils/formatDate.test.ts +0 -57
- package/src/utils/formatDate.ts +0 -27
- package/src/utils/schema.test.ts +0 -40
- package/src/utils/schema.ts +0 -8
- package/src/utils/weekdayOrder.test.ts +0 -11
- package/src/utils/weekdayOrder.ts +0 -7
- package/tsconfig.json +0 -31
- package/vitest.config.ts +0 -38
- package/vitest.shims.d.ts +0 -1
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { RangePicker } from './index';
|
|
3
|
-
import { setControlDate } from '../../utils/controlDate';
|
|
4
|
-
|
|
5
|
-
const meta: Meta<typeof RangePicker> = {
|
|
6
|
-
component: RangePicker,
|
|
7
|
-
parameters: {
|
|
8
|
-
layout: 'centered',
|
|
9
|
-
},
|
|
10
|
-
argTypes: {
|
|
11
|
-
monthDate: { control: 'date' },
|
|
12
|
-
minDate: { control: 'date' },
|
|
13
|
-
maxDate: { control: 'date' },
|
|
14
|
-
rangeStart: { control: 'date' },
|
|
15
|
-
rangeEnd: { control: 'date' },
|
|
16
|
-
firstDayOfWeek: {
|
|
17
|
-
control: 'select',
|
|
18
|
-
options: [0, 1],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default meta;
|
|
24
|
-
type Story = StoryObj<typeof RangePicker>;
|
|
25
|
-
|
|
26
|
-
export const Default: Story = {
|
|
27
|
-
args: {
|
|
28
|
-
monthDate: new Date(2026, 7, 1),
|
|
29
|
-
firstDayOfWeek: 1,
|
|
30
|
-
rangeStart: new Date(2026, 7, 10),
|
|
31
|
-
rangeEnd: new Date(2026, 7, 15),
|
|
32
|
-
},
|
|
33
|
-
render: (args) => (
|
|
34
|
-
<RangePicker
|
|
35
|
-
{...args}
|
|
36
|
-
monthDate={new Date(args.monthDate)}
|
|
37
|
-
minDate={setControlDate(args.minDate)}
|
|
38
|
-
maxDate={setControlDate(args.maxDate)}
|
|
39
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
40
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
41
|
-
/>
|
|
42
|
-
),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const WithTasks: Story = {
|
|
46
|
-
args: {
|
|
47
|
-
monthDate: new Date(2026, 7, 25),
|
|
48
|
-
firstDayOfWeek: 1,
|
|
49
|
-
enableTasks: true,
|
|
50
|
-
},
|
|
51
|
-
render: (args) => (
|
|
52
|
-
<RangePicker
|
|
53
|
-
{...args}
|
|
54
|
-
monthDate={new Date(args.monthDate)}
|
|
55
|
-
minDate={setControlDate(args.minDate)}
|
|
56
|
-
maxDate={setControlDate(args.maxDate)}
|
|
57
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
58
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
59
|
-
/>
|
|
60
|
-
),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const HideWeekends: Story = {
|
|
64
|
-
args: {
|
|
65
|
-
monthDate: new Date(2026, 8, 7),
|
|
66
|
-
firstDayOfWeek: 1,
|
|
67
|
-
hideWeekends: true,
|
|
68
|
-
},
|
|
69
|
-
render: (args) => (
|
|
70
|
-
<RangePicker
|
|
71
|
-
{...args}
|
|
72
|
-
monthDate={new Date(args.monthDate)}
|
|
73
|
-
minDate={setControlDate(args.minDate)}
|
|
74
|
-
maxDate={setControlDate(args.maxDate)}
|
|
75
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
76
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
77
|
-
/>
|
|
78
|
-
),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const ShowHolidays: Story = {
|
|
82
|
-
args: {
|
|
83
|
-
monthDate: new Date(2025, 0, 3),
|
|
84
|
-
firstDayOfWeek: 1,
|
|
85
|
-
showHolidays: true,
|
|
86
|
-
},
|
|
87
|
-
render: (args) => (
|
|
88
|
-
<RangePicker
|
|
89
|
-
{...args}
|
|
90
|
-
monthDate={new Date(args.monthDate)}
|
|
91
|
-
minDate={setControlDate(args.minDate)}
|
|
92
|
-
maxDate={setControlDate(args.maxDate)}
|
|
93
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
94
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
95
|
-
/>
|
|
96
|
-
),
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export const WeekMode: Story = {
|
|
100
|
-
args: {
|
|
101
|
-
monthDate: new Date(2025, 0, 31),
|
|
102
|
-
firstDayOfWeek: 1,
|
|
103
|
-
showHolidays: true,
|
|
104
|
-
mode: 'week',
|
|
105
|
-
},
|
|
106
|
-
render: (args) => (
|
|
107
|
-
<RangePicker
|
|
108
|
-
{...args}
|
|
109
|
-
monthDate={new Date(args.monthDate)}
|
|
110
|
-
minDate={setControlDate(args.minDate)}
|
|
111
|
-
maxDate={setControlDate(args.maxDate)}
|
|
112
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
113
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
114
|
-
/>
|
|
115
|
-
),
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export const WithMinMaxDates: Story = {
|
|
119
|
-
args: {
|
|
120
|
-
monthDate: new Date(2026, 7, 1),
|
|
121
|
-
firstDayOfWeek: 1,
|
|
122
|
-
minDate: new Date(2026, 7, 10),
|
|
123
|
-
maxDate: new Date(2026, 7, 20),
|
|
124
|
-
},
|
|
125
|
-
render: (args) => (
|
|
126
|
-
<RangePicker
|
|
127
|
-
{...args}
|
|
128
|
-
minDate={setControlDate(args.minDate)}
|
|
129
|
-
maxDate={setControlDate(args.maxDate)}
|
|
130
|
-
rangeStart={setControlDate(args.rangeStart)}
|
|
131
|
-
rangeEnd={setControlDate(args.rangeEnd)}
|
|
132
|
-
/>
|
|
133
|
-
),
|
|
134
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, KeyboardEvent, Ref } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useValidate } from '@/hooks/useValidate';
|
|
4
|
-
|
|
5
|
-
import { BaseCalendar } from '../BaseCalendar';
|
|
6
|
-
import { BaseCalendarProps, CalendarProps } from '../CalendarGrid/types';
|
|
7
|
-
import { Clear } from '../Clear';
|
|
8
|
-
import { Input } from '../Input';
|
|
9
|
-
import styles from './styles.module.scss';
|
|
10
|
-
|
|
11
|
-
export interface RangePickerProps
|
|
12
|
-
extends BaseCalendarProps, Pick<CalendarProps, 'rangeStart' | 'rangeEnd'> {
|
|
13
|
-
onChangeStart?: (date?: Date) => void;
|
|
14
|
-
onChangeEnd?: (date?: Date) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const RangePicker = ({
|
|
18
|
-
rangeStart,
|
|
19
|
-
rangeEnd,
|
|
20
|
-
monthDate = new Date(),
|
|
21
|
-
onChangeStart,
|
|
22
|
-
onChangeEnd,
|
|
23
|
-
...props
|
|
24
|
-
}: RangePickerProps) => {
|
|
25
|
-
const {
|
|
26
|
-
currentDate: startDate,
|
|
27
|
-
value: startValue,
|
|
28
|
-
error: startError,
|
|
29
|
-
ref: startRef,
|
|
30
|
-
handleDateSelect: handleStartDateSelect,
|
|
31
|
-
handleDateValidation: handleStartDateValidation,
|
|
32
|
-
handleClearInput: handleStartClearInput,
|
|
33
|
-
} = useValidate(rangeStart);
|
|
34
|
-
|
|
35
|
-
const {
|
|
36
|
-
currentDate: endDate,
|
|
37
|
-
value: endValue,
|
|
38
|
-
error: endError,
|
|
39
|
-
ref: endRef,
|
|
40
|
-
handleDateSelect: handleEndDateSelect,
|
|
41
|
-
handleDateValidation: handleEndDateValidation,
|
|
42
|
-
handleClearInput: handleEndClearInput,
|
|
43
|
-
} = useValidate(rangeEnd);
|
|
44
|
-
|
|
45
|
-
const handleDateSelectAndExternalUpdate = (
|
|
46
|
-
e: React.MouseEvent<HTMLButtonElement>,
|
|
47
|
-
date: Date
|
|
48
|
-
) => {
|
|
49
|
-
if (!startDate) {
|
|
50
|
-
handleStartDateSelect(date);
|
|
51
|
-
onChangeStart?.(date);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!endDate || e.ctrlKey) {
|
|
56
|
-
if (startDate && date < startDate) {
|
|
57
|
-
handleStartDateSelect(date);
|
|
58
|
-
handleEndDateSelect(startDate);
|
|
59
|
-
onChangeStart?.(date);
|
|
60
|
-
onChangeEnd?.(startDate);
|
|
61
|
-
} else {
|
|
62
|
-
handleEndDateSelect(date);
|
|
63
|
-
onChangeEnd?.(date);
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
handleStartDateSelect(date);
|
|
69
|
-
handleEndDateSelect();
|
|
70
|
-
onChangeStart?.(date);
|
|
71
|
-
onChangeEnd?.();
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const handleStartChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
75
|
-
const parsed = handleStartDateValidation(e.target.value);
|
|
76
|
-
if (!parsed) return;
|
|
77
|
-
onChangeStart?.(parsed);
|
|
78
|
-
if (endValue) handleEndDateValidation(endValue, parsed);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const handleStartKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
82
|
-
if (e.key !== 'Enter') return;
|
|
83
|
-
const parsed = handleStartDateValidation(e.currentTarget.value);
|
|
84
|
-
if (!parsed) return;
|
|
85
|
-
onChangeStart?.(parsed);
|
|
86
|
-
if (endValue) handleEndDateValidation(endValue, parsed);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const handleEndChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
90
|
-
const parsed = handleEndDateValidation(e.target.value, startDate);
|
|
91
|
-
if (parsed) onChangeEnd?.(parsed);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const handleEndKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
95
|
-
if (e.key !== 'Enter') return;
|
|
96
|
-
const parsed = handleEndDateValidation(e.currentTarget.value, startDate);
|
|
97
|
-
if (parsed) onChangeEnd?.(parsed);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const handleClearRange = () => {
|
|
101
|
-
handleStartClearInput();
|
|
102
|
-
handleEndClearInput();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<div className={styles.rangePicker}>
|
|
107
|
-
<div className={styles.inputs}>
|
|
108
|
-
<Input
|
|
109
|
-
isDateInput
|
|
110
|
-
label="From"
|
|
111
|
-
value={startValue}
|
|
112
|
-
ref={startRef as Ref<HTMLInputElement>}
|
|
113
|
-
placeholder="dd/mm/yyyy"
|
|
114
|
-
onBlur={handleStartChange}
|
|
115
|
-
onReset={handleStartClearInput}
|
|
116
|
-
onKeyDown={handleStartKeyDown}
|
|
117
|
-
error={startError}
|
|
118
|
-
/>
|
|
119
|
-
<Input
|
|
120
|
-
isDateInput
|
|
121
|
-
label="To"
|
|
122
|
-
value={endValue}
|
|
123
|
-
ref={endRef as Ref<HTMLInputElement>}
|
|
124
|
-
placeholder="dd/mm/yyyy"
|
|
125
|
-
onBlur={handleEndChange}
|
|
126
|
-
onReset={handleEndClearInput}
|
|
127
|
-
onKeyDown={handleEndKeyDown}
|
|
128
|
-
error={endError}
|
|
129
|
-
/>
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
<div className={styles.calendar}>
|
|
133
|
-
<BaseCalendar
|
|
134
|
-
monthDate={monthDate}
|
|
135
|
-
rangeStart={startDate}
|
|
136
|
-
rangeEnd={endDate}
|
|
137
|
-
onDateClick={handleDateSelectAndExternalUpdate}
|
|
138
|
-
{...props}
|
|
139
|
-
/>
|
|
140
|
-
<Clear onClick={handleClearRange} />
|
|
141
|
-
</div>
|
|
142
|
-
</div>
|
|
143
|
-
);
|
|
144
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
.rangePicker {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
padding: $gap-8;
|
|
5
|
-
|
|
6
|
-
@include themify-modules($themes) {
|
|
7
|
-
background-color: themed('background');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.calendar {
|
|
12
|
-
margin-top: 15px;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.inputs {
|
|
16
|
-
display: flex;
|
|
17
|
-
flex-direction: column;
|
|
18
|
-
gap: $gap-8;
|
|
19
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,62 +0,0 @@
|
|
|
1
|
-
.tasksManager {
|
|
2
|
-
min-width: 300px;
|
|
3
|
-
width: fit-content;
|
|
4
|
-
display: flex;
|
|
5
|
-
flex-direction: column;
|
|
6
|
-
gap: $gap-24;
|
|
7
|
-
max-height: 70%;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.tasks {
|
|
11
|
-
display: flex;
|
|
12
|
-
flex-direction: column;
|
|
13
|
-
gap: $gap-8;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.task {
|
|
17
|
-
display: flex;
|
|
18
|
-
gap: $gap-8;
|
|
19
|
-
justify-content: space-between;
|
|
20
|
-
align-items: center;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.checked {
|
|
24
|
-
@include themify-modules($themes) {
|
|
25
|
-
color: themed('disabled');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.title {
|
|
30
|
-
margin-right: auto;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.action {
|
|
34
|
-
border: none;
|
|
35
|
-
background-color: transparent;
|
|
36
|
-
|
|
37
|
-
@include themify-modules($themes) {
|
|
38
|
-
color: themed('text');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.delete {
|
|
43
|
-
@include themify-modules($themes) {
|
|
44
|
-
color: themed('accent');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.add {
|
|
49
|
-
@include themify-modules($themes) {
|
|
50
|
-
background-color: themed('middle-blue');
|
|
51
|
-
border-color: themed('border');
|
|
52
|
-
color: themed('white-color');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@include border;
|
|
56
|
-
|
|
57
|
-
border-radius: $radius-8;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.header {
|
|
61
|
-
font-size: $font-size-18;
|
|
62
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { Week } from '.';
|
|
3
|
-
|
|
4
|
-
const meta: Meta<typeof Week> = {
|
|
5
|
-
component: Week,
|
|
6
|
-
parameters: {
|
|
7
|
-
layout: 'centered',
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default meta;
|
|
12
|
-
|
|
13
|
-
const weekDaysArr = [
|
|
14
|
-
new Date(2026, 7, 25),
|
|
15
|
-
new Date(2026, 7, 26),
|
|
16
|
-
new Date(2026, 7, 27),
|
|
17
|
-
new Date(2026, 7, 28),
|
|
18
|
-
new Date(2026, 7, 29),
|
|
19
|
-
new Date(2026, 7, 30),
|
|
20
|
-
new Date(2026, 7, 31),
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const baseArgs = {
|
|
24
|
-
weekDays: weekDaysArr,
|
|
25
|
-
getIsCurrentMonth: () => {
|
|
26
|
-
return true;
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type Story = StoryObj<typeof Week>;
|
|
31
|
-
|
|
32
|
-
export const Default: Story = {
|
|
33
|
-
args: { ...baseArgs },
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const WithSelectedDate: Story = {
|
|
37
|
-
args: {
|
|
38
|
-
...baseArgs,
|
|
39
|
-
selectedDate: new Date(2026, 7, 28),
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const WithRange: Story = {
|
|
44
|
-
args: {
|
|
45
|
-
...baseArgs,
|
|
46
|
-
rangeStart: new Date(2026, 7, 26),
|
|
47
|
-
rangeEnd: new Date(2026, 7, 30),
|
|
48
|
-
},
|
|
49
|
-
};
|