Skip to content

Commit

Permalink
Merge pull request #2984 from glific/enhancement/hsm-rating
Browse files Browse the repository at this point in the history
Added hsm rating
  • Loading branch information
kurund authored Jul 20, 2024
2 parents d22af88 + be368e9 commit 23298f6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ export const getContactStatus = (contact: {

return statusMessage;
};

export const capitalizeFirstLetter = (string: string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
20 changes: 20 additions & 0 deletions src/containers/Template/List/Template.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@
text-align: end;
}

.LabelContainer {
display: flex;
flex-direction: column;
row-gap: 0.5rem;
}

.LabelText {
font-weight: 500;
font-size: 17px;
word-break: break-all;
}

.Quality {
font-size: 12px;
width: fit-content;
padding: 2px 6px;
background: #f0f7f1;
color: #555555;
border-radius: 8px;
}

.TableText {
text-align: left;
font-size: 14px;
Expand Down Expand Up @@ -129,3 +144,8 @@
.FormStyle {
width: 150px !important;
}

.Category {
width: 20%;
min-width: 100px;
}
29 changes: 26 additions & 3 deletions src/containers/Template/List/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useMutation, useQuery } from '@apollo/client';
import { List } from 'containers/List/List';
import { WhatsAppToJsx } from 'common/RichEditor';
import { STANDARD_DATE_TIME_FORMAT, GUPSHUP_ENTERPRISE_SHORTCODE } from 'common/constants';
import { capitalizeFirstLetter } from 'common/utils';
import {
GET_TEMPLATES_COUNT,
FILTER_TEMPLATES,
Expand Down Expand Up @@ -37,7 +38,12 @@ import { speedSendInfo, templateInfo } from 'common/HelpData';
import styles from './Template.module.css';
import { RaiseToGupShup } from './RaiseToGupshupDialog/RaiseToGupShup';

const getLabel = (label: string) => <div className={styles.LabelText}>{label}</div>;
const getLabel = (label: string, quality?: string) => (
<div className={styles.LabelContainer}>
<div className={styles.LabelText}>{label}</div>
<div className={styles.Quality}>{quality || 'Not Rated'}</div>
</div>
);

const getBody = (text: string) => <p className={styles.TableText}>{WhatsAppToJsx(text)}</p>;

Expand All @@ -55,6 +61,12 @@ const getTranslations = (language: any, data: string) => {
return JSON.stringify(dataObj);
};

const getCategory = (category: string) => {
// let's make category more user friendly
let categoryName = category.split('_').join(' ').toLowerCase();
return <p className={styles.TableText}>{capitalizeFirstLetter(categoryName)}</p>;
};

export interface TemplateProps {
title: string;
listItem: string;
Expand Down Expand Up @@ -176,6 +188,7 @@ export const Template = ({
];

if (isHSM) {
columnNames.push({ name: 'category', label: t('Category') });
columnNames.push({ name: 'status', label: t('Status') });
if (filters.REJECTED) {
columnNames.push({ label: t('Reason') });
Expand All @@ -189,7 +202,13 @@ export const Template = ({
let columnStyles: any = [styles.Name, styles.Body];

columnStyles = isHSM
? [...columnStyles, styles.Status, ...(filters.REJECTED ? [styles.Reason] : []), styles.Actions]
? [
...columnStyles,
styles.Category,
styles.Status,
...(filters.REJECTED ? [styles.Reason] : []),
styles.Actions,
]
: [...columnStyles, styles.LastModified, styles.Actions];

const getColumns = ({
Expand All @@ -201,13 +220,17 @@ export const Template = ({
translations,
status,
reason,
quality,
category,
}: any) => {
const columns: any = {
id,
label: getLabel(label),
label: getLabel(label, quality),
body: getBody(body),
};

if (isHSM) {
columns.category = getCategory(category);
columns.status = getStatus(status);
if (filters.REJECTED) {
columns.reason = getReason(reason);
Expand Down
10 changes: 10 additions & 0 deletions src/containers/Template/Template.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const SpeedSendsSessionTemplates = [
isActive: false,
updatedAt: '2020-12-01T18:00:28Z',
numberParameters: 0,
cateory: null,
quality: null,
translations:
'{"2":{"status":"approved","languageId":{"localized":true,"locale":"hi","label":"Hindi","id":"2","__typename":"Language"},"label":"आप ग्लिफ़िक के लिए कितने उत्साहित हैं?","isHsm":false,"body":"यह संदेश है\\n","MessageMedia":null}}',
type: 'TEXT',
Expand Down Expand Up @@ -97,6 +99,8 @@ const HSMSessionTemplates = [
translations: '{}',
type: 'TEXT',
numberParameters: 2,
quality: 'high',
cateory: 'MARKETING',
language: {
id: '1',
label: 'Hindi',
Expand Down Expand Up @@ -141,6 +145,8 @@ const sessionTemplates = [
isReserved: false,
translations: '{}',
type: 'TEXT',
quality: null,
cateory: null,
language: {
id: '1',
label: 'Hindi',
Expand Down Expand Up @@ -203,6 +209,8 @@ const filterTemplateQuery = {
isReserved: false,
updatedAt: '2020-12-01T18:00:32Z',
translations: '{}',
quality: null,
cateory: null,
},
],
},
Expand Down Expand Up @@ -779,10 +787,12 @@ const getHSMTemplate = (id: string, status: string) => ({
isHsm: true,
isReserved: false,
label: 'Account Balance',
category: 'ACCOUNT_UPDATE',
language: { id: '1', label: 'English' },
shortcode: 'account_balance',
status,
reason: 'test reason',
quality: null,
translations:
'{"2":{"number_parameters":1,"language_id":2,"body":" अब आप नीचे दिए विकल्पों में से एक का चयन करके {{1}} के साथ समाप्त होने वाले खाते के लिए अपना खाता शेष या मिनी स्टेटमेंट देख सकते हैं। | [अकाउंट बैलेंस देखें] | [देखें मिनी स्टेटमेंट]"}}',
type: 'TEXT',
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/queries/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const templateFields = `
updatedAt
translations
type
quality
category
language {
id
label
Expand Down
4 changes: 4 additions & 0 deletions src/mocks/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const TEMPLATE_MOCKS = [
label: 'Good message',
body: 'Hey there',
shortcode: 'test',
category: 'ACCOUNT_UPDATE',
isReserved: true,
status: 'APPROVED',
reason: 'test reason',
Expand Down Expand Up @@ -79,6 +80,7 @@ export const TEMPLATE_MOCKS = [
bspId: null,
label: 'Good message',
body: 'Hey there',
category: 'ACCOUNT_UPDATE',
shortcode: 'test',
isReserved: true,
isHsm: true,
Expand All @@ -105,6 +107,7 @@ export const TEMPLATE_MOCKS = [
bspId: null,
body: 'some description',
shortcode: 'test',
category: 'ACCOUNT_UPDATE',
isReserved: true,
isHsm: false,
isActive: true,
Expand Down Expand Up @@ -133,6 +136,7 @@ export const TEMPLATE_MOCKS = [
label: 'Good message',
bspId: null,
body: 'hi can you help!',
category: 'ACCOUNT_UPDATE',
shortcode: 'test',
isReserved: true,
isHsm: true,
Expand Down

0 comments on commit 23298f6

Please sign in to comment.