mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add Site settings > General (#133)
This commit is contained in:
committed by
GitHub
parent
bdc4004e4a
commit
35831b9801
140
app/javascript/reducers/SiteSettings/generalReducer.ts
Normal file
140
app/javascript/reducers/SiteSettings/generalReducer.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import {
|
||||
TenantRequestActionTypes,
|
||||
TENANT_REQUEST_START,
|
||||
TENANT_REQUEST_SUCCESS,
|
||||
TENANT_REQUEST_FAILURE,
|
||||
} from "../../actions/Tenant/requestTenant";
|
||||
|
||||
import {
|
||||
TenantUpdateActionTypes,
|
||||
TENANT_UPDATE_START,
|
||||
TENANT_UPDATE_SUCCESS,
|
||||
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: '',
|
||||
};
|
||||
|
||||
const siteSettingsGeneralReducer = (
|
||||
state = initialState,
|
||||
action:
|
||||
TenantRequestActionTypes |
|
||||
TenantUpdateActionTypes |
|
||||
ChangeSiteSettingsGeneralFormActionTypes
|
||||
) => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
export default siteSettingsGeneralReducer;
|
||||
@@ -1,3 +1,10 @@
|
||||
import {
|
||||
PostStatusesRequestActionTypes,
|
||||
POST_STATUSES_REQUEST_START,
|
||||
POST_STATUSES_REQUEST_SUCCESS,
|
||||
POST_STATUSES_REQUEST_FAILURE,
|
||||
} from '../../actions/PostStatus/requestPostStatuses';
|
||||
|
||||
import {
|
||||
PostStatusOrderUpdateActionTypes,
|
||||
POSTSTATUS_ORDER_UPDATE_START,
|
||||
@@ -38,12 +45,15 @@ const initialState: SiteSettingsPostStatusesState = {
|
||||
|
||||
const siteSettingsPostStatusesReducer = (
|
||||
state = initialState,
|
||||
action: PostStatusOrderUpdateActionTypes |
|
||||
action:
|
||||
PostStatusesRequestActionTypes |
|
||||
PostStatusOrderUpdateActionTypes |
|
||||
PostStatusDeleteActionTypes |
|
||||
PostStatusSubmitActionTypes |
|
||||
PostStatusUpdateActionTypes
|
||||
): SiteSettingsPostStatusesState => {
|
||||
switch (action.type) {
|
||||
case POST_STATUSES_REQUEST_START:
|
||||
case POSTSTATUS_SUBMIT_START:
|
||||
case POSTSTATUS_UPDATE_START:
|
||||
case POSTSTATUS_ORDER_UPDATE_START:
|
||||
@@ -53,6 +63,7 @@ const siteSettingsPostStatusesReducer = (
|
||||
areUpdating: true,
|
||||
};
|
||||
|
||||
case POST_STATUSES_REQUEST_SUCCESS:
|
||||
case POSTSTATUS_SUBMIT_SUCCESS:
|
||||
case POSTSTATUS_UPDATE_SUCCESS:
|
||||
case POSTSTATUS_ORDER_UPDATE_SUCCESS:
|
||||
@@ -63,6 +74,7 @@ const siteSettingsPostStatusesReducer = (
|
||||
error: '',
|
||||
};
|
||||
|
||||
case POST_STATUSES_REQUEST_FAILURE:
|
||||
case POSTSTATUS_SUBMIT_FAILURE:
|
||||
case POSTSTATUS_UPDATE_FAILURE:
|
||||
case POSTSTATUS_ORDER_UPDATE_FAILURE:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
import tenantSignUpReducer from './tenantSignUpReducer';
|
||||
|
||||
import postsReducer from './postsReducer';
|
||||
import boardsReducer from './boardsReducer';
|
||||
import postStatusesReducer from './postStatusesReducer';
|
||||
@@ -8,6 +10,8 @@ import currentPostReducer from './currentPostReducer';
|
||||
import siteSettingsReducer from './siteSettingsReducer';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
tenantSignUp: tenantSignUpReducer,
|
||||
|
||||
posts: postsReducer,
|
||||
boards: boardsReducer,
|
||||
postStatuses: postStatusesReducer,
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
import {
|
||||
TenantRequestActionTypes,
|
||||
TENANT_REQUEST_START,
|
||||
TENANT_REQUEST_SUCCESS,
|
||||
TENANT_REQUEST_FAILURE,
|
||||
} from '../actions/Tenant/requestTenant';
|
||||
|
||||
import {
|
||||
TenantUpdateActionTypes,
|
||||
TENANT_UPDATE_START,
|
||||
TENANT_UPDATE_SUCCESS,
|
||||
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,
|
||||
@@ -33,6 +55,13 @@ import {
|
||||
BOARD_DELETE_FAILURE,
|
||||
} from '../actions/Board/deleteBoard';
|
||||
|
||||
import {
|
||||
PostStatusesRequestActionTypes,
|
||||
POST_STATUSES_REQUEST_START,
|
||||
POST_STATUSES_REQUEST_SUCCESS,
|
||||
POST_STATUSES_REQUEST_FAILURE,
|
||||
} from '../actions/PostStatus/requestPostStatuses';
|
||||
|
||||
import {
|
||||
PostStatusOrderUpdateActionTypes,
|
||||
POSTSTATUS_ORDER_UPDATE_START,
|
||||
@@ -75,12 +104,14 @@ import {
|
||||
USER_UPDATE_FAILURE,
|
||||
} from '../actions/User/updateUser';
|
||||
|
||||
import siteSettingsGeneralReducer, { SiteSettingsGeneralState } from './SiteSettings/generalReducer';
|
||||
import siteSettingsBoardsReducer, { SiteSettingsBoardsState } from './SiteSettings/boardsReducer';
|
||||
import siteSettingsPostStatusesReducer, { SiteSettingsPostStatusesState } from './SiteSettings/postStatusesReducer';
|
||||
import siteSettingsRoadmapReducer, { SiteSettingsRoadmapState } from './SiteSettings/roadmapReducer';
|
||||
import siteSettingsUsersReducer, { SiteSettingsUsersState } from './SiteSettings/usersReducer';
|
||||
|
||||
interface SiteSettingsState {
|
||||
general: SiteSettingsGeneralState;
|
||||
boards: SiteSettingsBoardsState;
|
||||
postStatuses: SiteSettingsPostStatusesState;
|
||||
roadmap: SiteSettingsRoadmapState;
|
||||
@@ -88,6 +119,7 @@ interface SiteSettingsState {
|
||||
}
|
||||
|
||||
const initialState: SiteSettingsState = {
|
||||
general: siteSettingsGeneralReducer(undefined, {} as any),
|
||||
boards: siteSettingsBoardsReducer(undefined, {} as any),
|
||||
postStatuses: siteSettingsPostStatusesReducer(undefined, {} as any),
|
||||
roadmap: siteSettingsRoadmapReducer(undefined, {} as any),
|
||||
@@ -97,11 +129,15 @@ const initialState: SiteSettingsState = {
|
||||
const siteSettingsReducer = (
|
||||
state = initialState,
|
||||
action:
|
||||
TenantRequestActionTypes |
|
||||
TenantUpdateActionTypes |
|
||||
ChangeSiteSettingsGeneralFormActionTypes |
|
||||
BoardsRequestActionTypes |
|
||||
BoardSubmitActionTypes |
|
||||
BoardUpdateActionTypes |
|
||||
BoardOrderUpdateActionTypes |
|
||||
BoardDeleteActionTypes |
|
||||
PostStatusesRequestActionTypes |
|
||||
PostStatusOrderUpdateActionTypes |
|
||||
PostStatusDeleteActionTypes |
|
||||
PostStatusSubmitActionTypes |
|
||||
@@ -110,6 +146,21 @@ 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),
|
||||
};
|
||||
|
||||
case BOARDS_REQUEST_START:
|
||||
case BOARDS_REQUEST_SUCCESS:
|
||||
case BOARDS_REQUEST_FAILURE:
|
||||
@@ -130,6 +181,9 @@ const siteSettingsReducer = (
|
||||
boards: siteSettingsBoardsReducer(state.boards, action),
|
||||
};
|
||||
|
||||
case POST_STATUSES_REQUEST_START:
|
||||
case POST_STATUSES_REQUEST_SUCCESS:
|
||||
case POST_STATUSES_REQUEST_FAILURE:
|
||||
case POSTSTATUS_SUBMIT_START:
|
||||
case POSTSTATUS_SUBMIT_SUCCESS:
|
||||
case POSTSTATUS_SUBMIT_FAILURE:
|
||||
|
||||
145
app/javascript/reducers/tenantSignUpReducer.ts
Normal file
145
app/javascript/reducers/tenantSignUpReducer.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
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,
|
||||
TENANT_SUBMIT_SUCCESS,
|
||||
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,
|
||||
) => {
|
||||
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,
|
||||
isSubmitting: true,
|
||||
};
|
||||
|
||||
case TENANT_SUBMIT_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
currentStep: 3,
|
||||
isSubmitting: false,
|
||||
error: '',
|
||||
};
|
||||
|
||||
case TENANT_SUBMIT_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
isSubmitting: false,
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default tenantSignUpReducer;
|
||||
Reference in New Issue
Block a user