Skip to content

Commit 9ce8479

Browse files
authored
Merge pull request #3663 from glific/hide-whatsapp-forms-under-flag
Hide whatsapp forms button under the feature flag
2 parents 0cb02c0 + f349898 commit 9ce8479

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

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/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: '',
@@ -333,7 +327,7 @@ export const HSM = () => {
333327
if (hasButtons) {
334328
const { buttons: buttonsVal } = getTemplateAndButtons(templateButtonType, exampleValue, buttons);
335329
setTemplateButtons(buttonsVal);
336-
setTemplateType(buttonOptions.find((btn: any) => btn.id === templateButtonType));
330+
setTemplateType(BUTTON_OPTIONS.find((btn: any) => btn.id === templateButtonType));
337331
setIsAddButtonChecked(hasButtons);
338332
const parse = convertButtonsToTemplate(buttonsVal, templateButtonType);
339333
const parsedText = parse.length ? `| ${parse.join(' | ')}` : null;

src/containers/TemplateOptions/TemplateOptions.tsx

Lines changed: 8 additions & 1 deletion
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' },

0 commit comments

Comments
 (0)