Skip to content

Commit

Permalink
Merge pull request #2962 from glific/enhancement/hsm-category-button
Browse files Browse the repository at this point in the history
Added a checkbox for re-categorisation of HSM template categories
  • Loading branch information
kurund authored Jul 8, 2024
2 parents feac4ea + e58ecca commit 37168cf
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/components/UI/Form/Checkbox/Checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@
height: 16px;
width: 16px;
}

.Disabled {
opacity: 60%;
}
2 changes: 1 addition & 1 deletion src/components/UI/Form/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const Checkbox = ({
};

return (
<div className={`${styles.Checkbox} ${className}`}>
<div className={`${styles.Checkbox} ${className} ${disabled && styles.Disabled}`}>
<FormControlLabel
control={
<CheckboxElement
Expand Down
7 changes: 7 additions & 0 deletions src/containers/Template/Form/HSM/HSM.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
width: 29px;
height: 29px;
}

.IsActive {
color: #555555;
font-weight: 400;
line-height: 18px;
font-size: 16px;
}
2 changes: 2 additions & 0 deletions src/containers/Template/Form/HSM/HSM.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ describe('Add mode', () => {
fireEvent.keyDown(category, { key: 'ArrowDown' });
fireEvent.keyDown(category, { key: 'Enter' });

fireEvent.click(screen.getByText('Allow meta to re-categorize template?'));

attachmentType.focus();
fireEvent.keyDown(attachmentType, { key: 'ArrowDown' });
fireEvent.keyDown(attachmentType, { key: 'ArrowDown' });
Expand Down
17 changes: 17 additions & 0 deletions src/containers/Template/Form/HSM/HSM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Loading } from 'components/UI/Layout/Loading/Loading';
import { Simulator } from 'components/simulator/Simulator';
import Template from '../Template';
import styles from './HSM.module.css';
import { Checkbox } from 'components/UI/Form/Checkbox/Checkbox';
import { Typography } from '@mui/material';

const defaultAttribute = {
isHsm: true,
Expand All @@ -31,6 +33,7 @@ export const HSM = () => {
const [category, setCategory] = useState<any>(undefined);
const [example, setExample] = useState();
const [editorState, setEditorState] = useState<any>('');
const [allowTemplateCategoryChange, setAllowTemplateCategoryChange] = useState<boolean>(false);

const { t } = useTranslation();
const params = useParams();
Expand Down Expand Up @@ -127,6 +130,18 @@ export const HSM = () => {
setCategory(event);
},
},
{
component: Checkbox,
name: 'allowTemplateCategoryChange',
title: (
<Typography variant="h6" className={styles.IsActive}>
Allow meta to re-categorize template?
</Typography>
),
darkCheckbox: true,
disabled: isEditing,
handleChange: (value: boolean) => setAllowTemplateCategoryChange(value),
},
{
component: Input,
name: 'shortcode',
Expand Down Expand Up @@ -154,6 +169,8 @@ export const HSM = () => {
category={category}
onExampleChange={addButtonsToSampleMessage}
setExampleState={setEditorState}
allowTemplateCategoryChange={allowTemplateCategoryChange}
setAllowTemplateCategoryChange={setAllowTemplateCategoryChange}
/>
<Simulator isPreviewMessage message={sampleMessages} simulatorIcon={false} />
</div>
Expand Down
19 changes: 15 additions & 4 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface TemplateProps {
onExampleChange?: any;
languageStyle?: string;
setExampleState?: any;
allowTemplateCategoryChange?: boolean;
setAllowTemplateCategoryChange?: any;
}

interface CallToActionTemplate {
Expand Down Expand Up @@ -144,6 +146,8 @@ const Template = ({
onExampleChange = () => {},
languageStyle = 'dropdown',
setExampleState,
allowTemplateCategoryChange,
setAllowTemplateCategoryChange,
}: TemplateProps) => {
// "Audio" option is removed in case of HSM Template
const mediaTypes =
Expand Down Expand Up @@ -221,6 +225,7 @@ const Template = ({
isActive,
templateButtons,
isAddButtonChecked,
allowTemplateCategoryChange,
};

const setStates = ({
Expand All @@ -238,6 +243,7 @@ const Template = ({
buttonType: templateButtonType,
buttons,
hasButtons,
allowTemplateCategoryChange: allowCategoryChangeValue,
}: any) => {
if (languageOptions.length > 0 && languageIdValue) {
if (location.state && location.state !== 'copy') {
Expand All @@ -258,6 +264,9 @@ const Template = ({

setLabel(labelValue);
setIsActive(isActiveValue);
if (setAllowTemplateCategoryChange) {
setAllowTemplateCategoryChange(allowCategoryChangeValue);
}

if (typeof bodyValue === 'string') {
setBody(bodyValue || '');
Expand Down Expand Up @@ -748,14 +757,15 @@ const Template = ({
};

const hsmFields = formField && [
...formFields,
...formField.slice(0, 1),
...templateRadioOptions,
...formField.slice(1),
...attachmentField,
tags,
];

const fields = defaultAttribute.isHsm
? [...formFields, ...hsmFields, ...attachmentField, tags]
: [...formFields, ...attachmentField];
const fields = defaultAttribute.isHsm ? hsmFields : [...formFields, ...attachmentField];

// Creating payload for button template
const getButtonTemplatePayload = () => {
Expand Down Expand Up @@ -816,9 +826,9 @@ const Template = ({
}
} else {
delete payloadCopy.example;
delete payloadCopy.isActive;
delete payloadCopy.shortcode;
delete payloadCopy.category;
delete payloadCopy.allowTemplateCategoryChange;
}
if (payloadCopy.type === 'TEXT') {
delete payloadCopy.attachmentURL;
Expand Down Expand Up @@ -874,6 +884,7 @@ const Template = ({
delete payloadCopy.example;
delete payloadCopy.shortcode;
delete payloadCopy.category;
delete payloadCopy.allowTemplateCategoryChange;
}

delete payloadCopy.isAddButtonChecked;
Expand Down
8 changes: 8 additions & 0 deletions src/containers/Template/Template.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ const getTemplateData = {
buttonType: null,
updatedAt: '2020-12-01T18:00:32Z',
tag: null,
allowTemplateCategoryChange: false,
},
},
};
Expand All @@ -281,6 +282,7 @@ const createHsmWithButtontemplate = {
'[{"type":"QUICK_REPLY","text":"Quick reply 1"},{"type":"QUICK_REPLY","text":"Quick reply 2"}]',
buttonType: 'QUICK_REPLY',
translations: '{}',
allowTemplateCategoryChange: false,
},
},
},
Expand All @@ -306,6 +308,7 @@ const createHsmWithButtontemplate = {
buttons:
'[{"type":"QUICK_REPLY","text":"Quick reply 1"},{"type":"QUICK_REPLY","text":"Quick reply 2"}]',
buttonType: 'QUICK_REPLY',
allowTemplateCategoryChange: true,
},
errors: null,
},
Expand All @@ -332,6 +335,7 @@ const createHsmWithPhonetemplate = {
buttons: '[{"type":"PHONE_NUMBER","text":"Call me","phone_number":"9876543210"}]',
buttonType: 'CALL_TO_ACTION',
translations: '{}',
allowTemplateCategoryChange: false,
},
},
},
Expand All @@ -356,6 +360,7 @@ const createHsmWithPhonetemplate = {
hasButtons: true,
buttons: '[{"type":"PHONE_NUMBER","text":"Call me","phone_number":"9876543210"}]',
buttonType: 'CALL_TO_ACTION',
allowTemplateCategoryChange: false,
},
errors: null,
},
Expand All @@ -380,6 +385,7 @@ const createHSMtemplate = {
languageId: '1',
translations: '{}',
messageMediaId: 5,
allowTemplateCategoryChange: true,
},
},
},
Expand All @@ -404,6 +410,7 @@ const createHSMtemplate = {
hasButtons: false,
buttons: null,
buttonType: null,
allowTemplateCategoryChange: true,
},
errors: null,
},
Expand Down Expand Up @@ -587,6 +594,7 @@ const getHSMTemplate = (id: string, status: string) => ({
type: 'TEXT',
numberParameters: 2,
updatedAt: '2021-07-28T08:00:24Z',
allowTemplateCategoryChange: true,
});

export const HSM_LIST = [
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/mutations/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const CREATE_TEMPLATE = gql`
hasButtons
buttons
buttonType
allowTemplateCategoryChange
}
errors {
key
Expand Down Expand Up @@ -70,6 +71,7 @@ export const UPDATE_TEMPLATE = gql`
hasButtons
buttons
buttonType
allowTemplateCategoryChange
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/graphql/queries/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const GET_TEMPLATE = gql`
hasButtons
buttons
buttonType
allowTemplateCategoryChange
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mocks/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export const templateEditMock = (templateId: string, buttons: any) => ({
'{"2":{"uuid":"0de5b294-0385-48d0-bdc0-53cc833a31c5","status":"APPROVED","number_parameters":1,"language_id":2,"label":"Account Balance","example":" अब आप नीचे दिए विकल्पों में से एक का चयन करके [003] के साथ समाप्त होने वाले खाते के लिए अपना खाता शेष या मिनी स्टेटमेंट देख सकते हैं। | [अकाउंट बैलेंस देखें] | [देखें मिनी स्टेटमेंट]","body":" अब आप नीचे दिए विकल्पों में से एक का चयन करके {{1}} के साथ समाप्त होने वाले खाते के लिए अपना खाता शेष या मिनी स्टेटमेंट देख सकते हैं। | [अकाउंट बैलेंस देखें] | [देखें मिनी स्टेटमेंट]"}}',
type: 'TEXT',
updatedAt: '2024-03-28T10:41:16Z',
allowTemplateCategoryChange: true,
...buttons,
},
},
Expand Down

0 comments on commit 37168cf

Please sign in to comment.