mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Form refactoring (#142)
This commit is contained in:
committed by
GitHub
parent
d078e659c6
commit
9592ac3d1d
@@ -1,10 +1,3 @@
|
||||
import {
|
||||
TenantRequestActionTypes,
|
||||
TENANT_REQUEST_START,
|
||||
TENANT_REQUEST_SUCCESS,
|
||||
TENANT_REQUEST_FAILURE,
|
||||
} from "../../actions/Tenant/requestTenant";
|
||||
|
||||
import {
|
||||
TenantUpdateActionTypes,
|
||||
TENANT_UPDATE_START,
|
||||
@@ -12,38 +5,13 @@ import {
|
||||
TENANT_UPDATE_FAILURE,
|
||||
} from '../../actions/Tenant/updateTenant';
|
||||
|
||||
import {
|
||||
ChangeSiteSettingsGeneralFormActionTypes,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE,
|
||||
} from '../../actions/changeSiteSettingsGeneralForm';
|
||||
|
||||
export interface ISiteSettingsGeneralForm {
|
||||
siteName: string;
|
||||
siteLogo: string;
|
||||
brandDisplaySetting: string;
|
||||
locale: string;
|
||||
}
|
||||
|
||||
export interface SiteSettingsGeneralState {
|
||||
form: ISiteSettingsGeneralForm,
|
||||
areDirty: boolean;
|
||||
areLoading: boolean;
|
||||
areUpdating: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const initialState: SiteSettingsGeneralState = {
|
||||
form: {
|
||||
siteName: '',
|
||||
siteLogo: '',
|
||||
brandDisplaySetting: '',
|
||||
locale: '',
|
||||
},
|
||||
areDirty: false,
|
||||
areLoading: false,
|
||||
areUpdating: false,
|
||||
error: '',
|
||||
};
|
||||
@@ -51,86 +19,28 @@ const initialState: SiteSettingsGeneralState = {
|
||||
const siteSettingsGeneralReducer = (
|
||||
state = initialState,
|
||||
action:
|
||||
TenantRequestActionTypes |
|
||||
TenantUpdateActionTypes |
|
||||
ChangeSiteSettingsGeneralFormActionTypes
|
||||
TenantUpdateActionTypes
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case TENANT_REQUEST_START:
|
||||
return {
|
||||
...state,
|
||||
areLoading: true,
|
||||
};
|
||||
|
||||
case TENANT_UPDATE_START:
|
||||
return {
|
||||
...state,
|
||||
areUpdating: true,
|
||||
};
|
||||
|
||||
case TENANT_REQUEST_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
form: {
|
||||
siteName: action.tenant.site_name,
|
||||
siteLogo: action.tenant.site_logo,
|
||||
brandDisplaySetting: action.tenant.brand_display_setting,
|
||||
locale: action.tenant.locale,
|
||||
},
|
||||
areDirty: false,
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case TENANT_UPDATE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
areDirty: false,
|
||||
areUpdating: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case TENANT_REQUEST_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
areLoading: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case TENANT_UPDATE_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
areUpdating: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME:
|
||||
return {
|
||||
...state,
|
||||
form: { ...state.form, siteName: action.siteName },
|
||||
areDirty: true,
|
||||
};
|
||||
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO:
|
||||
return {
|
||||
...state,
|
||||
form: { ...state.form, siteLogo: action.siteLogo },
|
||||
areDirty: true,
|
||||
};
|
||||
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING:
|
||||
return {
|
||||
...state,
|
||||
form: { ...state.form, brandDisplaySetting: action.brandDisplaySetting },
|
||||
areDirty: true,
|
||||
};
|
||||
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE:
|
||||
return {
|
||||
...state,
|
||||
form: { ...state.form, locale: action.locale },
|
||||
areDirty: true,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
||||
@@ -12,14 +12,6 @@ import {
|
||||
TENANT_UPDATE_FAILURE,
|
||||
} from '../actions/Tenant/updateTenant';
|
||||
|
||||
import {
|
||||
ChangeSiteSettingsGeneralFormActionTypes,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING,
|
||||
SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE,
|
||||
} from '../actions/changeSiteSettingsGeneralForm';
|
||||
|
||||
import {
|
||||
BoardsRequestActionTypes,
|
||||
BOARDS_REQUEST_START,
|
||||
@@ -131,7 +123,6 @@ const siteSettingsReducer = (
|
||||
action:
|
||||
TenantRequestActionTypes |
|
||||
TenantUpdateActionTypes |
|
||||
ChangeSiteSettingsGeneralFormActionTypes |
|
||||
BoardsRequestActionTypes |
|
||||
BoardSubmitActionTypes |
|
||||
BoardUpdateActionTypes |
|
||||
@@ -146,16 +137,9 @@ const siteSettingsReducer = (
|
||||
UserUpdateActionTypes
|
||||
): SiteSettingsState => {
|
||||
switch (action.type) {
|
||||
case TENANT_REQUEST_START:
|
||||
case TENANT_REQUEST_SUCCESS:
|
||||
case TENANT_REQUEST_FAILURE:
|
||||
case TENANT_UPDATE_START:
|
||||
case TENANT_UPDATE_SUCCESS:
|
||||
case TENANT_UPDATE_FAILURE:
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME:
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO:
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING:
|
||||
case SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE:
|
||||
return {
|
||||
...state,
|
||||
general: siteSettingsGeneralReducer(state.general, action),
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
import {
|
||||
TenantSignUpFormActions,
|
||||
TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH,
|
||||
TENANT_SIGN_UP_CHANGE_USER_FULL_NAME,
|
||||
TENANT_SIGN_UP_CHANGE_USER_EMAIL,
|
||||
TENANT_SIGN_UP_CHANGE_USER_PASSWORD,
|
||||
TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION,
|
||||
TENANT_SIGN_UP_CONFIRM_USER_FORM,
|
||||
TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME,
|
||||
TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN,
|
||||
} from '../actions/Tenant/tenantSignUpFormActions';
|
||||
|
||||
import {
|
||||
TenantSubmitActionTypes,
|
||||
TENANT_SUBMIT_START,
|
||||
@@ -17,105 +5,21 @@ import {
|
||||
TENANT_SUBMIT_FAILURE,
|
||||
} from '../actions/Tenant/submitTenant';
|
||||
|
||||
export interface TenantSignUpUserFormState {
|
||||
fullName: string;
|
||||
email: string;
|
||||
password: string;
|
||||
passwordConfirmation: string;
|
||||
passwordConfirmationError: boolean;
|
||||
}
|
||||
|
||||
export interface TenantSignUpTenantFormState {
|
||||
siteName: string;
|
||||
subdomain: string;
|
||||
}
|
||||
|
||||
export interface TenantSignUpState {
|
||||
currentStep: number;
|
||||
emailAuth: boolean;
|
||||
isSubmitting: boolean;
|
||||
error: string;
|
||||
|
||||
userForm: TenantSignUpUserFormState;
|
||||
tenantForm: TenantSignUpTenantFormState;
|
||||
}
|
||||
|
||||
const initialState: TenantSignUpState = {
|
||||
currentStep: 1,
|
||||
emailAuth: false,
|
||||
isSubmitting: false,
|
||||
error: '',
|
||||
|
||||
userForm: {
|
||||
fullName: '',
|
||||
email: '',
|
||||
password: '',
|
||||
passwordConfirmation: '',
|
||||
passwordConfirmationError: false,
|
||||
},
|
||||
tenantForm: {
|
||||
siteName: '',
|
||||
subdomain: '',
|
||||
},
|
||||
};
|
||||
|
||||
const tenantSignUpReducer = (
|
||||
state = initialState,
|
||||
action: TenantSignUpFormActions | TenantSubmitActionTypes,
|
||||
action: TenantSubmitActionTypes,
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH:
|
||||
return {
|
||||
...state,
|
||||
emailAuth: !state.emailAuth,
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_USER_FULL_NAME:
|
||||
return {
|
||||
...state,
|
||||
userForm: { ...state.userForm, fullName: action.fullName },
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_USER_EMAIL:
|
||||
return {
|
||||
...state,
|
||||
userForm: { ...state.userForm, email: action.email },
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_USER_PASSWORD:
|
||||
return {
|
||||
...state,
|
||||
userForm: { ...state.userForm, password: action.password },
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION:
|
||||
return {
|
||||
...state,
|
||||
userForm: {
|
||||
...state.userForm,
|
||||
passwordConfirmation: action.passwordConfirmation,
|
||||
passwordConfirmationError: state.userForm.password !== action.passwordConfirmation,
|
||||
},
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CONFIRM_USER_FORM:
|
||||
return {
|
||||
...state,
|
||||
currentStep: 2,
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME:
|
||||
return {
|
||||
...state,
|
||||
tenantForm: { ...state.tenantForm, siteName: action.siteName },
|
||||
};
|
||||
|
||||
case TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN:
|
||||
return {
|
||||
...state,
|
||||
tenantForm: { ...state.tenantForm, subdomain: action.subdomain },
|
||||
};
|
||||
|
||||
case TENANT_SUBMIT_START:
|
||||
return {
|
||||
...state,
|
||||
@@ -125,7 +29,6 @@ const tenantSignUpReducer = (
|
||||
case TENANT_SUBMIT_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
currentStep: 3,
|
||||
isSubmitting: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user