-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): added configuration of notification schedule to configura…
…tion
- Loading branch information
Alvaro Jose
committed
Jul 28, 2023
1 parent
0de7ca0
commit 8802d12
Showing
8 changed files
with
362 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { useState } from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import Select from '@mui/material/Select'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import { NotificationConfiguration } from '../../../types/NotificationEnabled'; | ||
import TimePicker from 'react-time-picker'; | ||
import './style.css'; | ||
|
||
export const NotificationSchedule = ({ schedules, translate, updateSchedules }: any) => { | ||
const [localSchedule, setLocalSchedule] = useState(schedules); | ||
const update = (fieldName: string, index: number, value: any) => { | ||
console.log(value); | ||
setLocalSchedule( | ||
localSchedule.map((schedule: NotificationConfiguration, currentIndex: number) => | ||
currentIndex != index ? schedule : { ...schedule, [fieldName]: value } | ||
) | ||
); | ||
}; | ||
return ( | ||
<> | ||
{localSchedule.map((schedule: NotificationConfiguration, index: number) => ( | ||
<Stack | ||
spacing={1} | ||
justifyContent="space-between" | ||
direction="row" | ||
margin={'1rem 0'} | ||
key={`notification-schedule-${index}`} | ||
> | ||
<Select | ||
sx={{ | ||
flexBasis: '25%', | ||
}} | ||
value={schedule.weekday} | ||
label={translate('Weekday')} | ||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => update('weekday', index, event.target.value)} | ||
> | ||
<MenuItem value={1}>{translate('Monday')}</MenuItem> | ||
<MenuItem value={2}>{translate('Tuesday')}</MenuItem> | ||
<MenuItem value={3}>{translate('Wednesday')}</MenuItem> | ||
<MenuItem value={4}>{translate('Thursday')}</MenuItem> | ||
<MenuItem value={5}>{translate('Friday')}</MenuItem> | ||
<MenuItem value={6}>{translate('Saturday')}</MenuItem> | ||
<MenuItem value={0}>{translate('Sunday')}</MenuItem> | ||
</Select> | ||
<TimePicker | ||
disableClock | ||
clearIcon={null} | ||
value={`${schedule.enableTime.hour}:${schedule.enableTime.minute}`} | ||
onChange={(value) => | ||
update('enableTime', index, { hour: Number(value.substring(0, 2)), minute: Number(value.substring(3)) }) | ||
} | ||
/> | ||
<TimePicker | ||
disableClock | ||
clearIcon={null} | ||
value={`${schedule.disableTime.hour}:${schedule.disableTime.minute}`} | ||
onChange={(value) => | ||
update('disableTime', index, { hour: Number(value.substring(0, 2)), minute: Number(value.substring(3)) }) | ||
} | ||
/> | ||
<Button | ||
variant="contained" | ||
sx={{ | ||
flexBasis: '20%', | ||
}} | ||
onClick={() => | ||
setLocalSchedule(localSchedule.filter((_: any, currentIndex: number) => currentIndex != index)) | ||
} | ||
> | ||
{translate('Delete')} | ||
</Button> | ||
</Stack> | ||
))} | ||
<Stack spacing={2} direction="row"> | ||
<Button | ||
variant="contained" | ||
onClick={() => | ||
setLocalSchedule([ | ||
...localSchedule, | ||
{ weekday: 0, enableTime: { hour: 0, minute: 0 }, disableTime: { hour: 23, minute: 59 } }, | ||
]) | ||
} | ||
sx={{ | ||
flexBasis: '50%', | ||
}} | ||
> | ||
{translate('Add')} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
sx={{ | ||
flexBasis: '50%', | ||
}} | ||
onClick={() => updateSchedules(localSchedule)} | ||
> | ||
{translate('Save')} | ||
</Button> | ||
</Stack> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
.react-time-picker { | ||
display: inline-flex; | ||
position: relative; | ||
} | ||
|
||
.react-time-picker, | ||
.react-time-picker *, | ||
.react-time-picker *:before, | ||
.react-time-picker *:after { | ||
-moz-box-sizing: border-box; | ||
-webkit-box-sizing: border-box; | ||
box-sizing: border-box; | ||
} | ||
|
||
.react-time-picker--disabled { | ||
background-color: #f0f0f0; | ||
color: #6d6d6d; | ||
} | ||
|
||
.react-time-picker__wrapper { | ||
display: flex; | ||
flex-grow: 1; | ||
flex-shrink: 0; | ||
border: thin solid gray; | ||
} | ||
|
||
.react-time-picker__inputGroup { | ||
min-width: calc((4px * 3) + 0.217em * 2); | ||
flex-grow: 1; | ||
padding: 0 20px; | ||
box-sizing: content-box; | ||
} | ||
|
||
.react-time-picker__inputGroup__divider { | ||
padding: 1px 0; | ||
white-space: pre; | ||
} | ||
|
||
.react-time-picker__inputGroup__divider, | ||
.react-time-picker__inputGroup__leadingZero { | ||
display: inline-block; | ||
} | ||
|
||
.react-time-picker__inputGroup__input { | ||
min-width: 0.54em; | ||
height: 100%; | ||
position: relative; | ||
padding: 0 1px; | ||
border: 0; | ||
background: none; | ||
color: currentColor; | ||
font: inherit; | ||
box-sizing: content-box; | ||
-webkit-appearance: textfield; | ||
-moz-appearance: textfield; | ||
appearance: textfield; | ||
} | ||
|
||
.react-time-picker__inputGroup__input::-webkit-outer-spin-button, | ||
.react-time-picker__inputGroup__input::-webkit-inner-spin-button { | ||
-webkit-appearance: none; | ||
-moz-appearance: none; | ||
appearance: none; | ||
margin: 0; | ||
} | ||
|
||
.react-time-picker__inputGroup__input:invalid { | ||
background: rgba(255, 0, 0, 0.1); | ||
} | ||
|
||
.react-time-picker__inputGroup__amPm { | ||
font: inherit; | ||
-webkit-appearance: menulist; | ||
-moz-appearance: menulist; | ||
appearance: menulist; | ||
} | ||
|
||
.react-time-picker__button { | ||
border: 0; | ||
background: transparent; | ||
padding: 0; | ||
} | ||
|
||
.react-time-picker__button:enabled { | ||
cursor: pointer; | ||
} | ||
|
||
.react-time-picker__button:enabled:hover .react-time-picker__button__icon, | ||
.react-time-picker__button:enabled:focus .react-time-picker__button__icon { | ||
stroke: #0078d7; | ||
} | ||
|
||
.react-time-picker__button:disabled .react-time-picker__button__icon { | ||
stroke: #6d6d6d; | ||
} | ||
|
||
.react-time-picker__button svg { | ||
display: inherit; | ||
} | ||
|
||
.react-time-picker__clock { | ||
width: 200px; | ||
height: 200px; | ||
max-width: 100vw; | ||
padding: 25px; | ||
background-color: white; | ||
border: thin solid #a0a096; | ||
z-index: 1; | ||
} | ||
|
||
.react-time-picker__clock--closed { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.