Skip to content

Commit 7a2d94b

Browse files
Merge branch 'master' into bug_bash_1125
2 parents 75224f8 + 9ce8479 commit 7a2d94b

File tree

8 files changed

+45
-24
lines changed

8 files changed

+45
-24
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "glific-frontend",
3-
"version": "6.7.8",
3+
"version": "6.7.9",
44
"private": true,
55
"type": "module",
66
"license": {
@@ -21,7 +21,7 @@
2121
"@emoji-mart/react": "^1.1.1",
2222
"@emotion/react": "^11.14.0",
2323
"@emotion/styled": "^11.14.1",
24-
"@glific/flow-editor": "1.43.0-7",
24+
"@glific/flow-editor": "1.43.0-8",
2525
"@lexical/react": "^0.33.0",
2626
"@mui/icons-material": "^7.2.0",
2727
"@mui/material": "^7.2.0",

src/common/HelpData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ export const certificatesInfo: HelpDataProps = {
142142

143143
export const whatsappFormsInfo: HelpDataProps = {
144144
heading: 'An overview of all the whatsapp forms created to date',
145-
link: 'https://glific.github.io/docs/docs/Product%20Features/Custom%20Certificates',
145+
link: 'https://glific.github.io/docs/docs/Product%20Features/WhatsApp%20Forms',
146146
};

src/common/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ export const LOCATION_REQUEST = 'LOCATION_REQUEST_MESSAGE';
185185
export const TERMS_OF_USE_LINK = 'https://glific.org/glific-terms-and-conditions/';
186186
export const COMPACT_MESSAGE_LENGTH = 35;
187187

188+
export const BUTTON_OPTIONS: any = [
189+
{ id: 'CALL_TO_ACTION', label: 'Call to Action' },
190+
{ id: 'QUICK_REPLY', label: 'Quick Reply' },
191+
{ id: 'WHATSAPP_FORM', label: 'WhatsApp Form' },
192+
];
193+
188194
// Gupshup sample media
189195
export const SAMPLE_MEDIA_FOR_SIMULATOR = [
190196
{

src/components/floweditor/FlowEditor.helper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const setConfig = (uuid: any, skipValidation: boolean, isReadOnly: boolea
1717
mutable: !isReadOnly,
1818
showNodeLabel: false,
1919
attachmentsEnabled: false,
20-
filters: ['whatsapp', 'classifier'],
20+
filters: ['whatsapp', 'classifier', 'start_session'],
2121
skipValidation: skipValidation,
2222

2323
excludeTypes: ['add_contact_urn', 'send_email', 'call_resthook', 'transfer_airtime', 'split_by_scheme'],

src/containers/HSM/HSM.test.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, waitFor, within, fireEvent, screen, cleanup } from '@testing-library/react';
1+
import { render, waitFor, within, fireEvent, screen } from '@testing-library/react';
22
import { MockedProvider } from '@apollo/client/testing';
33
import userEvent from '@testing-library/user-event';
44
import { MemoryRouter, Route, Routes } from 'react-router';
@@ -12,6 +12,7 @@ import {
1212
import { WHATSAPP_FORM_MOCKS } from 'mocks/WhatsAppForm';
1313
import { setNotification } from 'common/notification';
1414
import * as utilsModule from 'common/utils';
15+
import { setOrganizationServices } from 'services/AuthService';
1516

1617
const mocks = HSM_TEMPLATE_MOCKS;
1718

@@ -25,10 +26,6 @@ vi.mock('common/notification', async (importOriginal) => {
2526
};
2627
});
2728

28-
beforeEach(() => {
29-
cleanup();
30-
});
31-
3229
vi.mock('lexical-beautiful-mentions', async (importOriginal) => {
3330
const actual = (await importOriginal()) as typeof import('lexical-beautiful-mentions');
3431
return {
@@ -195,6 +192,8 @@ describe('Add mode', () => {
195192
});
196193

197194
test('it should create a hsm template with whatsapp form', async () => {
195+
setOrganizationServices('{"__typename":"OrganizationServicesResult","whatsappFormsEnabled":true}');
196+
198197
render(template);
199198

200199
await waitFor(() => {
@@ -267,6 +266,22 @@ describe('Add mode', () => {
267266
});
268267
});
269268

269+
test('should not display WhatsApp Form when whatsappFormsEnabled is false', async () => {
270+
setOrganizationServices('{"__typename":"OrganizationServicesResult","whatsappFormsEnabled":false}');
271+
272+
render(template);
273+
274+
await waitFor(() => {
275+
expect(screen.getByText('Add a new HSM Template')).toBeInTheDocument();
276+
});
277+
fireEvent.click(screen.getByText('Add buttons'));
278+
279+
const combobox = screen.getAllByRole('combobox');
280+
const buttonTypeCombo = combobox[1] as HTMLInputElement;
281+
fireEvent.mouseDown(buttonTypeCombo);
282+
expect(screen.queryByText('WhatsApp Form')).not.toBeInTheDocument();
283+
});
284+
270285
test('it adds quick reply buttons', async () => {
271286
render(template);
272287

src/containers/HSM/HSM.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as Yup from 'yup';
88

99
import TemplateIcon from 'assets/images/icons/Template/UnselectedDark.svg?react';
1010

11-
import { CALL_TO_ACTION, QUICK_REPLY } from 'common/constants';
11+
import { BUTTON_OPTIONS, CALL_TO_ACTION, QUICK_REPLY } from 'common/constants';
1212
import { validateMedia } from 'common/utils';
1313
import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete';
1414
import { Checkbox } from 'components/UI/Form/Checkbox/Checkbox';
@@ -60,12 +60,6 @@ const buttonTypes: any = {
6060
WHATSAPP_FORM: { type: 'whatsapp_form', form_id: '', text: '', navigate_screen: '' },
6161
};
6262

63-
export const buttonOptions: any = [
64-
{ id: 'CALL_TO_ACTION', label: 'Call to Action' },
65-
{ id: 'QUICK_REPLY', label: 'Quick Reply' },
66-
{ id: 'WHATSAPP_FORM', label: 'WhatsApp Form' },
67-
];
68-
6963
export const HSM = () => {
7064
const location: any = useLocation();
7165
const [language, setLanguageId] = useState<any>(null);
@@ -89,7 +83,7 @@ export const HSM = () => {
8983
const [languageOptions, setLanguageOptions] = useState<any>([]);
9084
const [validatingURL, setValidatingURL] = useState<boolean>(false);
9185
const [isUrlValid, setIsUrlValid] = useState<any>();
92-
const [templateType, setTemplateType] = useState<any>(buttonOptions[0]);
86+
const [templateType, setTemplateType] = useState<any>(BUTTON_OPTIONS[0]);
9387
const [dynamicUrlParams, setDynamicUrlParams] = useState<any>({
9488
urlType: 'Static',
9589
sampleSuffix: '',
@@ -334,7 +328,7 @@ export const HSM = () => {
334328
if (hasButtons) {
335329
const { buttons: buttonsVal } = getTemplateAndButtons(templateButtonType, exampleValue, buttons);
336330
setTemplateButtons(buttonsVal);
337-
setTemplateType(buttonOptions.find((btn: any) => btn.id === templateButtonType));
331+
setTemplateType(BUTTON_OPTIONS.find((btn: any) => btn.id === templateButtonType));
338332
setIsAddButtonChecked(hasButtons);
339333
const parse = convertButtonsToTemplate(buttonsVal, templateButtonType);
340334
const parsedText = parse.length ? `| ${parse.join(' | ')}` : null;

src/containers/TemplateOptions/TemplateOptions.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import {
2222
QUICK_REPLY,
2323
WHATSAPP_FORM,
2424
GUPSHUP_WHATSAPP_FORM,
25+
BUTTON_OPTIONS,
2526
} from 'common/constants';
2627
import styles from './TemplateOptions.module.css';
2728
import { Fragment, useState } from 'react';
28-
import { buttonOptions } from 'containers/HSM/HSM';
2929
import { useQuery } from '@apollo/client';
3030
import { LIST_WHATSAPP_FORMS } from 'graphql/queries/WhatsAppForm';
31+
import { getOrganizationServices } from 'services/AuthService';
3132

3233
export interface TemplateOptionsProps {
3334
isAddButtonChecked: boolean;
@@ -80,6 +81,12 @@ export const TemplateOptions = ({
8081
const { urlType, sampleSuffix } = dynamicUrlParams;
8182
const [screens, setScreens] = useState<any>([]);
8283

84+
const isWhatsAppFormEnabled = getOrganizationServices('whatsappFormsEnabled');
85+
let buttonOptions = BUTTON_OPTIONS;
86+
if (!isWhatsAppFormEnabled) {
87+
buttonOptions = BUTTON_OPTIONS.filter((option: any) => option.id !== WHATSAPP_FORM);
88+
}
89+
8390
useQuery(LIST_WHATSAPP_FORMS, {
8491
variables: {
8592
filter: { status: 'PUBLISHED' },
@@ -351,7 +358,6 @@ export const TemplateOptions = ({
351358
value={navigate_screen}
352359
renderInput={(params) => <TextField {...params} label="Screen Name" />}
353360
onChange={(event: any, newValue: any) => {
354-
console.log(newValue);
355361
onInputChange(newValue.id, row, index, 'navigate_screen');
356362
}}
357363
disabled={disabled || !form_id}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@
678678
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.10.tgz#a2a1e3812d14525f725d011a73eceb41fef5bc1c"
679679
integrity sha512-aGTxbpbg8/b5JfU1HXSrbH3wXZuLPJcNEcZQFMxLs3oSzgtVu6nFPkbbGGUvBcUjKV2YyB9Wxxabo+HEH9tcRQ==
680680

681-
"@glific/flow-editor@1.43.0-7":
682-
version "1.43.0-7"
683-
resolved "https://registry.yarnpkg.com/@glific/flow-editor/-/flow-editor-1.43.0-7.tgz#864725764e89f4ab88e06f8b83a7b9de13c7317b"
684-
integrity sha512-pdb9fU4eVHK1IXeZLmUZcZnTb07ViDvdN0kDuAdFC/Nrbx1W4CzFtQ4Vve2cop79ZkYWblUCxzYz0gB39CPZcw==
681+
"@glific/flow-editor@1.43.0-8":
682+
version "1.43.0-8"
683+
resolved "https://registry.yarnpkg.com/@glific/flow-editor/-/flow-editor-1.43.0-8.tgz#5e4384210b34651c4569f3124a8ec02294788c04"
684+
integrity sha512-0Fq/WkJjRwuMdReHFeyE1RtkbSAuDZt48BR/HcTxvVvrLIbu84wshvwBFqrusm/4SY1fEpeGHVGPOXvj0dPLng==
685685
dependencies:
686686
"@nyaruka/temba-components" "0.120.4"
687687
react "^16.8.6"

0 commit comments

Comments
 (0)