|
|
|
@ -44,52 +44,54 @@ const STORE_NAME = 'features/calendar-sync'; |
|
|
|
|
* runtime value to see if we need to re-request the calendar permission from |
|
|
|
|
* the user. |
|
|
|
|
*/ |
|
|
|
|
isCalendarEnabled() |
|
|
|
|
&& PersistenceRegistry.register(STORE_NAME, { |
|
|
|
|
integrationType: true, |
|
|
|
|
msAuthState: true |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
isCalendarEnabled() |
|
|
|
|
&& ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => { |
|
|
|
|
switch (action.type) { |
|
|
|
|
case CLEAR_CALENDAR_INTEGRATION: |
|
|
|
|
return DEFAULT_STATE; |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_AUTH_STATE: { |
|
|
|
|
if (!action.msAuthState) { |
|
|
|
|
// received request to delete the state
|
|
|
|
|
return set(state, 'msAuthState', undefined); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return set(state, 'msAuthState', { |
|
|
|
|
...state.msAuthState, |
|
|
|
|
...action.msAuthState |
|
|
|
|
}); |
|
|
|
|
PersistenceRegistry.register(STORE_NAME, { |
|
|
|
|
integrationType: true, |
|
|
|
|
msAuthState: true |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => { |
|
|
|
|
if (!isCalendarEnabled(state)) { |
|
|
|
|
return state; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (action.type) { |
|
|
|
|
case CLEAR_CALENDAR_INTEGRATION: |
|
|
|
|
return DEFAULT_STATE; |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_AUTH_STATE: { |
|
|
|
|
if (!action.msAuthState) { |
|
|
|
|
// received request to delete the state
|
|
|
|
|
return set(state, 'msAuthState', undefined); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_AUTHORIZATION: |
|
|
|
|
return set(state, 'authorization', action.authorization); |
|
|
|
|
return set(state, 'msAuthState', { |
|
|
|
|
...state.msAuthState, |
|
|
|
|
...action.msAuthState |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_ERROR: |
|
|
|
|
return set(state, 'error', action.error); |
|
|
|
|
case SET_CALENDAR_AUTHORIZATION: |
|
|
|
|
return set(state, 'authorization', action.authorization); |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_EVENTS: |
|
|
|
|
return set(state, 'events', action.events); |
|
|
|
|
case SET_CALENDAR_ERROR: |
|
|
|
|
return set(state, 'error', action.error); |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_INTEGRATION: |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
|
integrationReady: action.integrationReady, |
|
|
|
|
integrationType: action.integrationType |
|
|
|
|
}; |
|
|
|
|
case SET_CALENDAR_EVENTS: |
|
|
|
|
return set(state, 'events', action.events); |
|
|
|
|
|
|
|
|
|
case SET_CALENDAR_PROFILE_EMAIL: |
|
|
|
|
return set(state, 'profileEmail', action.email); |
|
|
|
|
case SET_CALENDAR_INTEGRATION: |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
|
integrationReady: action.integrationReady, |
|
|
|
|
integrationType: action.integrationType |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
case SET_LOADING_CALENDAR_EVENTS: |
|
|
|
|
return set(state, 'isLoadingEvents', action.isLoadingEvents); |
|
|
|
|
} |
|
|
|
|
case SET_CALENDAR_PROFILE_EMAIL: |
|
|
|
|
return set(state, 'profileEmail', action.email); |
|
|
|
|
|
|
|
|
|
return state; |
|
|
|
|
}); |
|
|
|
|
case SET_LOADING_CALENDAR_EVENTS: |
|
|
|
|
return set(state, 'isLoadingEvents', action.isLoadingEvents); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return state; |
|
|
|
|
}); |
|
|
|
|