From dec11ff96e49f7224d549d669ab334b34c82d2ba Mon Sep 17 00:00:00 2001 From: Eric Newcomer Date: Fri, 3 May 2024 19:29:41 +0000 Subject: [PATCH] Simplify template configuration --- .../flow/actions/sendmsg/SendMsgForm.tsx | 25 ++++++++---------- .../flow/actions/sendmsg/helpers.ts | 26 ++++++++++++------- src/index.js | 1 - 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/components/flow/actions/sendmsg/SendMsgForm.tsx b/src/components/flow/actions/sendmsg/SendMsgForm.tsx index de5b2cd2a..acd7bc69e 100644 --- a/src/components/flow/actions/sendmsg/SendMsgForm.tsx +++ b/src/components/flow/actions/sendmsg/SendMsgForm.tsx @@ -25,8 +25,7 @@ import { mergeForm, StringArrayEntry, StringEntry, - SelectOptionEntry, - FormEntry + SelectOptionEntry } from 'store/nodeEditor'; import { MaxOfTenItems, shouldRequireIf, validate } from 'store/validators'; @@ -51,8 +50,8 @@ export interface SendMsgFormState extends FormState { templateTranslation?: TemplateTranslation; // template uuid to dict of component key to array - template: FormEntry; - templateVariables: StringArrayEntry; + template: { uuid: string; name: string }; + templateVariables: string[]; } export default class SendMsgForm extends React.Component { @@ -135,9 +134,8 @@ export default class SendMsgForm extends React.Component

@@ -222,7 +219,7 @@ export default class SendMsgForm extends React.Component { - let template: FormEntry = { value: null }; + let template: { uuid: string; name: string } = null; + let templateVariables: string[] = []; + if (settings.originalAction && settings.originalAction.type === Types.send_msg) { const action = settings.originalAction as SendMsg; const attachments: Attachment[] = []; + + if (action.template) { + template = action.template; + templateVariables = action.template_variables || []; + } + (action.attachments || []).forEach((attachmentString: string) => { const splitPoint = attachmentString.indexOf(':'); @@ -35,8 +43,8 @@ export const initializeForm = (settings: NodeEditorSettings): SendMsgFormState = return { topic: { value: TOPIC_OPTIONS.find(option => option.value === action.topic) }, - template: { value: action.template }, - templateVariables: { value: action.template_variables }, + template, + templateVariables, attachments, uploadInProgress: false, uploadError: '', @@ -50,14 +58,14 @@ export const initializeForm = (settings: NodeEditorSettings): SendMsgFormState = return { topic: { value: null }, - template: { value: template }, + template, + templateVariables, attachments: [], uploadInProgress: false, uploadError: '', message: { value: '' }, quickReplies: { value: [] }, quickReplyEntry: { value: '' }, - templateVariables: { value: [] }, sendAll: false, valid: false }; @@ -77,9 +85,9 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt uuid: getActionUUID(settings, Types.send_msg) }; - if (state.template.value) { - result.template = state.template.value; - result.template_variables = state.templateVariables.value; + if (state.template) { + result.template = state.template; + result.template_variables = state.templateVariables; } if (state.topic.value) { diff --git a/src/index.js b/src/index.js index 2fcbdbfcc..5750e47a2 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,6 @@ window.showFlowEditor = (ele, config) => { if (config.httpTimeout) { setHTTPTimeout(config.httpTimeout); } - ReactDOM.unmountComponentAtNode(ele); ReactDOM.render(, ele); };