-
Notifications
You must be signed in to change notification settings - Fork 32
/
ScheduleRecurring.js
178 lines (165 loc) · 6.14 KB
/
ScheduleRecurring.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
Copyright 2019 Iguazio Systems Ltd.
Licensed under the Apache License, Version 2.0 (the "License") with
an addition restriction as set forth herein. You may not use this
file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
In addition, you may not use the software for any purposes that are
illegal under applicable law, and the grant of the foregoing license
under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import React from 'react'
import PropTypes from 'prop-types'
import RangeInput from '../../common/RangeInput/RangeInput'
import Select from '../../common/Select/Select'
import DatePicker from '../../common/DatePicker/DatePicker'
import TimePicker from '../../common/TimePicker/TimePicker'
import { scheduleActionType } from '../../components/ScheduleJob/recurringReducer'
import { selectOptions } from './scheduleRecurring.util'
import './scheduleRecurring.scss'
const ScheduleRecurring = ({ daysOfWeek, handleDaysOfWeek, recurringDispatch, recurringState }) => {
const {
scheduleRepeat: { activeOption: scheduleRepeatActiveOption, week },
scheduleRepeatEnd: { activeOption: scheduleRepeatEndActiveOption, occurrences, date }
} = recurringState
const handleScheduleRepeatChange = (value, activeOption) => {
const selectedOption = activeOption ?? scheduleRepeatActiveOption
recurringDispatch({
type:
selectedOption === 'minute'
? scheduleActionType.SCHEDULE_REPEAT_MINUTE
: selectedOption === 'hour'
? scheduleActionType.SCHEDULE_REPEAT_HOUR
: null,
payload: parseInt(value)
})
}
return (
<div className="recurring-container">
<p>
Note: all times are interpreted in UTC timezone. <br />
The first day of the week (0) is <b>Monday</b>, and not Sunday.
</p>
<div className="repeat_container">
<Select
density="chunky"
onClick={item => {
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_ACTIVE_OPTION,
payload: item
})
}}
options={selectOptions.repeatInterval}
selectedId={scheduleRepeatActiveOption}
/>
{scheduleRepeatActiveOption === 'week' && (
<div className="schedule-repeat schedule-repeat-week">
{daysOfWeek.map(day => (
<span
className={`schedule-repeat-week_day ${week.days.includes(day.id) && 'active'}`}
key={day.id}
onClick={() => handleDaysOfWeek(day.id)}
>
{day.label}
</span>
))}
</div>
)}
{['minute', 'hour'].includes(scheduleRepeatActiveOption) && (
<div className="schedule-repeat">
<Select
density="chunky"
label="Every"
onClick={option => handleScheduleRepeatChange(option, null)}
options={selectOptions[scheduleRepeatActiveOption]}
selectedId={
selectOptions[scheduleRepeatActiveOption].find(
option =>
option.id ===
recurringState.scheduleRepeat[scheduleRepeatActiveOption].toString()
)?.id
}
/>
</div>
)}
<span className="schedule-repeat-text">
{scheduleRepeatActiveOption === 'minute'
? 'minutes'
: scheduleRepeatActiveOption === 'hour'
? 'hours at minute 0 past the hour'
: scheduleRepeatActiveOption === 'month'
? 'on the 1st day in every month at'
: 'at'}
</span>
{['day', 'month', 'week'].includes(scheduleRepeatActiveOption) && (
<TimePicker
hideLabel
value={recurringState.scheduleRepeat[scheduleRepeatActiveOption].time}
onChange={value => {
recurringDispatch({
type:
scheduleRepeatActiveOption === 'week'
? scheduleActionType.SCHEDULE_REPEAT_WEEK_TIME
: scheduleRepeatActiveOption === 'day'
? scheduleActionType.SCHEDULE_REPEAT_DAY_TIME
: scheduleActionType.SCHEDULE_REPEAT_MONTH_TIME,
payload: value
})
}}
/>
)}
</div>
{/* <span>Ends</span> */}
<div className="repeat_end_container">
<Select
density="chunky"
onClick={item =>
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_END_ACTIVE_OPTION,
payload: item
})
}
options={selectOptions.repeatEnd}
selectedId={scheduleRepeatEndActiveOption}
/>
{scheduleRepeatEndActiveOption === 'onDate' && (
<DatePicker
date={date}
onChange={item =>
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_END_DATE,
payload: item
})
}
/>
)}
{scheduleRepeatEndActiveOption === 'after' && (
<RangeInput
labelType="infoLabel"
label={occurrences.length < 10 ? 'occurrences' : ''}
onChange={item =>
recurringDispatch({
type: scheduleActionType.SCHEDULE_REPEAT_END_OCCURRENCES,
payload: item.toString()
})
}
value={occurrences.toString()}
/>
)}
</div>
</div>
)
}
ScheduleRecurring.propTypes = {
daysOfWeek: PropTypes.array.isRequired,
handleDaysOfWeek: PropTypes.func.isRequired,
recurringDispatch: PropTypes.func.isRequired,
recurringState: PropTypes.shape({}).isRequired
}
export default React.memo(ScheduleRecurring)