Skip to content

Commit d02f41f

Browse files
authored
Merge pull request #1225 from nyaruka/template-save-bug
Don't update template variables if tab is never visited
2 parents ae47b59 + 5be59a5 commit d02f41f

File tree

4 files changed

+35
-61
lines changed

4 files changed

+35
-61
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,3 @@
1-
@import 'variables.module.scss';
2-
3-
.checkbox {
4-
margin-top: 20px;
5-
}
6-
7-
.quick_reply_summary {
8-
margin-top: -20px;
9-
position: relative;
10-
}
11-
12-
13-
.existing_quick_replies {
14-
padding: 5px;
15-
border-radius: 5px;
16-
border: 1px solid $light_gray;
17-
18-
.existing_quick_reply {
19-
margin: 2px;
20-
display: inline-block;
21-
}
22-
}
23-
24-
.add_quick_replies {
25-
margin-top: 10px;
26-
}
27-
28-
.template_text {
29-
margin-top: 10px;
30-
padding: 10px;
31-
background: $light_gray_2;
32-
border-radius: 5px;
33-
margin-bottom: 10px;
34-
}
35-
36-
.variable {
37-
margin-bottom: 6px;
38-
}
39-
40-
temba-completion {
41-
--textarea-height: 120px;
42-
}
1+
.message {
2+
--textarea-height: 8em;
3+
}

src/components/flow/actions/sendmsg/SendMsgForm.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import i18n from 'config/i18n';
3737
import { Trans } from 'react-i18next';
3838
import { Attachment, renderAttachments } from './attachments';
3939
import { TembaComponent } from 'temba/TembaComponent';
40+
import styles from './SendMsgForm.module.scss';
4041

4142
export interface SendMsgFormState extends FormState {
4243
message: StringEntry;
@@ -400,6 +401,7 @@ export default class SendMsgForm extends React.Component<ActionFormProps, SendMs
400401
>
401402
<TypeList __className="" initialType={typeConfig} onChange={this.props.onTypeChange} />
402403
<TextInputElement
404+
__className={styles.message}
403405
name={i18n.t('forms.message', 'Message')}
404406
showLabel={false}
405407
counter=".sms-counter"

src/components/flow/actions/sendmsg/__snapshots__/SendMsgForm.test.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ exports[`SendMsgForm render should render 1`] = `
165165
onChange={[MockFunction]}
166166
/>
167167
<TextInputElement
168+
__className="message"
168169
autocomplete={true}
169170
counter=".sms-counter"
170171
entry={

src/components/flow/actions/sendmsg/helpers.ts

+29-19
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,38 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt
9292

9393
let templating: MsgTemplating = null;
9494
if (state.template && state.template.value) {
95-
const components = Object.keys(state.templateTranslation.components).map((key: string) => {
96-
let uuid = createUUID();
97-
98-
// try looking up the uuid from the original action
99-
if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
100-
const originalAction = settings.originalAction as SendMsg;
101-
if (originalAction.templating) {
102-
const originalComponent = originalAction.templating.components.find(
103-
(component: any) => component.name === key
104-
);
105-
if (originalComponent) {
106-
uuid = originalComponent.uuid;
95+
const originalAction =
96+
settings.originalAction.type === Types.send_msg ? (settings.originalAction as SendMsg) : null;
97+
98+
let components =
99+
originalAction.templating && originalAction.templating.components
100+
? originalAction.templating.components
101+
: [];
102+
103+
if (state.templateTranslation) {
104+
components = Object.keys(state.templateTranslation.components).map((key: string) => {
105+
let uuid = createUUID();
106+
107+
// try looking up the uuid from the original action
108+
if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
109+
const originalAction = settings.originalAction as SendMsg;
110+
if (originalAction.templating) {
111+
const originalComponent = originalAction.templating.components.find(
112+
(component: any) => component.name === key
113+
);
114+
if (originalComponent) {
115+
uuid = originalComponent.uuid;
116+
}
107117
}
108118
}
109-
}
110119

111-
return {
112-
uuid,
113-
name: key,
114-
params: state.paramsByTemplate[state.template.value.uuid][key]
115-
};
116-
});
120+
return {
121+
uuid,
122+
name: key,
123+
params: state.paramsByTemplate[state.template.value.uuid][key]
124+
};
125+
});
126+
}
117127

118128
templating = {
119129
template: {

0 commit comments

Comments
 (0)