;
- form: { touched: any; errors: any; values: any };
+ form: { touched: any; errors: any; values: any; setFieldValue: any };
onAddClick: any;
onRemoveClick: any;
onInputChange: any;
onTemplateTypeChange: any;
disabled: any;
+ dynamicUrlParams: any;
+ onDynamicParamsChange: any;
}
export const TemplateOptions = ({
isAddButtonChecked,
templateType,
inputFields,
- form: { touched, errors, values },
+ form: { touched, errors },
onAddClick,
onRemoveClick,
onTemplateTypeChange,
onInputChange,
disabled = false,
+ dynamicUrlParams,
+ onDynamicParamsChange,
}: TemplateOptionsProps) => {
const buttonTitle = 'Button Title';
const buttonValue = 'Button Value';
@@ -38,7 +51,8 @@ export const TemplateOptions = ({
CALL_TO_ACTION: 'Call to action',
QUICK_REPLY: 'Quick Reply',
};
-
+ const options = ['Static', 'Dynamic'];
+ const { urlType, sampleSuffix } = dynamicUrlParams;
const handleAddClick = (helper: any, type: boolean) => {
const obj = type ? { type: '', value: '', title: '' } : { value: '' };
helper.push(obj);
@@ -133,15 +147,32 @@ export const TemplateOptions = ({
) : null}
+ {type === 'url' && (
+
+
}
+ clearIcon={false}
+ value={urlType}
+ onChange={(event: any, newValue: string | null) => {
+ onDynamicParamsChange({
+ ...dynamicUrlParams,
+ urlType: newValue,
+ });
+ }}
+ />
+
+ )}
onInputChange(e, row, index, 'title')}
+ onChange={(e: any) => onInputChange(e, row, index, 'title')}
className={styles.TextField}
error={isError('title')}
/>
@@ -154,11 +185,11 @@ export const TemplateOptions = ({
onInputChange(e, row, index, 'value')}
+ onChange={(e: any) => onInputChange(e, row, index, 'value')}
className={styles.TextField}
error={isError('value')}
/>
@@ -167,7 +198,37 @@ export const TemplateOptions = ({
) : null}
+ {urlType === 'Dynamic' && type === 'url' && (
+
+
+ {`{{1}}`}
+ ),
+ },
+ }}
+ onChange={(event) =>
+ onDynamicParamsChange({
+ ...dynamicUrlParams,
+ sampleSuffix: event.target.value,
+ })
+ }
+ value={sampleSuffix}
+ />
+
+
+ )}
+
{inputFields.length === index + 1 && inputFields.length !== 2 ? addButton(arrayHelpers, true) : null}
@@ -182,22 +243,24 @@ export const TemplateOptions = ({
onInputChange(e, row, index, 'value')}
+ onChange={(e: any) => onInputChange(e, row, index, 'value')}
className={styles.TextField}
error={isError('value')}
- InputProps={{
- endAdornment: inputFields.length > 1 && !disabled && (
- handleRemoveClick(arrayHelpers, index)}
- />
- ),
+ slotProps={{
+ input: {
+ endAdornment: inputFields.length > 1 && !disabled && (
+ handleRemoveClick(arrayHelpers, index)}
+ />
+ ),
+ },
}}
/>
{errors.templateButtons && touched.templateButtons && touched.templateButtons[index] ? (
@@ -251,7 +314,7 @@ export const TemplateOptions = ({
name="templateButtons"
render={(arrayHelpers: any) => (
- {values.templateButtons.map((row: any, index: any) => (
+ {inputFields.map((row: any, index: any) => (
{getButtons(row, index, arrayHelpers)}
))}
diff --git a/src/mocks/Template.tsx b/src/mocks/Template.tsx
index 9e6bb62c5..888ca7fa1 100644
--- a/src/mocks/Template.tsx
+++ b/src/mocks/Template.tsx
@@ -280,6 +280,9 @@ export const templateMock = createTemplateMock({
languageId: '1',
example: 'Hi, How are you [User]',
shortcode: 'element_name',
+ hasButtons: true,
+ buttons: '[{"type":"PHONE_NUMBER","text":"Call me","phone_number":"9876543210"}]',
+ buttonType: 'CALL_TO_ACTION',
});
export const quickReplyMock = createTemplateMock({
@@ -295,7 +298,7 @@ export const quickReplyMock = createTemplateMock({
example: 'Hi',
shortcode: 'welcome',
hasButtons: true,
- buttons: '[{"type":"QUICK_REPLY","text":""},{"type":"QUICK_REPLY","text":""}]',
+ buttons: '[{"type":"QUICK_REPLY","text":"Yes"},{"type":"QUICK_REPLY","text":"No"}]',
buttonType: 'QUICK_REPLY',
});
@@ -312,7 +315,7 @@ export const ctaMock = createTemplateMock({
example: 'Hi',
shortcode: 'welcome',
hasButtons: true,
- buttons: '[{"type":"PHONE_NUMBER","text":"","phone_number":""}]',
+ buttons: '[{"type":"PHONE_NUMBER","text":"Call me","phone_number":"9876543210"}]',
buttonType: 'CALL_TO_ACTION',
});