@integry/sdk 4.5.2 → 4.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +2 -2
- package/THIRD_PARTY_LICENSES +0 -37
- package/dist/esm/index.csm.d.ts +12 -2
- package/dist/esm/index.csm.js +7262 -1
- package/dist/umd/index.umd.d.ts +9 -1
- package/dist/umd/index.umd.js +7262 -1
- package/jest.config.cjs +10 -0
- package/package.json +10 -4
- package/src/components/AddTagButton/index.ts +23 -0
- package/src/components/BasicSelect/index.ts +114 -0
- package/src/components/BasicSelect/styles.module.scss +44 -0
- package/src/components/Button/index.ts +94 -0
- package/src/components/Button/styles.module.scss +152 -0
- package/src/components/CheckboxGroup/Checkbox.ts +104 -0
- package/src/components/CheckboxGroup/index.ts +190 -0
- package/src/components/CheckboxGroup/styles.module.scss +63 -0
- package/src/components/CollapsedMenu/index.ts +101 -0
- package/src/components/CollapsedMenu/styles.module.scss +46 -0
- package/src/components/ConfigureFieldWrapper/index.ts +85 -0
- package/src/components/ConfigureFieldWrapper/styles.module.scss +57 -0
- package/src/components/EditableText/index.ts +121 -0
- package/src/components/EditableText/styles.module.scss +38 -0
- package/src/components/EditableTextArea/index.ts +143 -0
- package/src/components/EditableTextArea/styles.module.scss +91 -0
- package/src/components/ErrorMessage/index.ts +16 -0
- package/src/components/ErrorMessage/styles.module.scss +19 -0
- package/src/components/ErrorPage/index.ts +42 -0
- package/src/components/ErrorPage/styles.module.scss +26 -0
- package/src/components/Footer/index.ts +41 -0
- package/src/components/Footer/styles.module.scss +40 -0
- package/src/components/HTMLContent/index.tsx +275 -0
- package/src/components/HTMLContent/styles.module.scss +3 -0
- package/src/components/InfoBox/index.ts +48 -0
- package/src/components/InfoBox/styles.module.scss +21 -0
- package/src/components/Input/BaseInput/index.ts +170 -0
- package/src/components/Input/BaseInput/styles.module.scss +94 -0
- package/src/components/Input/DateInput/index.ts +103 -0
- package/src/components/Input/DateInput/styles.module.scss +50 -0
- package/src/components/Input/Input/index.ts +206 -0
- package/src/components/Input/Input/styles.module.scss +14 -0
- package/src/components/Input/PasswordInput/index.ts +164 -0
- package/src/components/Input/PasswordInput/styles.module.scss +37 -0
- package/src/components/Input/index.ts +7 -0
- package/src/components/Label/index.ts +61 -0
- package/src/components/Label/styles.module.scss +41 -0
- package/src/components/LargeLoader/index.ts +25 -0
- package/src/components/LargeLoader/styles.module.scss +16 -0
- package/src/components/Listbox/ListBoxItem.ts +57 -0
- package/src/components/Listbox/index.ts +479 -0
- package/src/components/Listbox/styles.module.scss +197 -0
- package/src/components/Loader/index.ts +25 -0
- package/src/components/Loader/styles.module.scss +16 -0
- package/src/components/MediaGallery/MediaGalleryModal.ts +82 -0
- package/src/components/MediaGallery/MediaSlider.ts +76 -0
- package/src/components/MediaGallery/index.ts +92 -0
- package/src/components/MediaGallery/styles.module.scss +156 -0
- package/src/components/MediaUpload/index.ts +233 -0
- package/src/components/MediaUpload/styles.module.scss +118 -0
- package/src/components/Modal/index.ts +87 -0
- package/src/components/Modal/styles.module.scss +441 -0
- package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +58 -0
- package/src/components/MultipurposeField/Dropdown/index.tsx +981 -0
- package/src/components/MultipurposeField/Dropdown/styles.module.scss +208 -0
- package/src/components/MultipurposeField/TagMenu/index.ts +384 -0
- package/src/components/MultipurposeField/TagMenu/styles.module.scss +136 -0
- package/src/components/MultipurposeField/TagOptions/index.tsx +83 -0
- package/src/components/MultipurposeField/TagOptions/styles.module.scss +95 -0
- package/src/components/MultipurposeField/index.tsx +687 -0
- package/src/components/MultipurposeField/styles.module.scss +56 -0
- package/src/components/NewModal/index.ts +69 -0
- package/src/components/NewModal/styles.module.scss +70 -0
- package/src/components/OverflowTooltip/index.tsx +59 -0
- package/src/components/PopUp/ConfirmationPopUp/index.ts +58 -0
- package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +49 -0
- package/src/components/PopUp/SuccessPopUp/index.ts +62 -0
- package/src/components/PopUp/SuccessPopUp/styles.module.scss +38 -0
- package/src/components/RadioGroup/Radio.ts +129 -0
- package/src/components/RadioGroup/index.ts +169 -0
- package/src/components/RadioGroup/styles.module.scss +81 -0
- package/src/components/Search/index.ts +69 -0
- package/src/components/Search/styles.module.scss +149 -0
- package/src/components/TabBar/Tab.ts +33 -0
- package/src/components/TabBar/index.ts +64 -0
- package/src/components/TabBar/styles.module.scss +43 -0
- package/src/components/Tag/index.ts +29 -0
- package/src/components/Tag/styles.module.scss +57 -0
- package/src/components/TextArea/index.ts +172 -0
- package/src/components/TextArea/styles.module.scss +70 -0
- package/src/components/TextContent/index.tsx +128 -0
- package/src/components/TextContent/styles.module.scss +6 -0
- package/src/components/ThreeDotLoader/index.ts +39 -0
- package/src/components/ThreeDotLoader/styles.module.scss +41 -0
- package/src/components/TimeInput/index.ts +129 -0
- package/src/components/TimeInput/styles.module.scss +16 -0
- package/src/components/Toggle/index.ts +34 -0
- package/src/components/Toggle/styles.module.scss +56 -0
- package/src/components/Toggle-v2/index.ts +40 -0
- package/src/components/Toggle-v2/styles.module.scss +86 -0
- package/src/components/Tooltip/index.ts +271 -0
- package/src/components/Tooltip/styles.module.scss +105 -0
- package/src/components/form/ObjectField/index.ts +364 -0
- package/src/components/form/ObjectField/styles.module.scss +103 -0
- package/src/components/form/index.ts +3 -0
- package/src/contexts/AppContext.ts +12 -0
- package/src/declaration.d.ts +7 -0
- package/src/extensions/HMAC.ts +25 -0
- package/src/extensions/IntegryAPIError.ts +19 -0
- package/src/features/common/AccountDropdown/index.ts +291 -0
- package/src/features/common/AccountDropdown/styles.module.scss +19 -0
- package/src/features/common/ActionForm/index.ts +1818 -0
- package/src/features/common/ActionForm/styles.module.scss +23 -0
- package/src/features/common/AppCard/index.ts +207 -0
- package/src/features/common/AppCard/styles.module.scss +117 -0
- package/src/features/common/AppCardCompact/index.ts +189 -0
- package/src/features/common/AppCardCompact/styles.module.scss +141 -0
- package/src/features/common/AuthSelector/index.ts +537 -0
- package/src/features/common/AuthSelector/styles.module.scss +161 -0
- package/src/features/common/AuthSelectorCompact/index.ts +706 -0
- package/src/features/common/AuthSelectorCompact/styles.module.scss +219 -0
- package/src/features/common/AuthSelectorDropdown/index.ts +704 -0
- package/src/features/common/AuthSelectorDropdown/styles.module.scss +361 -0
- package/src/features/common/DynamicField/index.ts +229 -0
- package/src/features/common/DynamicField/styles.module.scss +67 -0
- package/src/features/common/DynamicTypedField/index.ts +217 -0
- package/src/features/common/DynamicTypedField/styles.module.scss +67 -0
- package/src/features/common/FunctionForm/index.ts +862 -0
- package/src/features/common/FunctionForm/styles.module.scss +163 -0
- package/src/features/common/MappingUI/index.ts +649 -0
- package/src/features/common/MappingUI/styles.module.scss +121 -0
- package/src/features/common/MarketplaceAppCard/index.ts +279 -0
- package/src/features/common/MarketplaceAppCard/styles.module.scss +231 -0
- package/src/features/common/MarketplaceAppCardCompact/index.ts +283 -0
- package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +255 -0
- package/src/features/common/NewMappingUI/index.ts +515 -0
- package/src/features/common/NewMappingUI/styles.module.scss +113 -0
- package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +67 -0
- package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +23 -0
- package/src/features/common/RequestAppWidget/index.ts +48 -0
- package/src/features/common/RequestAppWidget/request-app-form.ts +89 -0
- package/src/features/common/RequestAppWidget/styles.module.scss +43 -0
- package/src/features/common/SectionField/index.ts +272 -0
- package/src/features/common/SectionField/styles.module.scss +67 -0
- package/src/features/common/Step/index.ts +827 -0
- package/src/features/common/Step/styles.module.scss +12 -0
- package/src/features/common/StepNavigation/CollapsedSteps.ts +125 -0
- package/src/features/common/StepNavigation/NavItem.ts +111 -0
- package/src/features/common/StepNavigation/index.ts +257 -0
- package/src/features/common/StepNavigation/styles.module.scss +117 -0
- package/src/features/common/Steps/index.ts +1139 -0
- package/src/features/common/Steps/styles.module.scss +314 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +383 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +367 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +194 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +389 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +577 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +83 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +212 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +45 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +1081 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +452 -0
- package/src/features/containers/AppFlowContainer/Authentication/index.ts +610 -0
- package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +468 -0
- package/src/features/containers/AppFlowContainer/index.ts +114 -0
- package/src/features/containers/AppPageContainer/AppPage/index.tsx +262 -0
- package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +120 -0
- package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +165 -0
- package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +81 -0
- package/src/features/containers/AppPageContainer/index.tsx +93 -0
- package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
- package/src/features/containers/AppsForFlows/index.ts +161 -0
- package/src/features/containers/AppsForFlows/styles.module.scss +280 -0
- package/src/features/containers/AppsForFlowsCompact/index.ts +161 -0
- package/src/features/containers/AppsForFlowsCompact/styles.module.scss +279 -0
- package/src/features/containers/AuthSetupContainer/AppSelection.ts +73 -0
- package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +67 -0
- package/src/features/containers/AuthSetupContainer/Footer.ts +32 -0
- package/src/features/containers/AuthSetupContainer/Header.ts +39 -0
- package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +27 -0
- package/src/features/containers/AuthSetupContainer/index.ts +349 -0
- package/src/features/containers/AuthSetupContainer/styles.module.scss +229 -0
- package/src/features/containers/FlowSetupContainer/index.ts +390 -0
- package/src/features/containers/FlowSetupContainer/styles.module.scss +18 -0
- package/src/features/containers/MarkeplaceApps/index.ts +574 -0
- package/src/features/containers/MarkeplaceApps/styles.module.scss +559 -0
- package/src/features/containers/MarketplaceAppsCompact/index.ts +576 -0
- package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +546 -0
- package/src/features/containers/MarketplaceAppsContainer/index.ts +83 -0
- package/src/features/containers/MarketplaceContainer/AppCard/index.ts +91 -0
- package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +66 -0
- package/src/features/containers/MarketplaceContainer/AppListing/index.ts +34 -0
- package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +10 -0
- package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +132 -0
- package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +117 -0
- package/src/features/containers/MarketplaceContainer/index.ts +242 -0
- package/src/features/containers/MarketplaceContainer/styles.module.scss +84 -0
- package/src/features/containers/SDKContainer/index.ts +817 -0
- package/src/features/containers/SDKContainer/styles.module.scss +266 -0
- package/src/features/containers/SDKDebugContainer/index.ts +137 -0
- package/src/features/containers/SDKDebugContainer/styles.module.scss +37 -0
- package/src/features/containers/SDKFailedContainer/index.ts +117 -0
- package/src/features/containers/SDKFailedContainer/styles.module.scss +57 -0
- package/src/features/integrations/IntegrationRow/Icons.ts +77 -0
- package/src/features/integrations/IntegrationRow/index.ts +129 -0
- package/src/features/integrations/IntegrationRow/styles.module.scss +62 -0
- package/src/features/integrations/IntegrationsHeader/index.ts +34 -0
- package/src/features/integrations/IntegrationsHeader/styles.module.scss +47 -0
- package/src/features/integrations/IntegrationsList/index.ts +252 -0
- package/src/features/integrations/IntegrationsList/styles.module.scss +67 -0
- package/src/features/templates/Template/index.ts +295 -0
- package/src/features/templates/Template/styles.module.scss +226 -0
- package/src/features/templates/TemplatesView/index.ts +368 -0
- package/src/features/templates/TemplatesView/styles.module.scss +71 -0
- package/src/features/templates/TemplatesViewCompact/index.ts +364 -0
- package/src/features/templates/TemplatesViewCompact/styles.module.scss +141 -0
- package/src/hooks/useAutosizeTextArea.ts +22 -0
- package/src/hooks/useCustomRef.ts +13 -0
- package/src/hooks/useDebounce.ts +17 -0
- package/src/hooks/useElementResize.ts +40 -0
- package/src/hooks/useEventListener.ts +44 -0
- package/src/hooks/useHover.ts +40 -0
- package/src/hooks/useOnClickOutside.ts +32 -0
- package/src/index.ts +2051 -0
- package/src/index.umd.ts +13 -0
- package/src/interfaces/index.ts +924 -0
- package/src/modules/api/index.ts +1315 -0
- package/src/modules/api/responseHandler.ts +38 -0
- package/src/modules/event-emitter/index.ts +72 -0
- package/src/modules/event-emitter/runners/abstract.ts +21 -0
- package/src/modules/event-emitter/runners/default.ts +11 -0
- package/src/modules/event-emitter/runners/ntimes.ts +28 -0
- package/src/modules/event-emitter/types.ts +34 -0
- package/src/store/actionFunctions.ts +1573 -0
- package/src/store/index.ts +17 -0
- package/src/store/initialState.ts +58 -0
- package/src/stories/Button.stories.tsx +83 -0
- package/src/stories/Checkbox/Checkbox.stories.tsx +41 -0
- package/src/stories/Checkbox/CheckboxGroup.stories.tsx +46 -0
- package/src/stories/EditableText.stories.tsx +35 -0
- package/src/stories/Input/BaseInput.stories.tsx +48 -0
- package/src/stories/Input/DateInput.stories.tsx +28 -0
- package/src/stories/Input/Input.stories.tsx +24 -0
- package/src/stories/Input/PasswordInput.stories.tsx +26 -0
- package/src/stories/Introduction.stories.mdx +211 -0
- package/src/stories/Label.stories.tsx +27 -0
- package/src/stories/Listbox.stories.tsx +122 -0
- package/src/stories/Radio/Radio.stories.tsx +39 -0
- package/src/stories/Radio/RadioGroup.stories.tsx +46 -0
- package/src/stories/StepNavigation/NavItem.stories.tsx +31 -0
- package/src/stories/StepNavigation/StepNavigation.stories.tsx +50 -0
- package/src/stories/TabBar.stories.tsx +31 -0
- package/src/stories/TextArea.stories.tsx +23 -0
- package/src/stories/TimeInput.stories.tsx +37 -0
- package/src/stories/Toggle.stories.tsx +33 -0
- package/src/stories/assets/code-brackets.svg +1 -0
- package/src/stories/assets/colors.svg +1 -0
- package/src/stories/assets/comments.svg +1 -0
- package/src/stories/assets/direction.svg +1 -0
- package/src/stories/assets/flow.svg +1 -0
- package/src/stories/assets/plugin.svg +1 -0
- package/src/stories/assets/repo.svg +1 -0
- package/src/stories/assets/stackalt.svg +1 -0
- package/src/types/index.ts +293 -0
- package/src/types/store.ts +366 -0
- package/src/types/utils.ts +19 -0
- package/src/utils/ActivityOutputUtils.ts +163 -0
- package/src/utils/common.ts +20 -0
- package/src/utils/copyToClipboard.ts +24 -0
- package/src/utils/datetime.ts +101 -0
- package/src/utils/getUrlParam.ts +11 -0
- package/src/utils/isAuthMessage.ts +16 -0
- package/src/utils/isBrowser.ts +1 -0
- package/src/utils/jsonEncodeDecode.ts +15 -0
- package/src/utils/objectUtils.ts +116 -0
- package/src/utils/popup.ts +30 -0
- package/src/utils/searchJson.ts +51 -0
- package/src/utils/stepUtils.ts +45 -0
- package/src/utils/truncate.ts +6 -0
- package/test/setup.ts +1 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,1573 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { Store } from 'unistore';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
BundleResponse,
|
|
6
|
+
// IntegrationResponse,
|
|
7
|
+
PreviewMetadata,
|
|
8
|
+
TemplateField,
|
|
9
|
+
TemplateStep,
|
|
10
|
+
ConditionalFields,
|
|
11
|
+
MarketplaceDetail,
|
|
12
|
+
MarketplaceAppAuthorizationType,
|
|
13
|
+
} from '@/interfaces';
|
|
14
|
+
import { StepStateStep, State } from '@/types/store';
|
|
15
|
+
import { Authorization } from '@/types';
|
|
16
|
+
import { initialState } from '@/store/initialState';
|
|
17
|
+
import { decodeJSON } from '@/utils/jsonEncodeDecode';
|
|
18
|
+
import { areParentValuesValid } from '@/utils/stepUtils';
|
|
19
|
+
|
|
20
|
+
export const actionFunctions = (storeSnapshot: Store<State>) => ({
|
|
21
|
+
setStoreState(state: State, partialUpdate: Partial<State>): Partial<State> {
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
...partialUpdate,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
setBaseData(state: State, bundleResponse: BundleResponse): Partial<State> {
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
integrations: bundleResponse.integrations.map((el) => ({
|
|
31
|
+
...el,
|
|
32
|
+
loading: false,
|
|
33
|
+
})),
|
|
34
|
+
templates: bundleResponse.templates,
|
|
35
|
+
fetchingIntegrations: false,
|
|
36
|
+
fetchingTemplates: false,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
setSteps(state: State, templateSteps: TemplateStep[]): Partial<State> {
|
|
41
|
+
const parsedSteps: StepStateStep[] = [];
|
|
42
|
+
let itemIndex = -1;
|
|
43
|
+
const appAuthIsAdded: number[] = [];
|
|
44
|
+
templateSteps.forEach((element) => {
|
|
45
|
+
const { authorization_type } = element;
|
|
46
|
+
const { app } = authorization_type;
|
|
47
|
+
const hideAuthorizaiton = element.hide_authorization;
|
|
48
|
+
|
|
49
|
+
if (!hideAuthorizaiton && !appAuthIsAdded.includes(app.id)) {
|
|
50
|
+
appAuthIsAdded.push(app.id);
|
|
51
|
+
let stepTitle: string = element.activity.app.name;
|
|
52
|
+
let stepIcon: string = element.activity.app.icon_url;
|
|
53
|
+
if (element.activity.type === 'MAKE_HTTP_CALL') {
|
|
54
|
+
stepTitle = element.authorization_type.app.name;
|
|
55
|
+
stepIcon = element.authorization_type.app.icon_url;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
itemIndex += 1;
|
|
59
|
+
// step has auth required so split into two.
|
|
60
|
+
parsedSteps.push({
|
|
61
|
+
stepId: element.id,
|
|
62
|
+
title: `${stepTitle} Account`,
|
|
63
|
+
iconUrl: stepIcon,
|
|
64
|
+
isCompleted: false,
|
|
65
|
+
isCurrentlyOpen: false,
|
|
66
|
+
type: 'AUTH',
|
|
67
|
+
requiredFields: [element.id], // auth if required will always be named like this
|
|
68
|
+
invalidFields: {
|
|
69
|
+
[element.id]: '',
|
|
70
|
+
},
|
|
71
|
+
isValid: false,
|
|
72
|
+
itemIndex,
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
// auth is implicit so we will select the first available auth
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// if (element.is_visible) {
|
|
79
|
+
// // check if we need to show the config step at all
|
|
80
|
+
// if (element.template_fields.length > 0) {
|
|
81
|
+
// // step has template fields with at least one visible
|
|
82
|
+
// const hasVisibleTemplateFields =
|
|
83
|
+
// element.template_fields.filter((el) => el.is_visible).length > 0;
|
|
84
|
+
|
|
85
|
+
// // check which of these are required
|
|
86
|
+
// const requiredFields = element.template_fields
|
|
87
|
+
// .filter((el) => el.is_required && el.is_visible)
|
|
88
|
+
// .map((field) => field.id);
|
|
89
|
+
|
|
90
|
+
// // check if no default value is provided
|
|
91
|
+
// const invalidFields = element.template_fields
|
|
92
|
+
// .filter(
|
|
93
|
+
// (el) => el.is_required && !el.default_value && el.is_visible,
|
|
94
|
+
// )
|
|
95
|
+
// .reduce((prev, field) => ({ ...prev, [field.id]: '' }), {});
|
|
96
|
+
|
|
97
|
+
// const isValidDefault = Object.keys(invalidFields).length < 1;
|
|
98
|
+
|
|
99
|
+
// if (hasVisibleTemplateFields) {
|
|
100
|
+
// itemIndex += 1;
|
|
101
|
+
// parsedSteps.push({
|
|
102
|
+
// stepId: element.id,
|
|
103
|
+
// title: element.title,
|
|
104
|
+
// iconUrl: element.activity.app.icon_url,
|
|
105
|
+
// isCompleted: false,
|
|
106
|
+
// isCurrentlyOpen: false,
|
|
107
|
+
// type: 'CONFIGURATION',
|
|
108
|
+
// requiredFields,
|
|
109
|
+
// invalidFields,
|
|
110
|
+
// isValid: isValidDefault,
|
|
111
|
+
// itemIndex,
|
|
112
|
+
// });
|
|
113
|
+
// }
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
});
|
|
117
|
+
templateSteps.forEach((element) => {
|
|
118
|
+
if (element.is_visible) {
|
|
119
|
+
// check if we need to show the config step at all
|
|
120
|
+
if (element.template_fields.length > 0) {
|
|
121
|
+
// step has template fields with at least one visible
|
|
122
|
+
const hasVisibleTemplateFields =
|
|
123
|
+
element.template_fields.filter((el) => el.is_visible).length > 0;
|
|
124
|
+
|
|
125
|
+
// check which of these are required
|
|
126
|
+
const requiredFields = element.template_fields
|
|
127
|
+
.filter((el) => el.is_required && el.is_visible)
|
|
128
|
+
.map((field) => field.id);
|
|
129
|
+
|
|
130
|
+
// check if no default value is provided
|
|
131
|
+
const invalidFields = element.template_fields
|
|
132
|
+
.filter(
|
|
133
|
+
(el) => el.is_required && !el.default_value && el.is_visible,
|
|
134
|
+
)
|
|
135
|
+
.reduce((prev, field) => ({ ...prev, [field.id]: '' }), {});
|
|
136
|
+
|
|
137
|
+
const isValidDefault = Object.keys(invalidFields).length < 1;
|
|
138
|
+
|
|
139
|
+
if (hasVisibleTemplateFields) {
|
|
140
|
+
itemIndex += 1;
|
|
141
|
+
parsedSteps.push({
|
|
142
|
+
stepId: element.id,
|
|
143
|
+
title: element.title,
|
|
144
|
+
description: element.description || '',
|
|
145
|
+
iconUrl: element.activity.app.icon_url,
|
|
146
|
+
isCompleted: false,
|
|
147
|
+
isCurrentlyOpen: false,
|
|
148
|
+
type: 'CONFIGURATION',
|
|
149
|
+
requiredFields,
|
|
150
|
+
invalidFields,
|
|
151
|
+
isValid: isValidDefault,
|
|
152
|
+
itemIndex,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
...state,
|
|
161
|
+
stepState: {
|
|
162
|
+
steps: parsedSteps,
|
|
163
|
+
fieldsListData: null,
|
|
164
|
+
currentStep: parsedSteps[0],
|
|
165
|
+
stepIndex: 0,
|
|
166
|
+
showValidation: false,
|
|
167
|
+
allStepsCompleted: false,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
setIntegrationLoadingState(
|
|
173
|
+
state: State,
|
|
174
|
+
data: {
|
|
175
|
+
integrationId: number;
|
|
176
|
+
isLoading: boolean;
|
|
177
|
+
op: 'edit' | 'delete' | 'edit-name';
|
|
178
|
+
nextVal?: boolean;
|
|
179
|
+
updatedName?: string;
|
|
180
|
+
},
|
|
181
|
+
): Partial<State> {
|
|
182
|
+
const { integrationId, isLoading, op, nextVal } = data;
|
|
183
|
+
const index = state.integrations.findIndex((el) => el.id === integrationId);
|
|
184
|
+
if (op === 'delete') {
|
|
185
|
+
return {
|
|
186
|
+
...state,
|
|
187
|
+
integrations: state.integrations.filter(
|
|
188
|
+
(el) => el.id !== integrationId,
|
|
189
|
+
),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (op === 'edit' && index > -1) {
|
|
193
|
+
const int = {
|
|
194
|
+
...state.integrations[index],
|
|
195
|
+
loading: isLoading,
|
|
196
|
+
};
|
|
197
|
+
if (nextVal !== null && nextVal !== undefined) {
|
|
198
|
+
int.status = nextVal ? 'ACTIVE' : 'INACTIVE';
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
...state,
|
|
202
|
+
integrations: [
|
|
203
|
+
...state.integrations.slice(0, index),
|
|
204
|
+
int,
|
|
205
|
+
...state.integrations.slice(index + 1),
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (op === 'edit-name' && index > -1) {
|
|
210
|
+
const int = {
|
|
211
|
+
...state.integrations[index],
|
|
212
|
+
name: `${data.updatedName}`,
|
|
213
|
+
loading: isLoading,
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
...state,
|
|
217
|
+
integrations: [
|
|
218
|
+
...state.integrations.slice(0, index),
|
|
219
|
+
int,
|
|
220
|
+
...state.integrations.slice(index + 1),
|
|
221
|
+
],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
...state,
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
showStepValidationState(state: State): Partial<State> {
|
|
230
|
+
const { stepState } = state;
|
|
231
|
+
return {
|
|
232
|
+
stepState: {
|
|
233
|
+
...stepState,
|
|
234
|
+
showValidation: true,
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
hideStepValidationState(state: State): Partial<State> {
|
|
240
|
+
const { stepState } = state;
|
|
241
|
+
return {
|
|
242
|
+
stepState: {
|
|
243
|
+
...stepState,
|
|
244
|
+
showValidation: false,
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
gotoNextStep(state: State): Partial<State> {
|
|
250
|
+
const { stepState } = state;
|
|
251
|
+
if (stepState) {
|
|
252
|
+
const newIndex = Number(stepState.stepIndex) + 1;
|
|
253
|
+
const step = stepState.steps[Number(stepState.stepIndex) + 1];
|
|
254
|
+
const updatedStep = {
|
|
255
|
+
...stepState.steps[state.stepState.stepIndex],
|
|
256
|
+
isCompleted: true,
|
|
257
|
+
};
|
|
258
|
+
if (!step) {
|
|
259
|
+
// last step reached
|
|
260
|
+
return {
|
|
261
|
+
stepState: {
|
|
262
|
+
...stepState,
|
|
263
|
+
steps: [
|
|
264
|
+
...stepState.steps.slice(0, stepState.stepIndex),
|
|
265
|
+
updatedStep,
|
|
266
|
+
...stepState.steps.slice(stepState.stepIndex + 1),
|
|
267
|
+
],
|
|
268
|
+
currentStep: {
|
|
269
|
+
type: 'CONFIRMATION',
|
|
270
|
+
},
|
|
271
|
+
stepIndex: newIndex,
|
|
272
|
+
allStepsCompleted: true,
|
|
273
|
+
showValidation: false,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
stepState: {
|
|
280
|
+
...stepState,
|
|
281
|
+
steps: [
|
|
282
|
+
...stepState.steps.slice(0, stepState.stepIndex),
|
|
283
|
+
updatedStep,
|
|
284
|
+
...stepState.steps.slice(stepState.stepIndex + 1),
|
|
285
|
+
],
|
|
286
|
+
currentStep: {
|
|
287
|
+
...step,
|
|
288
|
+
},
|
|
289
|
+
stepIndex: newIndex,
|
|
290
|
+
showValidation: false,
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return state;
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
gotoPreviousStep(state: State): Partial<State> {
|
|
298
|
+
if (state.stepState) {
|
|
299
|
+
const newIndex = Number(state.stepState.stepIndex) - 1;
|
|
300
|
+
const step = state.stepState.steps[Number(state.stepState.stepIndex) - 1];
|
|
301
|
+
let showStepValidation = !step.isValid;
|
|
302
|
+
if (state.genericData.isReadOnly) {
|
|
303
|
+
showStepValidation = false;
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
stepState: {
|
|
307
|
+
...state.stepState,
|
|
308
|
+
currentStep: step,
|
|
309
|
+
stepIndex: newIndex,
|
|
310
|
+
showValidation: showStepValidation,
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return state;
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
gotoStepInPreview: (
|
|
318
|
+
state: State,
|
|
319
|
+
previewMetadata: PreviewMetadata,
|
|
320
|
+
): Partial<State> => {
|
|
321
|
+
const { stepState } = state;
|
|
322
|
+
const { stepId, type } = previewMetadata;
|
|
323
|
+
|
|
324
|
+
if (stepId && type !== 'CONFIRMATION') {
|
|
325
|
+
// go to a particular step
|
|
326
|
+
const stepIndexToNavigateTo = stepState.steps.findIndex(
|
|
327
|
+
(el) => el.stepId === stepId && el.type === type,
|
|
328
|
+
);
|
|
329
|
+
if (stepIndexToNavigateTo > -1)
|
|
330
|
+
return {
|
|
331
|
+
stepState: {
|
|
332
|
+
...state.stepState,
|
|
333
|
+
currentStep: stepState.steps[stepIndexToNavigateTo],
|
|
334
|
+
stepIndex: stepIndexToNavigateTo,
|
|
335
|
+
allStepsCompleted: false,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!stepId && type === 'CONFIRMATION') {
|
|
341
|
+
return {
|
|
342
|
+
stepState: {
|
|
343
|
+
...stepState,
|
|
344
|
+
currentStep: {
|
|
345
|
+
type: 'CONFIRMATION',
|
|
346
|
+
},
|
|
347
|
+
stepIndex: stepState.steps.length,
|
|
348
|
+
allStepsCompleted: true,
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return state;
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
gotoStep: (state: State, stepIndex: number): Partial<State> => {
|
|
356
|
+
const { stepState } = state;
|
|
357
|
+
const { stepIndex: oldStepIndex } = stepState;
|
|
358
|
+
if (stepState) {
|
|
359
|
+
const { currentStep } = stepState;
|
|
360
|
+
const stepToNavigateTo = stepState.steps[stepIndex];
|
|
361
|
+
|
|
362
|
+
if (state.genericData.isPreviewMode) {
|
|
363
|
+
// we can go to any step in preview mode
|
|
364
|
+
if (stepIndex === stepState.steps.length) {
|
|
365
|
+
return {
|
|
366
|
+
stepState: {
|
|
367
|
+
...stepState,
|
|
368
|
+
currentStep: {
|
|
369
|
+
type: 'CONFIRMATION',
|
|
370
|
+
},
|
|
371
|
+
stepIndex: stepState.steps.length,
|
|
372
|
+
allStepsCompleted: true,
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
stepState: {
|
|
378
|
+
...state.stepState,
|
|
379
|
+
currentStep: {
|
|
380
|
+
...stepToNavigateTo,
|
|
381
|
+
},
|
|
382
|
+
stepIndex,
|
|
383
|
+
allStepsCompleted: false,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// go to any step in isReadOnly Mode
|
|
389
|
+
if (state.genericData.isReadOnly) {
|
|
390
|
+
return {
|
|
391
|
+
stepState: {
|
|
392
|
+
...state.stepState,
|
|
393
|
+
currentStep: {
|
|
394
|
+
...stepToNavigateTo,
|
|
395
|
+
},
|
|
396
|
+
stepIndex,
|
|
397
|
+
// allStepsCompleted: false,
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// navigate directly to confirmation page if all steps are completed
|
|
403
|
+
if (
|
|
404
|
+
stepState.allStepsCompleted &&
|
|
405
|
+
stepIndex === stepState.steps.length &&
|
|
406
|
+
stepState.currentStep?.type !== 'CONFIRMATION' &&
|
|
407
|
+
stepState.currentStep?.isValid
|
|
408
|
+
) {
|
|
409
|
+
return {
|
|
410
|
+
stepState: {
|
|
411
|
+
...stepState,
|
|
412
|
+
currentStep: {
|
|
413
|
+
type: 'CONFIRMATION',
|
|
414
|
+
},
|
|
415
|
+
stepIndex: stepState.steps.length,
|
|
416
|
+
allStepsCompleted: true,
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// navigate to confirmation from final step
|
|
422
|
+
if (
|
|
423
|
+
currentStep &&
|
|
424
|
+
currentStep.type !== 'CONFIRMATION' &&
|
|
425
|
+
currentStep.isValid &&
|
|
426
|
+
oldStepIndex === stepState.steps.length - 1 &&
|
|
427
|
+
stepIndex === stepState.steps.length
|
|
428
|
+
) {
|
|
429
|
+
const updatedStep = {
|
|
430
|
+
...stepState.steps[oldStepIndex],
|
|
431
|
+
isCompleted: true,
|
|
432
|
+
};
|
|
433
|
+
return {
|
|
434
|
+
stepState: {
|
|
435
|
+
...stepState,
|
|
436
|
+
steps: [
|
|
437
|
+
...stepState.steps.slice(0, oldStepIndex),
|
|
438
|
+
updatedStep,
|
|
439
|
+
...stepState.steps.slice(oldStepIndex + 1),
|
|
440
|
+
],
|
|
441
|
+
currentStep: {
|
|
442
|
+
type: 'CONFIRMATION',
|
|
443
|
+
},
|
|
444
|
+
stepIndex,
|
|
445
|
+
allStepsCompleted: true,
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// navigate to a step if it is completed
|
|
451
|
+
if (
|
|
452
|
+
(stepToNavigateTo && stepToNavigateTo.isCompleted) ||
|
|
453
|
+
(stepToNavigateTo &&
|
|
454
|
+
stepState.currentStep?.type !== 'CONFIRMATION' &&
|
|
455
|
+
stepState.currentStep?.isCompleted &&
|
|
456
|
+
stepToNavigateTo.type === 'CONFIRMATION')
|
|
457
|
+
) {
|
|
458
|
+
return {
|
|
459
|
+
stepState: {
|
|
460
|
+
...state.stepState,
|
|
461
|
+
currentStep: {
|
|
462
|
+
...stepToNavigateTo,
|
|
463
|
+
},
|
|
464
|
+
stepIndex,
|
|
465
|
+
showValidation: !stepToNavigateTo.isValid,
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (
|
|
470
|
+
// clicking on next step with current completed
|
|
471
|
+
stepState.currentStep?.type !== 'CONFIRMATION' &&
|
|
472
|
+
stepState.currentStep?.isValid &&
|
|
473
|
+
stepIndex === oldStepIndex + 1
|
|
474
|
+
) {
|
|
475
|
+
const updatedStep = {
|
|
476
|
+
...stepState.steps[oldStepIndex],
|
|
477
|
+
isCompleted: true,
|
|
478
|
+
isValid: true,
|
|
479
|
+
};
|
|
480
|
+
return {
|
|
481
|
+
stepState: {
|
|
482
|
+
...state.stepState,
|
|
483
|
+
steps: [
|
|
484
|
+
...stepState.steps.slice(0, oldStepIndex),
|
|
485
|
+
updatedStep,
|
|
486
|
+
...stepState.steps.slice(oldStepIndex + 1),
|
|
487
|
+
],
|
|
488
|
+
currentStep: {
|
|
489
|
+
...stepToNavigateTo,
|
|
490
|
+
},
|
|
491
|
+
stepIndex,
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// navigate to a step immediately following a completed step
|
|
497
|
+
if (
|
|
498
|
+
stepState.steps[stepIndex - 1] &&
|
|
499
|
+
stepState.steps[stepIndex - 1].isCompleted &&
|
|
500
|
+
stepState.steps[stepIndex].type !== 'CONFIRMATION'
|
|
501
|
+
) {
|
|
502
|
+
return {
|
|
503
|
+
stepState: {
|
|
504
|
+
...state.stepState,
|
|
505
|
+
currentStep: {
|
|
506
|
+
...stepToNavigateTo,
|
|
507
|
+
},
|
|
508
|
+
stepIndex,
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return state;
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
verifyStepValidity(state: State, stepId: number) {
|
|
517
|
+
const { stepDataMapping, conditionalFieldMapping } = state;
|
|
518
|
+
const element = stepDataMapping[stepId];
|
|
519
|
+
|
|
520
|
+
const fieldsData = Object.keys(element).map((fieldId) => {
|
|
521
|
+
const ele = element[Number(fieldId)];
|
|
522
|
+
return ele;
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
const visibleFields = fieldsData.filter((el) => {
|
|
526
|
+
// filter out hidden conditional fields
|
|
527
|
+
const fieldConditions = conditionalFieldMapping[stepId][el.machineName];
|
|
528
|
+
if (fieldConditions) {
|
|
529
|
+
return areParentValuesValid(stepId, fieldConditions, stepDataMapping);
|
|
530
|
+
}
|
|
531
|
+
return true;
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const invalid = visibleFields.filter((el) => {
|
|
535
|
+
if (el.isRequired) {
|
|
536
|
+
if (el.type === 'SECTION') {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
if (!el.value && !el.objectValue) {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
if (el.type === 'CHECKBOX' && el.value === '0') {
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (el.value && !el.passesRegexTest) {
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
return false;
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
const isValid = !(invalid.length > 0);
|
|
553
|
+
|
|
554
|
+
return {
|
|
555
|
+
stepState: {
|
|
556
|
+
...state.stepState,
|
|
557
|
+
currentStep: {
|
|
558
|
+
...state.stepState.currentStep,
|
|
559
|
+
isValid,
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
};
|
|
563
|
+
},
|
|
564
|
+
|
|
565
|
+
getStepState() {
|
|
566
|
+
return storeSnapshot.getState().stepState;
|
|
567
|
+
},
|
|
568
|
+
|
|
569
|
+
setGenericData(
|
|
570
|
+
state: State,
|
|
571
|
+
genericData: Partial<{
|
|
572
|
+
templateId: number;
|
|
573
|
+
deploymentId: number;
|
|
574
|
+
isPreviewMode: boolean;
|
|
575
|
+
marketplaceId?: number;
|
|
576
|
+
marketplaceDetail?: MarketplaceDetail;
|
|
577
|
+
IUAccountsData?: MarketplaceAppAuthorizationType;
|
|
578
|
+
testMultipurpose?: boolean;
|
|
579
|
+
}>,
|
|
580
|
+
): Partial<State> {
|
|
581
|
+
return {
|
|
582
|
+
genericData: {
|
|
583
|
+
...state.genericData,
|
|
584
|
+
...genericData,
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
},
|
|
588
|
+
|
|
589
|
+
setStepMapping(
|
|
590
|
+
state: State,
|
|
591
|
+
steps: TemplateStep[],
|
|
592
|
+
integrationId?: number,
|
|
593
|
+
): Partial<State> {
|
|
594
|
+
const integrationIdToEdit = state.integrationIdToEdit || integrationId;
|
|
595
|
+
|
|
596
|
+
// find first step that is of trigger/query type
|
|
597
|
+
const stepWithActivityOutput =
|
|
598
|
+
steps.find(
|
|
599
|
+
(step) =>
|
|
600
|
+
step.activity &&
|
|
601
|
+
(step.activity.type === 'TRIGGER' ||
|
|
602
|
+
step.activity.type === 'QUERY' ||
|
|
603
|
+
step.activity.type === 'ADAPTER'),
|
|
604
|
+
) || null;
|
|
605
|
+
|
|
606
|
+
let fieldListMappingData: {
|
|
607
|
+
[machineName: string]: TemplateField & { stepId: number };
|
|
608
|
+
} = {};
|
|
609
|
+
|
|
610
|
+
let standardFieldsInsideMapping: {
|
|
611
|
+
[k: string]: string | Record<string, string>;
|
|
612
|
+
} = {};
|
|
613
|
+
|
|
614
|
+
let stepIdWithFieldMapping = '';
|
|
615
|
+
|
|
616
|
+
fieldListMappingData = steps
|
|
617
|
+
.map((step) =>
|
|
618
|
+
step.template_fields.reduce((prev, next) => {
|
|
619
|
+
if (next.activity_field?.type === 'FIELD_LIST') {
|
|
620
|
+
return {
|
|
621
|
+
...prev,
|
|
622
|
+
[`{steps.${step.machine_name}.field_list}`]: {
|
|
623
|
+
...next,
|
|
624
|
+
stepId: step.id,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
return prev;
|
|
629
|
+
}, {}),
|
|
630
|
+
)
|
|
631
|
+
.filter((el) => Object.keys(el).length > 0)
|
|
632
|
+
.reduce((prev, next) => ({ ...prev, ...next }), {});
|
|
633
|
+
|
|
634
|
+
const stepMapping: any = steps.reduce((prev, step) => {
|
|
635
|
+
let selectedAuthId = 0;
|
|
636
|
+
let shouldAutoVerifyAuth = false;
|
|
637
|
+
if (
|
|
638
|
+
state.genericData.isReadOnly &&
|
|
639
|
+
integrationIdToEdit &&
|
|
640
|
+
step.step_authorization
|
|
641
|
+
) {
|
|
642
|
+
selectedAuthId = step.step_authorization; // set selected auth in read only mode
|
|
643
|
+
} else if (
|
|
644
|
+
step.hide_authorization ||
|
|
645
|
+
state.genericData.isPreviewMode ||
|
|
646
|
+
(step.is_workspace_app_step && step.activity.type === 'FORM')
|
|
647
|
+
) {
|
|
648
|
+
shouldAutoVerifyAuth = true;
|
|
649
|
+
selectedAuthId = step.step_authorization
|
|
650
|
+
? step.step_authorization
|
|
651
|
+
: step.authorization_type.authorizations[0]?.id ?? null;
|
|
652
|
+
} else if (state.stepMapping[step.id]) {
|
|
653
|
+
selectedAuthId = state.stepMapping[step.id].selectedAuthId;
|
|
654
|
+
} else if (integrationIdToEdit && step.step_authorization) {
|
|
655
|
+
shouldAutoVerifyAuth = true;
|
|
656
|
+
selectedAuthId = step.step_authorization; // set selected auth in edit mode
|
|
657
|
+
}
|
|
658
|
+
return {
|
|
659
|
+
...prev,
|
|
660
|
+
[step.id]: {
|
|
661
|
+
step,
|
|
662
|
+
integrationStepId: step.step_instance,
|
|
663
|
+
authorizations:
|
|
664
|
+
step.authorization_type.authorizations?.map((el) => ({
|
|
665
|
+
authorizationId: el.id,
|
|
666
|
+
userIdentity: el.user_identity,
|
|
667
|
+
authType: el.authorization_type,
|
|
668
|
+
disableLink: el.disable_link,
|
|
669
|
+
isErrored: false,
|
|
670
|
+
isVerifying: false,
|
|
671
|
+
isVerified: false,
|
|
672
|
+
accessToken: el?.access_token || null,
|
|
673
|
+
})) ?? [],
|
|
674
|
+
isAuthVerified: shouldAutoVerifyAuth,
|
|
675
|
+
isUserinfoRequired: step.authorization_type?.is_userinfo_required,
|
|
676
|
+
selectedAuthId,
|
|
677
|
+
invalidFields: {},
|
|
678
|
+
isValid: !!integrationIdToEdit,
|
|
679
|
+
isCompleted: !!integrationIdToEdit,
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
}, {});
|
|
683
|
+
|
|
684
|
+
const parsedStepsCopy = state.stepState.steps.map((el) => ({
|
|
685
|
+
...el,
|
|
686
|
+
invalidFields: {},
|
|
687
|
+
isValid: !!stepMapping[el.stepId].selectedAuthId,
|
|
688
|
+
isCompleted: !!stepMapping[el.stepId].selectedAuthId,
|
|
689
|
+
}));
|
|
690
|
+
|
|
691
|
+
function processTemplateFields(templateFields: any, step: any) {
|
|
692
|
+
return templateFields.reduce((acc: any, curr: any) => {
|
|
693
|
+
let value = null;
|
|
694
|
+
let objectValue = null;
|
|
695
|
+
let changedDynamicFields = [];
|
|
696
|
+
const isEditMode = !!integrationIdToEdit;
|
|
697
|
+
const isFieldMapping = curr.activity_field?.type === 'FIELD_MAPPING';
|
|
698
|
+
const isDynamicField = curr.activity_field?.type === 'DYNAMIC';
|
|
699
|
+
const isStepVisible = !!step.is_visible;
|
|
700
|
+
const isFieldVisible = !!curr.is_visible;
|
|
701
|
+
const userData =
|
|
702
|
+
(curr.app_user_data &&
|
|
703
|
+
curr.app_user_data.length > 0 &&
|
|
704
|
+
curr.app_user_data[0]) ||
|
|
705
|
+
null;
|
|
706
|
+
|
|
707
|
+
if (isEditMode && !isFieldMapping && userData && isFieldVisible) {
|
|
708
|
+
if (isDynamicField) {
|
|
709
|
+
try {
|
|
710
|
+
objectValue = JSON.parse(`${userData.value || '{}'}`);
|
|
711
|
+
changedDynamicFields = JSON.parse(
|
|
712
|
+
`${userData.changed_dynamic_fields || '[]'}`,
|
|
713
|
+
);
|
|
714
|
+
} catch (err) {
|
|
715
|
+
console.error(err);
|
|
716
|
+
}
|
|
717
|
+
} else {
|
|
718
|
+
value = userData.value;
|
|
719
|
+
}
|
|
720
|
+
} else if (!isStepVisible || !isFieldVisible) {
|
|
721
|
+
value = curr.default_value;
|
|
722
|
+
if (userData && userData.value) value = userData.value;
|
|
723
|
+
} else if (isFieldMapping && userData && userData.value) {
|
|
724
|
+
const mappingData: Record<
|
|
725
|
+
string,
|
|
726
|
+
string | Record<string, string>
|
|
727
|
+
> = JSON.parse(`${userData.value}`);
|
|
728
|
+
|
|
729
|
+
stepIdWithFieldMapping = `${step.id}`;
|
|
730
|
+
|
|
731
|
+
standardFieldsInsideMapping = Object.fromEntries(
|
|
732
|
+
Object.entries(mappingData).filter(
|
|
733
|
+
([key]) => typeof mappingData[key] === 'string',
|
|
734
|
+
),
|
|
735
|
+
);
|
|
736
|
+
|
|
737
|
+
const mapping = Object.fromEntries(
|
|
738
|
+
Object.entries(mappingData).filter(
|
|
739
|
+
([key]) => typeof mappingData[key] !== 'string',
|
|
740
|
+
),
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
objectValue = mapping[Object.keys(mapping)[0]];
|
|
744
|
+
} else {
|
|
745
|
+
value = '';
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const newAcc = {
|
|
749
|
+
...acc,
|
|
750
|
+
[curr.id]: {
|
|
751
|
+
fieldId: curr.id,
|
|
752
|
+
value,
|
|
753
|
+
objectValue,
|
|
754
|
+
machineName: curr.activity_field?.machine_name,
|
|
755
|
+
isRequired: curr.activity_field?.is_required || curr.is_required,
|
|
756
|
+
isVisible: curr.is_visible,
|
|
757
|
+
isDynamic:
|
|
758
|
+
curr.activity_field?.type === 'DYNAMIC' ||
|
|
759
|
+
curr.activity_field?.type === 'FIELD_MAPPING',
|
|
760
|
+
integrationFieldId:
|
|
761
|
+
curr.app_user_data && curr.app_user_data.length > 0
|
|
762
|
+
? curr.app_user_data[0].id
|
|
763
|
+
: null,
|
|
764
|
+
isAddedInMapping: !!curr.added_in_mapping,
|
|
765
|
+
type: curr.activity_field?.type || curr.type,
|
|
766
|
+
regex: curr.activity_field?.regex,
|
|
767
|
+
regexErrorMessage: curr.activity_field?.regex_error_message,
|
|
768
|
+
passesRegexTest: true,
|
|
769
|
+
isChanged: userData ? userData.is_changed : false,
|
|
770
|
+
changedDynamicFields,
|
|
771
|
+
},
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
if (curr?.type === 'SECTION' && curr?.template_fields) {
|
|
775
|
+
return {
|
|
776
|
+
...newAcc,
|
|
777
|
+
...processTemplateFields(curr.template_fields, step),
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return newAcc;
|
|
782
|
+
}, {});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
const stepDataMapping: Record<number, any> = steps.reduce(
|
|
786
|
+
(prev, step) => ({
|
|
787
|
+
...prev,
|
|
788
|
+
[step.id]: {
|
|
789
|
+
...state.stepDataMapping[step.id],
|
|
790
|
+
...processTemplateFields(step.template_fields, step),
|
|
791
|
+
},
|
|
792
|
+
}),
|
|
793
|
+
{},
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
// set standard field values from mapping data
|
|
797
|
+
if (
|
|
798
|
+
Object.keys(standardFieldsInsideMapping).length > 0 &&
|
|
799
|
+
stepIdWithFieldMapping
|
|
800
|
+
) {
|
|
801
|
+
Object.keys(stepDataMapping).forEach((stepId) => {
|
|
802
|
+
const stepObj = stepDataMapping[Number(stepId)];
|
|
803
|
+
Object.keys(stepObj).forEach((fieldId) => {
|
|
804
|
+
const field = stepObj[Number(fieldId)];
|
|
805
|
+
if (standardFieldsInsideMapping[field.machineName]) {
|
|
806
|
+
field.value = standardFieldsInsideMapping[field.machineName];
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
return {
|
|
813
|
+
stepState: integrationIdToEdit
|
|
814
|
+
? {
|
|
815
|
+
...state.stepState,
|
|
816
|
+
steps: parsedStepsCopy,
|
|
817
|
+
currentStep: parsedStepsCopy[0],
|
|
818
|
+
showValidation: !integrationIdToEdit,
|
|
819
|
+
allStepsCompleted: !!integrationIdToEdit,
|
|
820
|
+
}
|
|
821
|
+
: state.stepState,
|
|
822
|
+
stepMapping: {
|
|
823
|
+
...state.stepMapping,
|
|
824
|
+
...stepMapping,
|
|
825
|
+
},
|
|
826
|
+
stepDataMapping: {
|
|
827
|
+
...state.stepDataMapping,
|
|
828
|
+
...stepDataMapping,
|
|
829
|
+
},
|
|
830
|
+
fieldListMapping: fieldListMappingData,
|
|
831
|
+
genericData: {
|
|
832
|
+
...state.genericData,
|
|
833
|
+
stepWithActivityOutput,
|
|
834
|
+
},
|
|
835
|
+
};
|
|
836
|
+
},
|
|
837
|
+
|
|
838
|
+
setActivityOutputData(
|
|
839
|
+
state: State,
|
|
840
|
+
data: {
|
|
841
|
+
activityOutputData: {
|
|
842
|
+
value: string;
|
|
843
|
+
text: string;
|
|
844
|
+
}[];
|
|
845
|
+
},
|
|
846
|
+
): Partial<State> {
|
|
847
|
+
return {
|
|
848
|
+
...state,
|
|
849
|
+
activityOutputData: data.activityOutputData,
|
|
850
|
+
};
|
|
851
|
+
},
|
|
852
|
+
|
|
853
|
+
setAppsAuthData(
|
|
854
|
+
state: State,
|
|
855
|
+
data: {
|
|
856
|
+
appsAuthData: {
|
|
857
|
+
appId: number;
|
|
858
|
+
isVerified: boolean;
|
|
859
|
+
}[];
|
|
860
|
+
},
|
|
861
|
+
): Partial<State> {
|
|
862
|
+
return {
|
|
863
|
+
...state,
|
|
864
|
+
appsAuthData: data.appsAuthData,
|
|
865
|
+
};
|
|
866
|
+
},
|
|
867
|
+
|
|
868
|
+
setDynamicFieldData(
|
|
869
|
+
state: State,
|
|
870
|
+
data: {
|
|
871
|
+
dynamicFieldData: {
|
|
872
|
+
[fieldId: string]: (string | Record<string, string>)[];
|
|
873
|
+
};
|
|
874
|
+
},
|
|
875
|
+
): Partial<State> {
|
|
876
|
+
return {
|
|
877
|
+
...state,
|
|
878
|
+
dynamicFieldData: Object.keys(data.dynamicFieldData).reduce(
|
|
879
|
+
(prev, next) => ({
|
|
880
|
+
...prev,
|
|
881
|
+
[`{${next}}`]: data.dynamicFieldData[next],
|
|
882
|
+
}),
|
|
883
|
+
{},
|
|
884
|
+
),
|
|
885
|
+
};
|
|
886
|
+
},
|
|
887
|
+
|
|
888
|
+
setIncomingWebhookPayload(
|
|
889
|
+
state: State,
|
|
890
|
+
data: {
|
|
891
|
+
incomingWebhookPayload: {
|
|
892
|
+
[fieldId: string]: string | Record<string, string>;
|
|
893
|
+
};
|
|
894
|
+
},
|
|
895
|
+
): Partial<State> {
|
|
896
|
+
return {
|
|
897
|
+
...state,
|
|
898
|
+
incomingWebhookPayload: data.incomingWebhookPayload,
|
|
899
|
+
};
|
|
900
|
+
},
|
|
901
|
+
|
|
902
|
+
setParentChildMapping(state: State, steps: TemplateStep[]): Partial<State> {
|
|
903
|
+
const parentChildMapping = steps.reduce(
|
|
904
|
+
(prev, step) => ({
|
|
905
|
+
...prev,
|
|
906
|
+
[step.id]: {
|
|
907
|
+
...state.parentChildMapping[step.id],
|
|
908
|
+
...step.template_fields.reduce((acc, curr) => {
|
|
909
|
+
if (curr.activity_field)
|
|
910
|
+
return {
|
|
911
|
+
...acc,
|
|
912
|
+
[curr.activity_field?.machine_name]: {
|
|
913
|
+
fieldId: curr.id,
|
|
914
|
+
childFields: curr.activity_field?.child_fields
|
|
915
|
+
? JSON.parse(curr.activity_field?.child_fields ?? '[]')
|
|
916
|
+
: null,
|
|
917
|
+
parentFields: curr.activity_field?.parent_fields
|
|
918
|
+
? JSON.parse(curr.activity_field?.parent_fields ?? '[]')
|
|
919
|
+
: null,
|
|
920
|
+
},
|
|
921
|
+
};
|
|
922
|
+
return acc;
|
|
923
|
+
}, {}),
|
|
924
|
+
},
|
|
925
|
+
}),
|
|
926
|
+
{},
|
|
927
|
+
);
|
|
928
|
+
|
|
929
|
+
return {
|
|
930
|
+
parentChildMapping: {
|
|
931
|
+
...state.parentChildMapping,
|
|
932
|
+
...parentChildMapping,
|
|
933
|
+
},
|
|
934
|
+
};
|
|
935
|
+
},
|
|
936
|
+
|
|
937
|
+
setConditionalFieldMapping(
|
|
938
|
+
state: State,
|
|
939
|
+
steps: TemplateStep[],
|
|
940
|
+
): Partial<State> {
|
|
941
|
+
const conditionalFieldMapping = steps.reduce(
|
|
942
|
+
(prev, step) => ({
|
|
943
|
+
...prev,
|
|
944
|
+
[step.id]: {
|
|
945
|
+
...state.conditionalFieldMapping[step.id],
|
|
946
|
+
...step.template_fields.reduce((acc: { [key: string]: [] }, curr) => {
|
|
947
|
+
if (
|
|
948
|
+
curr.activity_field &&
|
|
949
|
+
!!curr.activity_field.conditional_fields
|
|
950
|
+
) {
|
|
951
|
+
const parentMachineName = curr.activity_field?.machine_name;
|
|
952
|
+
const parentFieldId = curr.id;
|
|
953
|
+
const conditions = (decodeJSON(
|
|
954
|
+
curr?.activity_field?.conditional_fields,
|
|
955
|
+
) || []) as ConditionalFields[];
|
|
956
|
+
return {
|
|
957
|
+
...acc, // conditions from previous fields
|
|
958
|
+
...conditions.reduce(
|
|
959
|
+
(accCondition: { [key: string]: [] }, currCondition) => {
|
|
960
|
+
const { value } = currCondition;
|
|
961
|
+
const childFields = (decodeJSON(
|
|
962
|
+
currCondition.field_array,
|
|
963
|
+
) || []) as string[];
|
|
964
|
+
return {
|
|
965
|
+
...accCondition,
|
|
966
|
+
...childFields.reduce(
|
|
967
|
+
(accChild, currChild) => ({
|
|
968
|
+
...accChild,
|
|
969
|
+
[currChild]: [
|
|
970
|
+
...(acc[currChild] || []), // current child conditions from previous fields
|
|
971
|
+
...(accCondition[currChild] || []), // current child conditions from previous condition array
|
|
972
|
+
{ value, parentMachineName, parentFieldId },
|
|
973
|
+
],
|
|
974
|
+
}),
|
|
975
|
+
{},
|
|
976
|
+
),
|
|
977
|
+
};
|
|
978
|
+
},
|
|
979
|
+
{},
|
|
980
|
+
),
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
return acc;
|
|
984
|
+
}, {}),
|
|
985
|
+
},
|
|
986
|
+
}),
|
|
987
|
+
{},
|
|
988
|
+
);
|
|
989
|
+
|
|
990
|
+
return {
|
|
991
|
+
conditionalFieldMapping: {
|
|
992
|
+
...state.conditionalFieldMapping,
|
|
993
|
+
...conditionalFieldMapping,
|
|
994
|
+
},
|
|
995
|
+
};
|
|
996
|
+
},
|
|
997
|
+
|
|
998
|
+
addAuthorization(
|
|
999
|
+
state: State,
|
|
1000
|
+
params: {
|
|
1001
|
+
stepId: number;
|
|
1002
|
+
authData: Authorization;
|
|
1003
|
+
},
|
|
1004
|
+
): Partial<State> {
|
|
1005
|
+
const { stepId, authData } = params;
|
|
1006
|
+
return {
|
|
1007
|
+
stepMapping: {
|
|
1008
|
+
...state.stepMapping,
|
|
1009
|
+
[stepId]: {
|
|
1010
|
+
...state.stepMapping[stepId],
|
|
1011
|
+
authorizations: [
|
|
1012
|
+
...state.stepMapping[stepId].authorizations,
|
|
1013
|
+
authData,
|
|
1014
|
+
],
|
|
1015
|
+
},
|
|
1016
|
+
},
|
|
1017
|
+
};
|
|
1018
|
+
},
|
|
1019
|
+
|
|
1020
|
+
addAppAuthorization(
|
|
1021
|
+
state: State,
|
|
1022
|
+
params: {
|
|
1023
|
+
appId: number;
|
|
1024
|
+
authData: Authorization;
|
|
1025
|
+
},
|
|
1026
|
+
): Partial<State> {
|
|
1027
|
+
const { appId, authData } = params;
|
|
1028
|
+
return {
|
|
1029
|
+
authMapping: {
|
|
1030
|
+
...state.authMapping,
|
|
1031
|
+
[appId]: {
|
|
1032
|
+
...state.authMapping[appId],
|
|
1033
|
+
authorizations: [
|
|
1034
|
+
...state.authMapping[appId]?.authorizations,
|
|
1035
|
+
authData,
|
|
1036
|
+
],
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1039
|
+
};
|
|
1040
|
+
},
|
|
1041
|
+
|
|
1042
|
+
setSelectedAuthByAppId(
|
|
1043
|
+
state: State,
|
|
1044
|
+
params: {
|
|
1045
|
+
appId: number;
|
|
1046
|
+
authId: number | null;
|
|
1047
|
+
},
|
|
1048
|
+
): Partial<State> {
|
|
1049
|
+
const { appId, authId } = params;
|
|
1050
|
+
return {
|
|
1051
|
+
selectedAuthByAppId: {
|
|
1052
|
+
...state.selectedAuthByAppId,
|
|
1053
|
+
[appId]: authId,
|
|
1054
|
+
},
|
|
1055
|
+
};
|
|
1056
|
+
},
|
|
1057
|
+
|
|
1058
|
+
removeAuthorization(
|
|
1059
|
+
state: State,
|
|
1060
|
+
params: {
|
|
1061
|
+
stepId: number;
|
|
1062
|
+
authId: number;
|
|
1063
|
+
},
|
|
1064
|
+
): Partial<State> {
|
|
1065
|
+
const { stepId, authId } = params;
|
|
1066
|
+
|
|
1067
|
+
const updatedArr = state.stepMapping[stepId].authorizations.filter(
|
|
1068
|
+
(el) => el.authorizationId !== authId,
|
|
1069
|
+
);
|
|
1070
|
+
|
|
1071
|
+
const step = state.stepState.currentStep as StepStateStep;
|
|
1072
|
+
return {
|
|
1073
|
+
stepState: {
|
|
1074
|
+
...state.stepState,
|
|
1075
|
+
currentStep: {
|
|
1076
|
+
...step,
|
|
1077
|
+
isValid: updatedArr.length > 0 ? step.isValid : false,
|
|
1078
|
+
isCompleted: updatedArr.length > 0 ? step.isCompleted : false,
|
|
1079
|
+
},
|
|
1080
|
+
},
|
|
1081
|
+
stepMapping: {
|
|
1082
|
+
...state.stepMapping,
|
|
1083
|
+
[stepId]: {
|
|
1084
|
+
...state.stepMapping[stepId],
|
|
1085
|
+
authorizations: updatedArr,
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
};
|
|
1089
|
+
},
|
|
1090
|
+
|
|
1091
|
+
toggleVerifyAuthorizationFlag(
|
|
1092
|
+
state: State,
|
|
1093
|
+
params: {
|
|
1094
|
+
stepId: number;
|
|
1095
|
+
authId: number;
|
|
1096
|
+
isVerifying: boolean;
|
|
1097
|
+
},
|
|
1098
|
+
): Partial<State> {
|
|
1099
|
+
const { stepId, authId, isVerifying } = params;
|
|
1100
|
+
const authObjIndex = state.stepMapping[stepId]?.authorizations.findIndex(
|
|
1101
|
+
(el) => el.authorizationId === authId,
|
|
1102
|
+
);
|
|
1103
|
+
|
|
1104
|
+
if (!(authObjIndex > -1)) return state;
|
|
1105
|
+
|
|
1106
|
+
return {
|
|
1107
|
+
stepMapping: {
|
|
1108
|
+
...state.stepMapping,
|
|
1109
|
+
[stepId]: {
|
|
1110
|
+
...state.stepMapping[stepId],
|
|
1111
|
+
authorizations: [
|
|
1112
|
+
...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
|
|
1113
|
+
{
|
|
1114
|
+
...state.stepMapping[stepId].authorizations[authObjIndex],
|
|
1115
|
+
isVerifying,
|
|
1116
|
+
},
|
|
1117
|
+
...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
|
|
1118
|
+
],
|
|
1119
|
+
},
|
|
1120
|
+
},
|
|
1121
|
+
};
|
|
1122
|
+
},
|
|
1123
|
+
|
|
1124
|
+
toggleVerifyAppAuthorizationFlag(
|
|
1125
|
+
state: State,
|
|
1126
|
+
params: {
|
|
1127
|
+
appId: number;
|
|
1128
|
+
authId: number;
|
|
1129
|
+
isVerifying: boolean;
|
|
1130
|
+
},
|
|
1131
|
+
): Partial<State> {
|
|
1132
|
+
const { appId, authId, isVerifying } = params;
|
|
1133
|
+
const authObjIndex = state.authMapping[appId]?.authorizations.findIndex(
|
|
1134
|
+
(el) => el.authorizationId === authId,
|
|
1135
|
+
);
|
|
1136
|
+
|
|
1137
|
+
if (!(authObjIndex > -1)) return state;
|
|
1138
|
+
|
|
1139
|
+
return {
|
|
1140
|
+
stepMapping: {
|
|
1141
|
+
...state.stepMapping,
|
|
1142
|
+
[appId]: {
|
|
1143
|
+
...state.authMapping[appId],
|
|
1144
|
+
authorizations: [
|
|
1145
|
+
...state.authMapping[appId].authorizations.slice(0, authObjIndex),
|
|
1146
|
+
{
|
|
1147
|
+
...state.authMapping[appId].authorizations[authObjIndex],
|
|
1148
|
+
isVerifying,
|
|
1149
|
+
},
|
|
1150
|
+
...state.authMapping[appId].authorizations.slice(authObjIndex + 1),
|
|
1151
|
+
],
|
|
1152
|
+
},
|
|
1153
|
+
},
|
|
1154
|
+
};
|
|
1155
|
+
},
|
|
1156
|
+
|
|
1157
|
+
toggleDeleteAuthorizationFlag(
|
|
1158
|
+
state: State,
|
|
1159
|
+
params: {
|
|
1160
|
+
stepId: number;
|
|
1161
|
+
authId: number;
|
|
1162
|
+
isDeleting: boolean;
|
|
1163
|
+
error: string;
|
|
1164
|
+
},
|
|
1165
|
+
): Partial<State> {
|
|
1166
|
+
const { stepId, authId, isDeleting, error } = params;
|
|
1167
|
+
const authObjIndex = state.stepMapping[stepId].authorizations.findIndex(
|
|
1168
|
+
(el) => el.authorizationId === authId,
|
|
1169
|
+
);
|
|
1170
|
+
return {
|
|
1171
|
+
stepMapping: {
|
|
1172
|
+
...state.stepMapping,
|
|
1173
|
+
[stepId]: {
|
|
1174
|
+
...state.stepMapping[stepId],
|
|
1175
|
+
authorizations: [
|
|
1176
|
+
...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
|
|
1177
|
+
{
|
|
1178
|
+
...state.stepMapping[stepId].authorizations[authObjIndex],
|
|
1179
|
+
isDeleting,
|
|
1180
|
+
error,
|
|
1181
|
+
},
|
|
1182
|
+
...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
|
|
1183
|
+
],
|
|
1184
|
+
},
|
|
1185
|
+
},
|
|
1186
|
+
};
|
|
1187
|
+
},
|
|
1188
|
+
|
|
1189
|
+
toggleDeleteAppAuthorizationFlag(
|
|
1190
|
+
state: State,
|
|
1191
|
+
params: {
|
|
1192
|
+
stepId: number;
|
|
1193
|
+
authId: number;
|
|
1194
|
+
isDeleting: boolean;
|
|
1195
|
+
error: string;
|
|
1196
|
+
},
|
|
1197
|
+
): Partial<State> {
|
|
1198
|
+
const { stepId, authId, isDeleting, error } = params;
|
|
1199
|
+
const authObjIndex = state.stepMapping[stepId].authorizations.findIndex(
|
|
1200
|
+
(el) => el.authorizationId === authId,
|
|
1201
|
+
);
|
|
1202
|
+
return {
|
|
1203
|
+
stepMapping: {
|
|
1204
|
+
...state.stepMapping,
|
|
1205
|
+
[stepId]: {
|
|
1206
|
+
...state.stepMapping[stepId],
|
|
1207
|
+
authorizations: [
|
|
1208
|
+
...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
|
|
1209
|
+
{
|
|
1210
|
+
...state.stepMapping[stepId].authorizations[authObjIndex],
|
|
1211
|
+
isDeleting,
|
|
1212
|
+
error,
|
|
1213
|
+
},
|
|
1214
|
+
...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
|
|
1215
|
+
],
|
|
1216
|
+
},
|
|
1217
|
+
},
|
|
1218
|
+
};
|
|
1219
|
+
},
|
|
1220
|
+
|
|
1221
|
+
setStepAuthId(
|
|
1222
|
+
state: State,
|
|
1223
|
+
params: { stepId: number; authId: number },
|
|
1224
|
+
): Partial<State> {
|
|
1225
|
+
const { stepId, authId } = params;
|
|
1226
|
+
return {
|
|
1227
|
+
stepMapping: {
|
|
1228
|
+
...state.stepMapping,
|
|
1229
|
+
[stepId]: {
|
|
1230
|
+
...state.stepMapping[stepId],
|
|
1231
|
+
selectedAuthId: authId,
|
|
1232
|
+
},
|
|
1233
|
+
},
|
|
1234
|
+
};
|
|
1235
|
+
},
|
|
1236
|
+
|
|
1237
|
+
setStepAuthorization(
|
|
1238
|
+
state: State,
|
|
1239
|
+
stepId: number,
|
|
1240
|
+
selectedAuthId: number | null,
|
|
1241
|
+
isVerified: boolean,
|
|
1242
|
+
fieldsToReset: number[],
|
|
1243
|
+
override: boolean,
|
|
1244
|
+
): Partial<State> {
|
|
1245
|
+
const step = state.stepState.steps[state.stepState.stepIndex];
|
|
1246
|
+
const stepFromMapping = state.stepMapping[stepId];
|
|
1247
|
+
const latestStepState = storeSnapshot.getState().stepState;
|
|
1248
|
+
if (
|
|
1249
|
+
step &&
|
|
1250
|
+
step.type !== 'CONFIRMATION' &&
|
|
1251
|
+
latestStepState.currentStep?.type !== 'CONFIRMATION' &&
|
|
1252
|
+
latestStepState.currentStep?.stepId === stepId
|
|
1253
|
+
) {
|
|
1254
|
+
const { invalidFields } = step;
|
|
1255
|
+
if (isVerified) delete invalidFields[stepId];
|
|
1256
|
+
const updatedStep = {
|
|
1257
|
+
...state.stepState.steps[state.stepState.stepIndex],
|
|
1258
|
+
invalidFields,
|
|
1259
|
+
isValid: Object.keys(invalidFields).length < 1 && isVerified,
|
|
1260
|
+
isCompleted: stepFromMapping.selectedAuthId !== null || isVerified,
|
|
1261
|
+
};
|
|
1262
|
+
const authObjIndex = state.stepMapping[stepId]?.authorizations.findIndex(
|
|
1263
|
+
(el) => el.authorizationId === selectedAuthId,
|
|
1264
|
+
);
|
|
1265
|
+
|
|
1266
|
+
if (!(authObjIndex > -1)) {
|
|
1267
|
+
/**
|
|
1268
|
+
* Reset template step fields when the step does not have the selected auth ID
|
|
1269
|
+
*/
|
|
1270
|
+
if (!(authObjIndex > -1)) {
|
|
1271
|
+
return {
|
|
1272
|
+
// reset all values for the dependent fields of auth
|
|
1273
|
+
stepMapping: {
|
|
1274
|
+
...state.stepMapping,
|
|
1275
|
+
[stepId]: {
|
|
1276
|
+
...state.stepMapping[stepId],
|
|
1277
|
+
selectedAuthId: null,
|
|
1278
|
+
},
|
|
1279
|
+
},
|
|
1280
|
+
stepDataMapping: override
|
|
1281
|
+
? state.stepDataMapping
|
|
1282
|
+
: {
|
|
1283
|
+
...state.stepDataMapping,
|
|
1284
|
+
[stepId]: {
|
|
1285
|
+
...state.stepDataMapping[stepId],
|
|
1286
|
+
...fieldsToReset.reduce(
|
|
1287
|
+
(acc, curr) => ({
|
|
1288
|
+
...acc,
|
|
1289
|
+
[curr]: {
|
|
1290
|
+
...state.stepDataMapping[stepId][curr],
|
|
1291
|
+
value: '',
|
|
1292
|
+
},
|
|
1293
|
+
}),
|
|
1294
|
+
{},
|
|
1295
|
+
),
|
|
1296
|
+
},
|
|
1297
|
+
},
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// get all steps, update selected auth ID for all steps where auth type matches
|
|
1303
|
+
let stepMappingCopy = {};
|
|
1304
|
+
|
|
1305
|
+
Object.keys(state.stepMapping).forEach((stepID) => {
|
|
1306
|
+
const currentStep = state.stepMapping[stepID];
|
|
1307
|
+
const authStep = state.stepMapping[stepId];
|
|
1308
|
+
let defaultStepAuthorizations = currentStep.authorizations;
|
|
1309
|
+
if (
|
|
1310
|
+
currentStep.step.authorization_type.app.id ===
|
|
1311
|
+
state.stepMapping[stepId].step.authorization_type.app.id &&
|
|
1312
|
+
stepId !== Number(stepID)
|
|
1313
|
+
) {
|
|
1314
|
+
/**
|
|
1315
|
+
* this means that there is another step of same app that should also be populated with new auth added
|
|
1316
|
+
*/
|
|
1317
|
+
if (defaultStepAuthorizations.length === 0) {
|
|
1318
|
+
defaultStepAuthorizations =
|
|
1319
|
+
state.stepMapping[stepId].authorizations;
|
|
1320
|
+
} else {
|
|
1321
|
+
defaultStepAuthorizations = [
|
|
1322
|
+
...currentStep.authorizations.slice(0, authObjIndex),
|
|
1323
|
+
{
|
|
1324
|
+
...state.stepMapping[stepId].authorizations[authObjIndex],
|
|
1325
|
+
isVerified,
|
|
1326
|
+
isVerifying: false,
|
|
1327
|
+
didFetchStatus: true,
|
|
1328
|
+
error: '',
|
|
1329
|
+
},
|
|
1330
|
+
...currentStep.authorizations.slice(authObjIndex + 1),
|
|
1331
|
+
];
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
stepMappingCopy = {
|
|
1335
|
+
...stepMappingCopy,
|
|
1336
|
+
[stepID]: {
|
|
1337
|
+
...currentStep,
|
|
1338
|
+
selectedAuthId:
|
|
1339
|
+
(isVerified && stepId === Number(stepID)) ||
|
|
1340
|
+
currentStep.step.authorization_type.id ===
|
|
1341
|
+
authStep.step.authorization_type.id // if the step we are currently on has the same auth type, update the ID
|
|
1342
|
+
? selectedAuthId
|
|
1343
|
+
: currentStep.selectedAuthId,
|
|
1344
|
+
isAuthVerified: isVerified,
|
|
1345
|
+
authorizations:
|
|
1346
|
+
Number(stepID) === stepId
|
|
1347
|
+
? [
|
|
1348
|
+
...currentStep.authorizations.slice(0, authObjIndex),
|
|
1349
|
+
{
|
|
1350
|
+
...currentStep.authorizations[authObjIndex],
|
|
1351
|
+
isVerified,
|
|
1352
|
+
isVerifying: false,
|
|
1353
|
+
didFetchStatus: true,
|
|
1354
|
+
error: '',
|
|
1355
|
+
},
|
|
1356
|
+
...currentStep.authorizations.slice(authObjIndex + 1),
|
|
1357
|
+
]
|
|
1358
|
+
: defaultStepAuthorizations,
|
|
1359
|
+
},
|
|
1360
|
+
};
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
return {
|
|
1364
|
+
stepState: {
|
|
1365
|
+
...state.stepState,
|
|
1366
|
+
steps: [
|
|
1367
|
+
...state.stepState.steps.slice(0, state.stepState.stepIndex),
|
|
1368
|
+
updatedStep,
|
|
1369
|
+
...state.stepState.steps.slice(state.stepState.stepIndex + 1),
|
|
1370
|
+
],
|
|
1371
|
+
currentStep: updatedStep,
|
|
1372
|
+
showValidation: !isVerified && !stepFromMapping.selectedAuthId,
|
|
1373
|
+
},
|
|
1374
|
+
stepMapping: stepMappingCopy,
|
|
1375
|
+
// // reset all values for the dependent fields of auth
|
|
1376
|
+
stepDataMapping: override
|
|
1377
|
+
? state.stepDataMapping
|
|
1378
|
+
: {
|
|
1379
|
+
...state.stepDataMapping,
|
|
1380
|
+
[stepId]: {
|
|
1381
|
+
...state.stepDataMapping[stepId],
|
|
1382
|
+
...fieldsToReset.reduce(
|
|
1383
|
+
(acc, curr) => ({
|
|
1384
|
+
...acc,
|
|
1385
|
+
[curr]: {
|
|
1386
|
+
...state.stepDataMapping[stepId][curr],
|
|
1387
|
+
value: '',
|
|
1388
|
+
},
|
|
1389
|
+
}),
|
|
1390
|
+
{},
|
|
1391
|
+
),
|
|
1392
|
+
},
|
|
1393
|
+
},
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
return state;
|
|
1397
|
+
},
|
|
1398
|
+
|
|
1399
|
+
resetCustomMappingData(state: State, stepId: number): Partial<State> {
|
|
1400
|
+
const step = state.stepMapping[stepId];
|
|
1401
|
+
const dynamicFieldId = step.step.template_fields.filter(
|
|
1402
|
+
(el) => el.activity_field?.type === 'DYNAMIC',
|
|
1403
|
+
)[0]?.id;
|
|
1404
|
+
|
|
1405
|
+
if (dynamicFieldId) {
|
|
1406
|
+
const stepData = state.stepDataMapping[stepId][dynamicFieldId];
|
|
1407
|
+
if (stepData) stepData.objectValue = {};
|
|
1408
|
+
return {
|
|
1409
|
+
stepDataMapping: {
|
|
1410
|
+
...state.stepDataMapping,
|
|
1411
|
+
[stepId]: {
|
|
1412
|
+
...state.stepDataMapping[stepId],
|
|
1413
|
+
[dynamicFieldId]: stepData,
|
|
1414
|
+
},
|
|
1415
|
+
},
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
return state;
|
|
1419
|
+
},
|
|
1420
|
+
|
|
1421
|
+
setStepFieldData(
|
|
1422
|
+
state: State,
|
|
1423
|
+
data: {
|
|
1424
|
+
stepId: number;
|
|
1425
|
+
fieldId: number;
|
|
1426
|
+
value: string;
|
|
1427
|
+
isRequired: boolean;
|
|
1428
|
+
passesRegexTest?: boolean;
|
|
1429
|
+
},
|
|
1430
|
+
): Partial<State> {
|
|
1431
|
+
const { stepId, fieldId, value, passesRegexTest = true } = data;
|
|
1432
|
+
const step = state.stepState.steps[state.stepState.stepIndex];
|
|
1433
|
+
|
|
1434
|
+
if (step.type !== 'CONFIRMATION') {
|
|
1435
|
+
return {
|
|
1436
|
+
stepState: {
|
|
1437
|
+
...state.stepState,
|
|
1438
|
+
allStepsCompleted: false,
|
|
1439
|
+
},
|
|
1440
|
+
stepDataMapping: {
|
|
1441
|
+
...state.stepDataMapping,
|
|
1442
|
+
[stepId]: {
|
|
1443
|
+
...state.stepDataMapping[stepId],
|
|
1444
|
+
[fieldId]: {
|
|
1445
|
+
...state.stepDataMapping[stepId][fieldId],
|
|
1446
|
+
value,
|
|
1447
|
+
passesRegexTest,
|
|
1448
|
+
},
|
|
1449
|
+
},
|
|
1450
|
+
},
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
return state;
|
|
1454
|
+
},
|
|
1455
|
+
|
|
1456
|
+
clearChildFields(
|
|
1457
|
+
state: State,
|
|
1458
|
+
data: {
|
|
1459
|
+
stepId: number;
|
|
1460
|
+
fieldId: number;
|
|
1461
|
+
},
|
|
1462
|
+
): Partial<State> {
|
|
1463
|
+
// clear all child fields of the field that was just updated
|
|
1464
|
+
const { stepId, fieldId } = data;
|
|
1465
|
+
const step = state.stepState.steps[state.stepState.stepIndex];
|
|
1466
|
+
if (step && step.type !== 'CONFIRMATION') {
|
|
1467
|
+
const stepData = state.parentChildMapping[stepId];
|
|
1468
|
+
|
|
1469
|
+
if (!stepData) return state;
|
|
1470
|
+
|
|
1471
|
+
const field = Object.keys(stepData).find(
|
|
1472
|
+
(el) => stepData[el].fieldId === fieldId,
|
|
1473
|
+
);
|
|
1474
|
+
|
|
1475
|
+
if (!field) return state;
|
|
1476
|
+
|
|
1477
|
+
const { childFields } = stepData[field];
|
|
1478
|
+
|
|
1479
|
+
if (!childFields) return state;
|
|
1480
|
+
|
|
1481
|
+
// empty all fields in step data mapping for this step ID
|
|
1482
|
+
const stepDataMapping = state.stepDataMapping[stepId];
|
|
1483
|
+
|
|
1484
|
+
// update fields inside step data mapping if machine name matches
|
|
1485
|
+
const updatedStepDataMapping = Object.keys(stepDataMapping).reduce(
|
|
1486
|
+
(acc, curr: string) => {
|
|
1487
|
+
const stepField = stepDataMapping[Number(curr)];
|
|
1488
|
+
if (childFields.includes(stepField.machineName)) {
|
|
1489
|
+
return {
|
|
1490
|
+
...acc,
|
|
1491
|
+
[curr]: {
|
|
1492
|
+
...stepField,
|
|
1493
|
+
value: '',
|
|
1494
|
+
},
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
...acc,
|
|
1499
|
+
[curr]: stepField,
|
|
1500
|
+
};
|
|
1501
|
+
},
|
|
1502
|
+
{},
|
|
1503
|
+
);
|
|
1504
|
+
|
|
1505
|
+
return {
|
|
1506
|
+
...state,
|
|
1507
|
+
stepDataMapping: {
|
|
1508
|
+
...state.stepDataMapping,
|
|
1509
|
+
[stepId]: updatedStepDataMapping,
|
|
1510
|
+
},
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
return state;
|
|
1514
|
+
},
|
|
1515
|
+
|
|
1516
|
+
setStepMappingData(
|
|
1517
|
+
state: State,
|
|
1518
|
+
data: {
|
|
1519
|
+
stepId: number;
|
|
1520
|
+
fieldId: number;
|
|
1521
|
+
id: string;
|
|
1522
|
+
value: string | null;
|
|
1523
|
+
},
|
|
1524
|
+
): Partial<State> {
|
|
1525
|
+
const val = state.stepDataMapping[data.stepId][data.fieldId]?.objectValue;
|
|
1526
|
+
let newVal;
|
|
1527
|
+
if (data.value) {
|
|
1528
|
+
newVal = {
|
|
1529
|
+
...(state.stepDataMapping[data.stepId][data.fieldId]?.objectValue ??
|
|
1530
|
+
{}),
|
|
1531
|
+
...{ [data.id]: data.value },
|
|
1532
|
+
};
|
|
1533
|
+
} else if (val) {
|
|
1534
|
+
delete val[data.id];
|
|
1535
|
+
newVal = val;
|
|
1536
|
+
if (Object.keys(newVal).length === 0) newVal = null;
|
|
1537
|
+
}
|
|
1538
|
+
if (newVal)
|
|
1539
|
+
return {
|
|
1540
|
+
stepDataMapping: {
|
|
1541
|
+
...state.stepDataMapping,
|
|
1542
|
+
[data.stepId]: {
|
|
1543
|
+
...state.stepDataMapping[data.stepId],
|
|
1544
|
+
[data.fieldId]: {
|
|
1545
|
+
...state.stepDataMapping[data.stepId][data.fieldId],
|
|
1546
|
+
objectValue: newVal,
|
|
1547
|
+
},
|
|
1548
|
+
},
|
|
1549
|
+
},
|
|
1550
|
+
};
|
|
1551
|
+
return state;
|
|
1552
|
+
},
|
|
1553
|
+
resetTemplateFields(state: State): State {
|
|
1554
|
+
return {
|
|
1555
|
+
...state,
|
|
1556
|
+
stepMapping: initialState.stepMapping,
|
|
1557
|
+
stepDataMapping: initialState.stepDataMapping,
|
|
1558
|
+
stepState: initialState.stepState,
|
|
1559
|
+
showSetupModal: initialState.showSetupModal,
|
|
1560
|
+
showSetupInline: initialState.showSetupInline,
|
|
1561
|
+
parentChildMapping: initialState.parentChildMapping,
|
|
1562
|
+
integrationIdToEdit: initialState.integrationIdToEdit,
|
|
1563
|
+
genericData: {
|
|
1564
|
+
...state.genericData,
|
|
1565
|
+
brandingApp: initialState.genericData.brandingApp,
|
|
1566
|
+
templateId: initialState.genericData.templateId,
|
|
1567
|
+
},
|
|
1568
|
+
};
|
|
1569
|
+
},
|
|
1570
|
+
reset(): State {
|
|
1571
|
+
return initialState;
|
|
1572
|
+
},
|
|
1573
|
+
});
|