2022-10-15 14:51:25 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2023-02-02 06:13:00 +00:00
|
|
|
import {
|
|
|
|
|
APPSMITH_BRAND_FAVICON_URL,
|
|
|
|
|
APPSMITH_BRAND_LOGO_URL,
|
|
|
|
|
APPSMITH_BRAND_PRIMARY_COLOR,
|
|
|
|
|
createBrandColorsFromPrimaryColor,
|
|
|
|
|
} from "utils/BrandingUtils";
|
2022-10-15 14:51:25 +00:00
|
|
|
import { createReducer } from "utils/ReducerUtils";
|
|
|
|
|
|
2023-01-10 05:39:15 +00:00
|
|
|
export interface TenantReduxState<T> {
|
2022-10-15 14:51:25 +00:00
|
|
|
userPermissions: string[];
|
2023-01-10 05:39:15 +00:00
|
|
|
tenantConfiguration: Record<string, T>;
|
2022-10-15 14:51:25 +00:00
|
|
|
new: boolean;
|
2023-01-10 05:39:15 +00:00
|
|
|
isLoading: boolean;
|
2022-10-15 14:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-09 14:43:47 +00:00
|
|
|
export const defaultBrandingConfig = {
|
2023-02-02 06:13:00 +00:00
|
|
|
brandFaviconUrl: APPSMITH_BRAND_FAVICON_URL,
|
2022-12-09 14:43:47 +00:00
|
|
|
brandColors: {
|
2023-02-02 06:13:00 +00:00
|
|
|
...createBrandColorsFromPrimaryColor(APPSMITH_BRAND_PRIMARY_COLOR),
|
2022-12-09 14:43:47 +00:00
|
|
|
},
|
2023-02-02 06:13:00 +00:00
|
|
|
brandLogoUrl: APPSMITH_BRAND_LOGO_URL,
|
2022-12-09 14:43:47 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-10 05:39:15 +00:00
|
|
|
export const initialState: TenantReduxState<any> = {
|
2022-10-15 14:51:25 +00:00
|
|
|
userPermissions: [],
|
2022-12-09 14:43:47 +00:00
|
|
|
tenantConfiguration: {
|
2023-02-02 06:13:00 +00:00
|
|
|
...defaultBrandingConfig,
|
2022-12-09 14:43:47 +00:00
|
|
|
},
|
2022-10-15 14:51:25 +00:00
|
|
|
new: false,
|
2023-01-10 05:39:15 +00:00
|
|
|
isLoading: true,
|
2022-10-15 14:51:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const handlers = {
|
2023-01-10 05:39:15 +00:00
|
|
|
[ReduxActionTypes.FETCH_CURRENT_TENANT_CONFIG]: (
|
|
|
|
|
state: TenantReduxState<any>,
|
|
|
|
|
) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isLoading: true,
|
|
|
|
|
}),
|
2022-10-15 14:51:25 +00:00
|
|
|
[ReduxActionTypes.FETCH_CURRENT_TENANT_CONFIG_SUCCESS]: (
|
2023-01-10 05:39:15 +00:00
|
|
|
state: TenantReduxState<any>,
|
|
|
|
|
action: ReduxAction<TenantReduxState<any>>,
|
2022-10-15 14:51:25 +00:00
|
|
|
) => ({
|
|
|
|
|
...state,
|
2022-12-12 10:39:42 +00:00
|
|
|
userPermissions: action.payload.userPermissions || [],
|
2022-12-09 14:43:47 +00:00
|
|
|
tenantConfiguration: {
|
2023-02-02 06:13:00 +00:00
|
|
|
...state.tenantConfiguration,
|
2022-12-09 14:43:47 +00:00
|
|
|
...action.payload.tenantConfiguration,
|
|
|
|
|
},
|
2023-01-10 05:39:15 +00:00
|
|
|
isLoading: false,
|
2022-10-15 14:51:25 +00:00
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.FETCH_CURRENT_TENANT_CONFIG_ERROR]: (
|
2023-01-10 05:39:15 +00:00
|
|
|
state: TenantReduxState<any>,
|
2022-10-15 14:51:25 +00:00
|
|
|
) => ({
|
|
|
|
|
...state,
|
2023-01-10 05:39:15 +00:00
|
|
|
isLoading: false,
|
2022-10-15 14:51:25 +00:00
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default createReducer(initialState, handlers);
|