2024-08-06 14:52:22 +00:00
|
|
|
import type { ReduxAction } from "ee/constants/ReduxActionConstants";
|
2022-10-15 14:51:25 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/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;
|
2023-02-11 19:43:53 +00:00
|
|
|
instanceId: string;
|
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
|
|
|
};
|
|
|
|
|
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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,
|
2023-02-11 19:43:53 +00:00
|
|
|
instanceId: "",
|
2022-10-15 14:51:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const handlers = {
|
2023-01-10 05:39:15 +00:00
|
|
|
[ReduxActionTypes.FETCH_CURRENT_TENANT_CONFIG]: (
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-01-10 05:39:15 +00:00
|
|
|
state: TenantReduxState<any>,
|
2023-02-07 09:23:15 +00:00
|
|
|
action: ReduxAction<{ isBackgroundRequest: boolean }>,
|
2023-01-10 05:39:15 +00:00
|
|
|
) => ({
|
|
|
|
|
...state,
|
2023-02-07 09:23:15 +00:00
|
|
|
isLoading: !action.payload.isBackgroundRequest,
|
2023-01-10 05:39:15 +00:00
|
|
|
}),
|
2022-10-15 14:51:25 +00:00
|
|
|
[ReduxActionTypes.FETCH_CURRENT_TENANT_CONFIG_SUCCESS]: (
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-01-10 05:39:15 +00:00
|
|
|
state: TenantReduxState<any>,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-01-10 05:39:15 +00:00
|
|
|
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-10-19 18:12:01 +00:00
|
|
|
...defaultBrandingConfig,
|
2023-02-02 06:13:00 +00:00
|
|
|
...state.tenantConfiguration,
|
2022-12-09 14:43:47 +00:00
|
|
|
...action.payload.tenantConfiguration,
|
2023-10-19 18:12:01 +00:00
|
|
|
brandColors: {
|
|
|
|
|
...defaultBrandingConfig.brandColors,
|
|
|
|
|
...action.payload.tenantConfiguration.brandColors,
|
|
|
|
|
},
|
2022-12-09 14:43:47 +00:00
|
|
|
},
|
2023-01-10 05:39:15 +00:00
|
|
|
isLoading: false,
|
2023-02-11 19:43:53 +00:00
|
|
|
instanceId: action.payload.instanceId,
|
2022-10-15 14:51:25 +00:00
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.FETCH_CURRENT_TENANT_CONFIG_ERROR]: (
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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
|
|
|
}),
|
2023-06-02 11:06:41 +00:00
|
|
|
[ReduxActionTypes.UPDATE_TENANT_CONFIG_SUCCESS]: (
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-06-02 11:06:41 +00:00
|
|
|
state: TenantReduxState<any>,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-06-02 11:06:41 +00:00
|
|
|
action: ReduxAction<TenantReduxState<any>>,
|
|
|
|
|
) => ({
|
|
|
|
|
...state,
|
|
|
|
|
...action.payload,
|
|
|
|
|
tenantConfiguration: {
|
|
|
|
|
...state.tenantConfiguration,
|
|
|
|
|
...action.payload.tenantConfiguration,
|
|
|
|
|
},
|
|
|
|
|
isLoading: false,
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.UPDATE_TENANT_CONFIG_ERROR]: (
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-06-02 11:06:41 +00:00
|
|
|
state: TenantReduxState<any>,
|
|
|
|
|
) => ({
|
|
|
|
|
...state,
|
|
|
|
|
isLoading: false,
|
|
|
|
|
}),
|
2022-10-15 14:51:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default createReducer(initialState, handlers);
|