mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 19:27:52 +01:00
Add Site settings > General (#133)
This commit is contained in:
committed by
GitHub
parent
bdc4004e4a
commit
35831b9801
59
app/javascript/actions/Tenant/requestTenant.ts
Normal file
59
app/javascript/actions/Tenant/requestTenant.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Action } from 'redux';
|
||||
import { ThunkAction } from 'redux-thunk';
|
||||
|
||||
import ITenantJSON from '../../interfaces/json/ITenant';
|
||||
import { State } from '../../reducers/rootReducer';
|
||||
|
||||
export const TENANT_REQUEST_START = 'TENANT_REQUEST_START';
|
||||
interface TenantRequestStartAction {
|
||||
type: typeof TENANT_REQUEST_START;
|
||||
}
|
||||
|
||||
export const TENANT_REQUEST_SUCCESS = 'TENANT_REQUEST_SUCCESS';
|
||||
interface TenantRequestSuccessAction {
|
||||
type: typeof TENANT_REQUEST_SUCCESS;
|
||||
tenant: ITenantJSON;
|
||||
}
|
||||
|
||||
export const TENANT_REQUEST_FAILURE = 'TENANT_REQUEST_FAILURE';
|
||||
interface TenantRequestFailureAction {
|
||||
type: typeof TENANT_REQUEST_FAILURE;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type TenantRequestActionTypes =
|
||||
TenantRequestStartAction |
|
||||
TenantRequestSuccessAction |
|
||||
TenantRequestFailureAction;
|
||||
|
||||
|
||||
const tenantRequestStart = (): TenantRequestActionTypes => ({
|
||||
type: TENANT_REQUEST_START,
|
||||
});
|
||||
|
||||
const tenantRequestSuccess = (
|
||||
tenant: ITenantJSON
|
||||
): TenantRequestActionTypes => ({
|
||||
type: TENANT_REQUEST_SUCCESS,
|
||||
tenant,
|
||||
});
|
||||
|
||||
const tenantRequestFailure = (error: string): TenantRequestActionTypes => ({
|
||||
type: TENANT_REQUEST_FAILURE,
|
||||
error,
|
||||
});
|
||||
|
||||
export const requestTenant = (): ThunkAction<void, State, null, Action<string>> => (
|
||||
async (dispatch) => {
|
||||
dispatch(tenantRequestStart());
|
||||
|
||||
try {
|
||||
const response = await fetch('/tenants/0');
|
||||
const json = await response.json();
|
||||
|
||||
dispatch(tenantRequestSuccess(json));
|
||||
} catch (e) {
|
||||
dispatch(tenantRequestFailure(e));
|
||||
}
|
||||
}
|
||||
);
|
||||
82
app/javascript/actions/Tenant/submitTenant.ts
Normal file
82
app/javascript/actions/Tenant/submitTenant.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { Action } from "redux";
|
||||
import { ThunkAction } from "redux-thunk";
|
||||
import HttpStatus from "../../constants/http_status";
|
||||
import buildRequestHeaders from "../../helpers/buildRequestHeaders";
|
||||
import ITenantJSON from "../../interfaces/json/ITenant";
|
||||
import { State } from "../../reducers/rootReducer";
|
||||
|
||||
export const TENANT_SUBMIT_START = 'TENANT_SUBMIT_START';
|
||||
interface TenantSubmitStartAction {
|
||||
type: typeof TENANT_SUBMIT_START;
|
||||
}
|
||||
|
||||
export const TENANT_SUBMIT_SUCCESS = 'TENANT_SUBMIT_SUCCESS';
|
||||
interface TenantSubmitSuccessAction {
|
||||
type: typeof TENANT_SUBMIT_SUCCESS;
|
||||
tenant: ITenantJSON;
|
||||
}
|
||||
|
||||
export const TENANT_SUBMIT_FAILURE = 'TENANT_SUBMIT_FAILURE';
|
||||
interface TenantSubmitFailureAction {
|
||||
type: typeof TENANT_SUBMIT_FAILURE;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type TenantSubmitActionTypes =
|
||||
TenantSubmitStartAction |
|
||||
TenantSubmitSuccessAction |
|
||||
TenantSubmitFailureAction;
|
||||
|
||||
const tenantSubmitStart = (): TenantSubmitStartAction => ({
|
||||
type: TENANT_SUBMIT_START,
|
||||
});
|
||||
|
||||
const tenantSubmitSuccess = (
|
||||
tenantJSON: ITenantJSON,
|
||||
): TenantSubmitSuccessAction => ({
|
||||
type: TENANT_SUBMIT_SUCCESS,
|
||||
tenant: tenantJSON,
|
||||
});
|
||||
|
||||
const tenantSubmitFailure = (error: string): TenantSubmitFailureAction => ({
|
||||
type: TENANT_SUBMIT_FAILURE,
|
||||
error,
|
||||
});
|
||||
|
||||
export const submitTenant = (
|
||||
userFullName: string,
|
||||
userEmail: string,
|
||||
userPassword: string,
|
||||
siteName: string,
|
||||
subdomain: string,
|
||||
authenticityToken: string,
|
||||
): ThunkAction<void, State, null, Action<string>> => async (dispatch) => {
|
||||
dispatch(tenantSubmitStart());
|
||||
|
||||
try {
|
||||
const res = await fetch(`/tenants`, {
|
||||
method: 'POST',
|
||||
headers: buildRequestHeaders(authenticityToken),
|
||||
body: JSON.stringify({
|
||||
user: {
|
||||
full_name: userFullName,
|
||||
email: userEmail,
|
||||
password: userPassword,
|
||||
},
|
||||
tenant: {
|
||||
site_name: siteName,
|
||||
subdomain: subdomain,
|
||||
},
|
||||
}),
|
||||
});
|
||||
const json = await res.json();
|
||||
|
||||
if (res.status === HttpStatus.Created) {
|
||||
dispatch(tenantSubmitSuccess(json));
|
||||
} else {
|
||||
dispatch(tenantSubmitFailure(json.error));
|
||||
}
|
||||
} catch (e) {
|
||||
dispatch(tenantSubmitFailure(e));
|
||||
}
|
||||
};
|
||||
124
app/javascript/actions/Tenant/tenantSignUpFormActions.ts
Normal file
124
app/javascript/actions/Tenant/tenantSignUpFormActions.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
export const TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH = 'TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH';
|
||||
|
||||
interface TenantSignUpToggleEmailAuth {
|
||||
type: typeof TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH,
|
||||
}
|
||||
|
||||
export const toggleEmailAuthTenantSignUp = (
|
||||
|
||||
): TenantSignUpToggleEmailAuth => ({
|
||||
type: TENANT_SIGN_UP_TOGGLE_EMAIL_AUTH,
|
||||
});
|
||||
|
||||
|
||||
// User full name
|
||||
export const TENANT_SIGN_UP_CHANGE_USER_FULL_NAME = 'TENANT_SIGN_UP_CHANGE_USER_FULL_NAME';
|
||||
|
||||
interface TenantSignUpChangeUserFullName {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_USER_FULL_NAME,
|
||||
fullName: string,
|
||||
}
|
||||
|
||||
export const changeUserFullNameTenantSignUp = (
|
||||
fullName: string
|
||||
): TenantSignUpChangeUserFullName => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_USER_FULL_NAME,
|
||||
fullName,
|
||||
});
|
||||
|
||||
// User email
|
||||
export const TENANT_SIGN_UP_CHANGE_USER_EMAIL = 'TENANT_SIGN_UP_CHANGE_USER_EMAIL';
|
||||
|
||||
interface TenantSignUpChangeUserEmail {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_USER_EMAIL,
|
||||
email: string,
|
||||
}
|
||||
|
||||
export const changeUserEmailTenantSignUp = (
|
||||
email: string
|
||||
): TenantSignUpChangeUserEmail => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_USER_EMAIL,
|
||||
email,
|
||||
});
|
||||
|
||||
// User password
|
||||
export const TENANT_SIGN_UP_CHANGE_USER_PASSWORD = 'TENANT_SIGN_UP_CHANGE_USER_PASSWORD';
|
||||
|
||||
interface TenantSignUpChangeUserPassword {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_USER_PASSWORD,
|
||||
password: string,
|
||||
}
|
||||
|
||||
export const changeUserPasswordTenantSignUp = (
|
||||
password: string
|
||||
): TenantSignUpChangeUserPassword => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_USER_PASSWORD,
|
||||
password,
|
||||
});
|
||||
|
||||
// User password confirmation
|
||||
export const TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION = 'TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION';
|
||||
|
||||
interface TenantSignUpChangeUserPasswordConfirmation {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION,
|
||||
passwordConfirmation: string,
|
||||
}
|
||||
|
||||
export const changeUserPasswordConfirmationTenantSignUp = (
|
||||
passwordConfirmation: string
|
||||
): TenantSignUpChangeUserPasswordConfirmation => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_USER_PASSWORD_CONFIRMATION,
|
||||
passwordConfirmation,
|
||||
});
|
||||
|
||||
// Confirm user data, proceed to step 2
|
||||
export const TENANT_SIGN_UP_CONFIRM_USER_FORM = 'TENANT_SIGN_UP_CONFIRM_USER_FORM';
|
||||
|
||||
interface TenantSignUpConfirmUserForm {
|
||||
type: typeof TENANT_SIGN_UP_CONFIRM_USER_FORM;
|
||||
}
|
||||
|
||||
export const confirmUserFormTenantSignUp = (): TenantSignUpConfirmUserForm => ({
|
||||
type: TENANT_SIGN_UP_CONFIRM_USER_FORM,
|
||||
});
|
||||
|
||||
// Tenant site name
|
||||
export const TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME = 'TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME';
|
||||
|
||||
interface TenantSignUpChangeTenantSiteName {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME,
|
||||
siteName: string,
|
||||
}
|
||||
|
||||
export const changeTenantSiteNameTenantSignUp = (
|
||||
siteName: string
|
||||
): TenantSignUpChangeTenantSiteName => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_TENANT_SITE_NAME,
|
||||
siteName,
|
||||
});
|
||||
|
||||
// Tenant site name
|
||||
export const TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN = 'TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN';
|
||||
|
||||
interface TenantSignUpChangeTenantSubdomain {
|
||||
type: typeof TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN,
|
||||
subdomain: string,
|
||||
}
|
||||
|
||||
export const changeTenantSubdomainTenantSignUp = (
|
||||
subdomain: string
|
||||
): TenantSignUpChangeTenantSubdomain => ({
|
||||
type: TENANT_SIGN_UP_CHANGE_TENANT_SUBDOMAIN,
|
||||
subdomain,
|
||||
});
|
||||
|
||||
|
||||
export type TenantSignUpFormActions =
|
||||
TenantSignUpToggleEmailAuth |
|
||||
TenantSignUpChangeUserFullName |
|
||||
TenantSignUpChangeUserEmail |
|
||||
TenantSignUpChangeUserPassword |
|
||||
TenantSignUpChangeUserPasswordConfirmation |
|
||||
TenantSignUpConfirmUserForm |
|
||||
TenantSignUpChangeTenantSiteName |
|
||||
TenantSignUpChangeTenantSubdomain;
|
||||
91
app/javascript/actions/Tenant/updateTenant.ts
Normal file
91
app/javascript/actions/Tenant/updateTenant.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { Action } from "redux";
|
||||
import { ThunkAction } from "redux-thunk";
|
||||
|
||||
import HttpStatus from "../../constants/http_status";
|
||||
import buildRequestHeaders from "../../helpers/buildRequestHeaders";
|
||||
import ITenantJSON from "../../interfaces/json/ITenant";
|
||||
import { State } from "../../reducers/rootReducer";
|
||||
|
||||
export const TENANT_UPDATE_START = 'TENANT_UPDATE_START';
|
||||
interface TenantUpdateStartAction {
|
||||
type: typeof TENANT_UPDATE_START;
|
||||
}
|
||||
|
||||
export const TENANT_UPDATE_SUCCESS = 'TENANT_UPDATE_SUCCESS';
|
||||
interface TenantUpdateSuccessAction {
|
||||
type: typeof TENANT_UPDATE_SUCCESS;
|
||||
tenant: ITenantJSON;
|
||||
}
|
||||
|
||||
export const TENANT_UPDATE_FAILURE = 'TENANT_UPDATE_FAILURE';
|
||||
interface TenantUpdateFailureAction {
|
||||
type: typeof TENANT_UPDATE_FAILURE;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export type TenantUpdateActionTypes =
|
||||
TenantUpdateStartAction |
|
||||
TenantUpdateSuccessAction |
|
||||
TenantUpdateFailureAction;
|
||||
|
||||
const tenantUpdateStart = (): TenantUpdateStartAction => ({
|
||||
type: TENANT_UPDATE_START,
|
||||
});
|
||||
|
||||
const tenantUpdateSuccess = (
|
||||
tenantJSON: ITenantJSON,
|
||||
): TenantUpdateSuccessAction => ({
|
||||
type: TENANT_UPDATE_SUCCESS,
|
||||
tenant: tenantJSON,
|
||||
});
|
||||
|
||||
const tenantUpdateFailure = (error: string): TenantUpdateFailureAction => ({
|
||||
type: TENANT_UPDATE_FAILURE,
|
||||
error,
|
||||
});
|
||||
|
||||
interface UpdateTenantParams {
|
||||
siteName?: string;
|
||||
siteLogo?: string;
|
||||
brandDisplaySetting?: string;
|
||||
locale?: string;
|
||||
authenticityToken: string;
|
||||
}
|
||||
|
||||
export const updateTenant = ({
|
||||
siteName = null,
|
||||
siteLogo = null,
|
||||
brandDisplaySetting = null,
|
||||
locale = null,
|
||||
authenticityToken,
|
||||
}: UpdateTenantParams): ThunkAction<void, State, null, Action<string>> => async (dispatch) => {
|
||||
dispatch(tenantUpdateStart());
|
||||
|
||||
const tenant = Object.assign({},
|
||||
siteName !== null ? { site_name: siteName } : null,
|
||||
siteLogo !== null ? { site_logo: siteLogo } : null,
|
||||
brandDisplaySetting !== null ? { brand_display_setting: brandDisplaySetting } : null,
|
||||
locale !== null ? { locale } : null
|
||||
);
|
||||
|
||||
try {
|
||||
const res = await fetch(`/tenants/0`, {
|
||||
method: 'PATCH',
|
||||
headers: buildRequestHeaders(authenticityToken),
|
||||
body: JSON.stringify({ tenant }),
|
||||
});
|
||||
const json = await res.json();
|
||||
|
||||
if (res.status === HttpStatus.OK) {
|
||||
dispatch(tenantUpdateSuccess(json));
|
||||
} else {
|
||||
dispatch(tenantUpdateFailure(json.error));
|
||||
}
|
||||
|
||||
return Promise.resolve(res);
|
||||
} catch (e) {
|
||||
dispatch(tenantUpdateFailure(e));
|
||||
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
};
|
||||
65
app/javascript/actions/changeSiteSettingsGeneralForm.ts
Normal file
65
app/javascript/actions/changeSiteSettingsGeneralForm.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
// siteName
|
||||
export const SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME = 'SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME';
|
||||
|
||||
interface SiteSettingsChangeGeneralFormSiteName {
|
||||
type: typeof SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME,
|
||||
siteName: string,
|
||||
}
|
||||
|
||||
export const changeSiteSettingsGeneralFormSiteName = (
|
||||
siteName: string
|
||||
): SiteSettingsChangeGeneralFormSiteName => ({
|
||||
type: SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_NAME,
|
||||
siteName,
|
||||
});
|
||||
|
||||
// siteLogo
|
||||
export const SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO = 'SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO';
|
||||
|
||||
interface SiteSettingsChangeGeneralFormSiteLogo {
|
||||
type: typeof SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO,
|
||||
siteLogo: string,
|
||||
}
|
||||
|
||||
export const changeSiteSettingsGeneralFormSiteLogo = (
|
||||
siteLogo: string
|
||||
): SiteSettingsChangeGeneralFormSiteLogo => ({
|
||||
type: SITE_SETTINGS_CHANGE_GENERAL_FORM_SITE_LOGO,
|
||||
siteLogo,
|
||||
});
|
||||
|
||||
// brandDisplaySetting
|
||||
export const SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING = 'SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING';
|
||||
|
||||
interface SiteSettingsChangeGeneralFormBrandSetting {
|
||||
type: typeof SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING,
|
||||
brandDisplaySetting: string,
|
||||
}
|
||||
|
||||
export const changeSiteSettingsGeneralFormBrandSetting = (
|
||||
brandDisplaySetting: string
|
||||
): SiteSettingsChangeGeneralFormBrandSetting => ({
|
||||
type: SITE_SETTINGS_CHANGE_GENERAL_FORM_BRAND_SETTING,
|
||||
brandDisplaySetting,
|
||||
});
|
||||
|
||||
// locale
|
||||
export const SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE = 'SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE';
|
||||
|
||||
interface SiteSettingsChangeGeneralFormLocale {
|
||||
type: typeof SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE,
|
||||
locale: string,
|
||||
}
|
||||
|
||||
export const changeSiteSettingsGeneralFormLocale = (
|
||||
locale: string
|
||||
): SiteSettingsChangeGeneralFormLocale => ({
|
||||
type: SITE_SETTINGS_CHANGE_GENERAL_FORM_LOCALE,
|
||||
locale,
|
||||
});
|
||||
|
||||
export type ChangeSiteSettingsGeneralFormActionTypes =
|
||||
SiteSettingsChangeGeneralFormSiteName |
|
||||
SiteSettingsChangeGeneralFormSiteLogo |
|
||||
SiteSettingsChangeGeneralFormBrandSetting |
|
||||
SiteSettingsChangeGeneralFormLocale;
|
||||
Reference in New Issue
Block a user