Skip to content

Commit

Permalink
Merge pull request #2922 from glific/enhancement/dynamic-interactive-…
Browse files Browse the repository at this point in the history
…messages

Enhancements in Interactive messages
  • Loading branch information
akanshaaa19 authored Jun 12, 2024
2 parents f51987e + 4c2fb5f commit 53fabb5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/containers/InteractiveMessage/InteractiveMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,24 @@ describe('location request message', () => {
});
});
});

test('It creates a interactive message with dynamic content', async () => {
const { getByTestId, getAllByRole, getByText } = render(interactiveMessage);
await waitFor(() => {
expect(getByText('Marathi')).toBeInTheDocument();
});

fireEvent.click(getAllByRole('checkbox')[1]);

const autoCompletes = getAllByRole('combobox');

const attachmentType = autoCompletes[1];

attachmentType.focus();
fireEvent.keyDown(attachmentType, { key: 'ArrowDown' });
fireEvent.keyDown(attachmentType, { key: 'ArrowDown' });
fireEvent.keyDown(attachmentType, { key: 'Enter' });

fireEvent.change(getAllByRole('textbox')[4], { target: { value: '@results.result_1' } });
fireEvent.click(getByTestId('submitActionButton'));
});
23 changes: 21 additions & 2 deletions src/containers/InteractiveMessage/InteractiveMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const InteractiveMessage = () => {
const [language, setLanguage] = useState<any>({});
const [languageOptions, setLanguageOptions] = useState<any>([]);
const [editorState, setEditorState] = useState<any>('');
const [dynamicMedia, setDynamicMedia] = useState<boolean>(false);

const [translations, setTranslations] = useState<any>('{}');

Expand Down Expand Up @@ -148,6 +149,7 @@ export const InteractiveMessage = () => {
templateTypeField,
type,
attachmentURL,
dynamicMedia,
};

const updateStates = ({
Expand Down Expand Up @@ -251,6 +253,10 @@ export const InteractiveMessage = () => {
setAttachmentURL(data.attachmentURL);
}

if (isEditing && data.attachmentURL) {
setDynamicMedia(!isUrlValid);
}

if (translationsVal) {
setTranslations(translationsVal);
}
Expand All @@ -277,7 +283,7 @@ export const InteractiveMessage = () => {
};

useEffect(() => {
if ((type === '' || type) && attachmentURL) {
if (!dynamicMedia && (type === '' || type) && attachmentURL) {
validateURL(attachmentURL);
}
}, [type, attachmentURL]);
Expand Down Expand Up @@ -738,7 +744,7 @@ export const InteractiveMessage = () => {
name: 'attachmentURL',
type: 'text',
label: t('Attachment URL'),
validate: () => isUrlValid,
validate: () => !dynamicMedia && isUrlValid,
inputProp: {
onBlur: (event: any) => {
setAttachmentURL(event.target.value);
Expand All @@ -747,6 +753,19 @@ export const InteractiveMessage = () => {
setAttachmentURL(event.target.value);
},
},
helperText:
dynamicMedia &&
t(
'Please ensure that the entered media is valid as we cannot pre-validate dynamic media files and it may lead to errors.'
),
},
{
component: Checkbox,
title: t('Allow dynamic media'),
name: 'dynamicMedia',
handleChange: (value: boolean) => {
setDynamicMedia(value);
},
},
];

Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,7 @@
"App name is required.": "App name is required.",
"API key is required.": "API key is required.",
"Please agree to the terms and conditions.": "Please agree to the terms and conditions.",
"Enter a valid phone number.": "Enter a valid phone number."
"Enter a valid phone number.": "Enter a valid phone number.",
"Allow dynamic media": "Allow dynamic media",
"Please ensure that the entered media is valid as we cannot pre-validate dynamic media files and it may lead to errors.": "Please ensure that the entered media is valid as we cannot pre-validate dynamic media files and it may lead to errors."
}

0 comments on commit 53fabb5

Please sign in to comment.