diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-05 13:43:56 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-07-05 17:12:56 +0200 |
| commit | 6403d3b357a247c7601edf40bcd4e06f5d85addf (patch) | |
| tree | 91cae2e40a9fee389a041bb85d45a510ee687ef1 /app | |
| parent | f0ac8a80c03a77fa325e2ef48b3a662692e4bbc2 (diff) | |
| download | mullvadvpn-6403d3b357a247c7601edf40bcd4e06f5d85addf.tar.xz mullvadvpn-6403d3b357a247c7601edf40bcd4e06f5d85addf.zip | |
Add support state in redux store
Diffstat (limited to 'app')
| -rw-r--r-- | app/redux/store.js | 11 | ||||
| -rw-r--r-- | app/redux/support/actions.js | 32 | ||||
| -rw-r--r-- | app/redux/support/reducers.js | 37 |
3 files changed, 78 insertions, 2 deletions
diff --git a/app/redux/store.js b/app/redux/store.js index 9e15b3a325..0070248099 100644 --- a/app/redux/store.js +++ b/app/redux/store.js @@ -9,24 +9,29 @@ import connection from './connection/reducers'; import connectionActions from './connection/actions'; import settings from './settings/reducers'; import settingsActions from './settings/actions'; +import support from './support/reducers'; +import supportActions from './support/actions'; import type { Store } from 'redux'; import type { History } from 'history'; import type { AccountReduxState } from './account/reducers'; import type { ConnectionReduxState } from './connection/reducers'; import type { SettingsReduxState } from './settings/reducers'; +import type { SupportReduxState } from './support/reducers'; -import type { ConnectionAction } from './connection/actions'; import type { AccountAction } from './account/actions'; +import type { ConnectionAction } from './connection/actions'; import type { SettingsAction } from './settings/actions'; +import type { SupportAction } from './support/actions'; export type ReduxState = { account: AccountReduxState, connection: ConnectionReduxState, settings: SettingsReduxState, + support: SupportReduxState, }; -export type ReduxAction = AccountAction | SettingsAction | ConnectionAction; +export type ReduxAction = AccountAction | ConnectionAction | SettingsAction | SupportAction; export type ReduxStore = Store<ReduxState, ReduxAction, ReduxDispatch>; export type ReduxGetState = () => ReduxState; export type ReduxDispatch = (action: ReduxAction | ReduxThunk) => any; @@ -42,6 +47,7 @@ export default function configureStore( ...accountActions, ...connectionActions, ...settingsActions, + ...supportActions, pushRoute: (route) => push(route), replaceRoute: (route) => replace(route), }; @@ -50,6 +56,7 @@ export default function configureStore( account, connection, settings, + support, router: routerReducer, }; diff --git a/app/redux/support/actions.js b/app/redux/support/actions.js new file mode 100644 index 0000000000..d81fd19c0d --- /dev/null +++ b/app/redux/support/actions.js @@ -0,0 +1,32 @@ +// @flow + +export type SupportReportForm = { + email: string, + message: string, +}; + +export type KeepReportFormAction = { + type: 'SAVE_REPORT_FORM', + form: SupportReportForm, +}; + +export type ClearReportFormAction = { + type: 'CLEAR_REPORT_FORM', +}; + +export type SupportAction = KeepReportFormAction | ClearReportFormAction; + +function saveReportForm(form: SupportReportForm): KeepReportFormAction { + return { + type: 'SAVE_REPORT_FORM', + form, + }; +} + +function clearReportForm(): ClearReportFormAction { + return { + type: 'CLEAR_REPORT_FORM', + }; +} + +export default { saveReportForm, clearReportForm }; diff --git a/app/redux/support/reducers.js b/app/redux/support/reducers.js new file mode 100644 index 0000000000..f885f22dd5 --- /dev/null +++ b/app/redux/support/reducers.js @@ -0,0 +1,37 @@ +// @flow + +import type { ReduxAction } from '../store'; + +export type SupportReduxState = { + email: string, + message: string, +}; + +const initialState: SupportReduxState = { + email: '', + message: '', +}; + +export default function( + state: SupportReduxState = initialState, + action: ReduxAction, +): SupportReduxState { + switch (action.type) { + case 'SAVE_REPORT_FORM': + return { + ...state, + email: action.form.email, + message: action.form.message, + }; + + case 'CLEAR_REPORT_FORM': + return { + ...state, + email: '', + message: '', + }; + + default: + return state; + } +} |
