Skip to content

Commit

Permalink
Merge branch 'enhancement/dynamic-interactive-messages' of github.com…
Browse files Browse the repository at this point in the history
…-akanshaaa19:glific/glific-frontend into enhancement/dynamic-interactive-messages
  • Loading branch information
akanshaaa19 committed Jun 12, 2024
2 parents 7aaabf0 + eecda0d commit ea7a004
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/components/floweditor/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Button } from 'components/UI/Form/Button/Button';
import { APP_NAME } from 'config/index';
import { Simulator } from 'components/simulator/Simulator';
import { DialogBox } from 'components/UI/DialogBox/DialogBox';
import { setNotification } from 'common/notification';
import { setErrorMessage, setNotification } from 'common/notification';
import { PUBLISH_FLOW, RESET_FLOW_COUNT } from 'graphql/mutations/Flow';
import { EXPORT_FLOW, GET_FLOW_DETAILS, GET_FREE_FLOW } from 'graphql/queries/Flow';
import { getOrganizationServices, setAuthHeaders } from 'services/AuthService';
Expand Down Expand Up @@ -94,6 +94,9 @@ export const FlowEditor = () => {
const { exportData } = exportFlow;
exportFlowMethod(exportData, flowTitle);
},
onError: (error) => {
setErrorMessage(error);
},
});
const [resetFlowCountMethod] = useMutation(RESET_FLOW_COUNT, {
onCompleted: ({ resetFlowCount }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Flow/FlowList/FlowList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { GET_TAGS } from 'graphql/queries/Tags';
import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete';
import { flowInfo } from 'common/HelpData';
import { DialogBox } from 'components/UI/DialogBox/DialogBox';
import { setNotification } from 'common/notification';
import { setErrorMessage, setNotification } from 'common/notification';

const getName = (text: string, keywordsList: any, roles: any) => {
const keywords = keywordsList.map((keyword: any) => keyword);
Expand Down Expand Up @@ -114,7 +114,7 @@ export const FlowList = () => {
setNotification('Flow exported successfully');
},
onError: (error: any) => {
setNotification('An error occured while exporting the flow', 'warning');
setErrorMessage(error);
},
});

Expand Down
34 changes: 20 additions & 14 deletions src/containers/InteractiveMessage/InteractiveMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const InteractiveMessage = () => {
const [language, setLanguage] = useState<any>({});
const [languageOptions, setLanguageOptions] = useState<any>([]);
const [editorState, setEditorState] = useState<any>('');
const [dynamicInteractiveMessage, setDynamicInteractiveMessage] = useState<boolean>(false);
const [dynamicMedia, setDynamicMedia] = useState<boolean>(false);

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

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

const updateStates = ({
Expand Down Expand Up @@ -258,6 +258,10 @@ export const InteractiveMessage = () => {
}
}

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

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

useEffect(() => {
if (!dynamicInteractiveMessage && (type === '' || type) && attachmentURL) {
if (!dynamicMedia && (type === '' || type) && attachmentURL) {
validateURL(attachmentURL);
}
}, [type, attachmentURL]);
Expand Down Expand Up @@ -725,14 +729,6 @@ export const InteractiveMessage = () => {
};

const attachmentInputs = [
{
component: Checkbox,
title: 'Dynamic Interactive Message',
name: 'dynamicInteractiveMessage',
handleChange: (value: boolean) => {
setDynamicInteractiveMessage(value);
},
},
{
component: AutoComplete,
name: 'type',
Expand All @@ -753,7 +749,7 @@ export const InteractiveMessage = () => {
name: 'attachmentURL',
type: 'text',
label: t('Attachment URL'),
validate: () => !dynamicInteractiveMessage && isUrlValid,
validate: () => !dynamicMedia && isUrlValid,
inputProp: {
onBlur: (event: any) => {
setAttachmentURL(event.target.value);
Expand All @@ -763,8 +759,18 @@ export const InteractiveMessage = () => {
},
},
helperText:
dynamicInteractiveMessage &&
'Please ensure that the media you are submitting is valid. Using incorrect media can cause errors as we cannot pre-validate media files.',
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 ea7a004

Please sign in to comment.