2018-09-13 18:28:23 +01:00
|
|
|
import { createAction, handleActions } from 'redux-actions';
|
|
|
|
|
|
|
|
import { createTypes, createAsyncTypes } from '../../utils/createTypes';
|
2019-02-26 19:59:57 +05:30
|
|
|
import { createDangerZoneSaga } from './danger-zone-saga';
|
2018-09-13 18:28:23 +01:00
|
|
|
import { createSettingsSagas } from './settings-sagas';
|
2018-09-20 10:22:45 +01:00
|
|
|
import { createUpdateMyEmailSaga } from './update-email-saga';
|
2018-09-13 18:28:23 +01:00
|
|
|
|
2019-03-25 09:04:17 +03:00
|
|
|
// prettier-ignore
|
2019-03-28 11:18:26 +03:00
|
|
|
import { createUpdateLegacyCertSaga } from
|
2019-03-25 09:04:17 +03:00
|
|
|
'./update-legacy-certificate-saga';
|
|
|
|
|
2018-11-29 12:12:15 +00:00
|
|
|
export const ns = 'settings';
|
2018-09-13 18:28:23 +01:00
|
|
|
|
|
|
|
const defaultFetchState = {
|
|
|
|
pending: false,
|
|
|
|
complete: false,
|
|
|
|
errored: false,
|
|
|
|
error: null
|
|
|
|
};
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
usernameValidation: {
|
|
|
|
isValidUsername: false,
|
|
|
|
fetchState: { ...defaultFetchState }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const types = createTypes(
|
|
|
|
[
|
|
|
|
...createAsyncTypes('validateUsername'),
|
2018-09-14 13:18:31 +01:00
|
|
|
...createAsyncTypes('submitNewAbout'),
|
2018-09-14 14:00:43 +01:00
|
|
|
...createAsyncTypes('submitNewUsername'),
|
2018-09-20 10:22:45 +01:00
|
|
|
...createAsyncTypes('updateMyEmail'),
|
2019-03-28 11:18:26 +03:00
|
|
|
...createAsyncTypes('updateLegacyCert'),
|
2018-09-18 09:36:20 +01:00
|
|
|
...createAsyncTypes('updateUserFlag'),
|
2018-09-25 12:51:17 +01:00
|
|
|
...createAsyncTypes('submitProfileUI'),
|
2019-02-21 21:47:22 +05:30
|
|
|
...createAsyncTypes('verifyCert'),
|
|
|
|
...createAsyncTypes('resetProgress'),
|
|
|
|
...createAsyncTypes('deleteAccount')
|
2018-09-13 18:28:23 +01:00
|
|
|
],
|
|
|
|
ns
|
|
|
|
);
|
2018-09-20 10:22:45 +01:00
|
|
|
|
|
|
|
export const sagas = [
|
|
|
|
...createSettingsSagas(types),
|
2019-02-26 19:59:57 +05:30
|
|
|
...createUpdateMyEmailSaga(types),
|
2019-03-25 09:04:17 +03:00
|
|
|
...createDangerZoneSaga(types),
|
2019-03-28 11:18:26 +03:00
|
|
|
...createUpdateLegacyCertSaga(types)
|
2018-09-20 10:22:45 +01:00
|
|
|
];
|
|
|
|
|
2018-09-14 14:00:43 +01:00
|
|
|
const checkForSuccessPayload = ({ type, payload }) =>
|
|
|
|
type === 'success' ? payload : null;
|
2018-09-13 18:28:23 +01:00
|
|
|
|
2018-09-14 13:18:31 +01:00
|
|
|
export const submitNewAbout = createAction(types.submitNewAbout);
|
|
|
|
export const submitNewAboutComplete = createAction(
|
|
|
|
types.submitNewAboutComplete,
|
2018-09-14 14:00:43 +01:00
|
|
|
checkForSuccessPayload
|
2018-09-14 13:18:31 +01:00
|
|
|
);
|
|
|
|
export const submitNewAboutError = createAction(types.submitNewAboutError);
|
|
|
|
|
2018-09-13 18:28:23 +01:00
|
|
|
export const submitNewUsername = createAction(types.submitNewUsername);
|
|
|
|
export const submitNewUsernameComplete = createAction(
|
|
|
|
types.submitNewUsernameComplete,
|
|
|
|
({ type, username }) => (type === 'success' ? username : null)
|
|
|
|
);
|
|
|
|
export const submitNewUsernameError = createAction(
|
|
|
|
types.submitNewUsernameError
|
|
|
|
);
|
|
|
|
|
2018-09-18 09:36:20 +01:00
|
|
|
export const submitProfileUI = createAction(types.submitProfileUI);
|
|
|
|
export const submitProfileUIComplete = createAction(
|
|
|
|
types.submitProfileUIComplete,
|
|
|
|
checkForSuccessPayload
|
|
|
|
);
|
|
|
|
export const submitProfileUIError = createAction(types.submitProfileUIError);
|
|
|
|
|
2018-09-20 10:22:45 +01:00
|
|
|
export const updateMyEmail = createAction(types.updateMyEmail);
|
|
|
|
export const updateMyEmailComplete = createAction(types.updateMyEmailComplete);
|
|
|
|
export const updateMyEmailError = createAction(types.updateMyEmailError);
|
|
|
|
|
2019-03-28 11:18:26 +03:00
|
|
|
export const updateLegacyCert = createAction(types.updateLegacyCert);
|
|
|
|
export const updateLegacyCertComplete = createAction(
|
|
|
|
types.updateLegacyCertComplete
|
2019-03-25 09:04:17 +03:00
|
|
|
);
|
2019-03-28 11:18:26 +03:00
|
|
|
export const updateLegacyCertError = createAction(types.updateLegacyCertError);
|
2019-03-25 09:04:17 +03:00
|
|
|
|
2018-09-14 14:00:43 +01:00
|
|
|
export const updateUserFlag = createAction(types.updateUserFlag);
|
|
|
|
export const updateUserFlagComplete = createAction(
|
|
|
|
types.updateUserFlagComplete,
|
|
|
|
checkForSuccessPayload
|
|
|
|
);
|
|
|
|
export const updateUserFlagError = createAction(types.updateUserFlagError);
|
|
|
|
|
2018-09-13 18:28:23 +01:00
|
|
|
export const validateUsername = createAction(types.validateUsername);
|
|
|
|
export const validateUsernameComplete = createAction(
|
|
|
|
types.validateUsernameComplete
|
|
|
|
);
|
|
|
|
export const validateUsernameError = createAction(types.validateUsernameError);
|
|
|
|
|
2018-09-25 12:51:17 +01:00
|
|
|
export const verifyCert = createAction(types.verifyCert);
|
|
|
|
export const verifyCertComplete = createAction(
|
|
|
|
types.verifyCertComplete,
|
|
|
|
checkForSuccessPayload
|
|
|
|
);
|
|
|
|
export const verifyCertError = createAction(types.verifyCertError);
|
|
|
|
|
2019-02-21 21:47:22 +05:30
|
|
|
export const resetProgress = createAction(types.resetProgress);
|
|
|
|
export const resetProgressError = createAction(types.resetProgressError);
|
|
|
|
|
|
|
|
export const deleteAccount = createAction(types.deleteAccount);
|
|
|
|
export const deleteAccountError = createAction(types.deleteAccountError);
|
|
|
|
|
2018-09-13 18:28:23 +01:00
|
|
|
export const usernameValidationSelector = state => state[ns].usernameValidation;
|
|
|
|
|
|
|
|
export const reducer = handleActions(
|
|
|
|
{
|
|
|
|
[types.submitNewUsernameComplete]: state => ({
|
|
|
|
...state,
|
|
|
|
usernameValidation: { ...initialState.usernameValidation }
|
|
|
|
}),
|
|
|
|
[types.validateUsername]: state => ({
|
|
|
|
...state,
|
|
|
|
usernameValidation: {
|
|
|
|
...state.usernameValidation,
|
|
|
|
isValidUsername: false,
|
|
|
|
fetchState: { ...defaultFetchState, pending: true }
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
[types.validateUsernameComplete]: (state, { payload }) => ({
|
|
|
|
...state,
|
|
|
|
usernameValidation: {
|
|
|
|
...state.usernameValidation,
|
|
|
|
isValidUsername: !payload,
|
|
|
|
fetchState: { ...defaultFetchState, pending: false, complete: true }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
initialState
|
|
|
|
);
|