Skip to content

Commit

Permalink
Settings for advances notifications openintents#75
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardohofling committed Feb 18, 2019
1 parent a518fa4 commit ef42751
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/components/event-details/EventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class EventDetails extends Component {
loadGuestList,
addingConferencing,
removingConferencing,
richNofifExclude,
} = this.props
const { GuestList } = views
const {
Expand Down Expand Up @@ -284,6 +285,19 @@ class EventDetails extends Component {
)
}

function getLabelForReminder() {
var isEnriched = false
let array = guestsStringToArray(eventDetail.guests)

array.forEach(e => {
if (!richNofifExclude.includes(e)) {
isEnriched = true
}
})

return isEnriched ? 'Enriched Notification' : 'Set Reminder'
}

return (
<Modal show onHide={handleClose}>
<Modal.Header closeButton>
Expand Down Expand Up @@ -359,7 +373,7 @@ class EventDetails extends Component {
<Row>
<Col xs={12}>
<div className="reminder-container">
<label> Set Reminder </label>
<label> {getLabelForReminder()} </label>

<div className="reminder-group">
<input
Expand Down
70 changes: 70 additions & 0 deletions src/components/settings/Notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { Component } from 'react'
import { Form, Card } from 'react-bootstrap'

const guestsStringToArray = function(guestsString) {
if (!guestsString || !guestsString.length) {
return []
}
const guests = guestsString.split(/[,\s]+/g)
return guests.filter(g => g.length > 0).map(g => g.toLowerCase())
}

export default class Notifications extends Component {
constructor(props) {
super(props)

const { richNotifEnabled, richNofifExclude } = this.props

this.state = {
richNofifExclude: richNofifExclude ? richNofifExclude.join(',') : '',
richNotifEnabled,
}
}
handleEnrichedNotificationsChange = event => {
const { enableRichNotif, disableRichNotif } = this.props
if (event.target.checked) {
enableRichNotif()
} else {
disableRichNotif()
}
}

handleExcludedGuestsChange = event => {
const { saveRichNotifExcludeGuests } = this.props
saveRichNotifExcludeGuests(guestsStringToArray(event.target.value))
}

renderBody = () => {
const { richNotifEnabled, richNofifExclude } = this.state
return (
<Form>
<Form.Group controlId="formBasicChecbox">
<Form.Check
type="checkbox"
label="Enable Enriched Notifications"
defaultChecked={richNotifEnabled}
onChange={this.handleEnrichedNotificationsChange}
/>
</Form.Group>
<Form.Group controlId="formEcludedGuests">
<Form.Label>Excluded guests</Form.Label>
<Form.Control
type="email"
defaultValue={richNofifExclude}
placeholder="bob.id, alice.id.blockstack, ..."
onBlur={this.handleExcludedGuestsChange}
/>
</Form.Group>
</Form>
)
}

render() {
return (
<Card style={{}}>
<Card.Header>Enriched Notifications</Card.Header>
<Card.Body>{this.renderBody()}</Card.Body>
</Card>
)
}
}
27 changes: 26 additions & 1 deletion src/components/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { Button } from 'react-bootstrap'

import Calendars from './Calendars'
import Contacts from './Contacts'
import Notifications from './Notifications'

class SettingsPage extends Component {
render() {
const { CalendarsContent, ContactsContent, handleHide } = this.props
const {
CalendarsContent,
ContactsContent,
NotificationsContent,
handleHide,
} = this.props
return (
<div
className="bodyContainer"
Expand All @@ -16,6 +22,7 @@ class SettingsPage extends Component {

{CalendarsContent}
{ContactsContent}
{NotificationsContent}
<Button onClick={handleHide}>Done</Button>
</div>
)
Expand All @@ -41,6 +48,11 @@ export default class Settings extends Component {
user,
verifyNewCalendar,
verifiedNewCalendarData,
richNotifEnabled,
richNofifExclude,
enableRichNotif,
disableRichNotif,
saveRichNotifExcludeGuests,
} = this.props
const CalendarsContent = (
<div>
Expand Down Expand Up @@ -72,10 +84,23 @@ export default class Settings extends Component {
</div>
)

const NotificationsContent = (
<div>
<Notifications
richNotifEnabled={richNotifEnabled}
richNofifExclude={richNofifExclude}
enableRichNotif={enableRichNotif}
disableRichNotif={disableRichNotif}
saveRichNotifExcludeGuests={saveRichNotifExcludeGuests}
/>
</div>
)

return (
<SettingsPage
CalendarsContent={CalendarsContent}
ContactsContent={ContactsContent}
NotificationsContent={NotificationsContent}
handleHide={handleHide}
/>
)
Expand Down
4 changes: 4 additions & 0 deletions src/flow/connect/connectEventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default connect(
const inviteSuccess = state.events.inviteSuccess
const addingConferencing = state.events.addingConferencing
const removingConferencing = state.events.removingConferencing
const richNotifEnabled = state.events.richNotifEnabled
const richNofifExclude = state.events.richNofifExclude

return {
inviteError,
Expand All @@ -45,6 +47,8 @@ export default connect(
eventType: currentEventType,
addingConferencing,
removingConferencing,
richNotifEnabled,
richNofifExclude,
}
},
(dispatch, redux) => {
Expand Down
16 changes: 16 additions & 0 deletions src/flow/connect/connectSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
showAllCalendars,
verifyNewCalendar,
clearVerifyCalendar,
enableRichNotif,
disableRichNotif,
saveRichNotifExcludeGuests,
} from '../store/event/eventActionLazy'

import {
Expand All @@ -26,13 +29,17 @@ export default connect(
const calendars = state.events.calendars
const user = state.auth.user
const verifiedNewCalendarData = state.events.verifiedNewCalendarData
const richNotifEnabled = state.events.richNotifEnabled
const richNofifExclude = state.events.richNofifExclude
return {
show,
contacts,
calendars,
addCalendarUrl,
user,
verifiedNewCalendarData,
richNotifEnabled,
richNofifExclude,
}
},
(dispatch, redux) => {
Expand Down Expand Up @@ -85,6 +92,15 @@ export default connect(
verifyNewCalendar: calendar => {
dispatch(verifyNewCalendar(calendar))
},
enableRichNotif: isActive => {
dispatch(enableRichNotif(isActive))
},
disableRichNotif: isActive => {
dispatch(disableRichNotif())
},
saveRichNotifExcludeGuests: guests => {
dispatch(saveRichNotifExcludeGuests(guests))
},
}
}
)
3 changes: 3 additions & 0 deletions src/flow/store/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const SHOW_ALL_CALENDARS = 'settings.SHOW_ALL_CALENDARS'
export const SHOW_SETTINGS_ADD_CALENDAR = 'settings.SHOW_SETTINGS_ADD_CALENDAR'
export const SHOW_INSTRUCTIONS = 'settings.SHOW_INSTRUCTIONS'
export const SHOW_FILES = 'settings.SHOW_FILES'
export const SET_RICH_NOTIF_ENABLED = 'settings.SET_RICH_NOTIF_ENABLED'
export const SET_RICH_NOTIF_EXCLUDE_GUESTS =
'settings.SET_RICH_NOTIF_EXCLUDE_GUESTS'

// FILES
export const SET_FILES = 'files.SET_FILES'
Expand Down
36 changes: 36 additions & 0 deletions src/flow/store/event/eventActionLazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
CREATE_CONFERENCING_ROOM,
REMOVE_CONFERENCING_ROOM,
VERIFY_NEW_CALENDAR,
SET_RICH_NOTIF_ENABLED,
SET_RICH_NOTIF_EXCLUDE_GUESTS,
} from '../ActionTypes'

import { defaultEvents } from '../../io/eventDefaults'
Expand Down Expand Up @@ -200,6 +202,14 @@ export function showInstructionsAction(show) {
return { type: SHOW_INSTRUCTIONS, payload: { show } }
}

function setRichNotifEnabled(isEnabled) {
return { type: SET_RICH_NOTIF_ENABLED, payload: { isEnabled } }
}

function setRichNotifExcludeGuests(guests) {
return { type: SET_RICH_NOTIF_EXCLUDE_GUESTS, payload: { guests } }
}

export function initializePreferences() {
return async (dispatch, getState) => {
fetchPreferences().then(preferences => {
Expand All @@ -210,6 +220,8 @@ export function initializePreferences() {
: true
)
)
dispatch(setRichNotifEnabled(preferences.richNotifEnabled))
dispatch(setRichNotifExcludeGuests(preferences.richNofifExclude))
})
}
}
Expand All @@ -224,6 +236,30 @@ export function hideInstructions() {
}
}

export function enableRichNotif() {
console.log('enableRichNotif')
return async (dispatch, getState) => {
savePreferences({ richNotifEnabled: true })
dispatch(setRichNotifEnabled(true))
}
}

export function disableRichNotif() {
console.log('disableRichNotif')
return async (dispatch, getState) => {
savePreferences({ richNotifEnabled: false })
dispatch(setRichNotifEnabled(false))
}
}

export function saveRichNotifExcludeGuests(guests) {
console.log('saveRichNotifExcludeGuests', guests)
return async (dispatch, getState) => {
savePreferences({ richNofifExclude: guests })
dispatch(setRichNotifExcludeGuests(guests))
}
}

// ################
// Events
// ################
Expand Down
14 changes: 14 additions & 0 deletions src/flow/store/event/eventReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
REMOVE_CONFERENCING_ROOM,
VERIFY_NEW_CALENDAR,
SHOW_FILES,
SET_RICH_NOTIF_ENABLED,
SET_RICH_NOTIF_EXCLUDE_GUESTS,
} from '../ActionTypes'

let initialState = {
Expand Down Expand Up @@ -244,6 +246,18 @@ export default function reduce(state = initialState, action = {}) {
verifiedNewCalendarData: payload,
}
break
case SET_RICH_NOTIF_ENABLED:
newState = {
...state,
richNotifEnabled: payload.isEnabled,
}
break
case SET_RICH_NOTIF_EXCLUDE_GUESTS:
newState = {
...state,
richNofifExclude: payload.guests,
}
break

default:
newState = state
Expand Down

0 comments on commit ef42751

Please sign in to comment.