Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor validation enhancements in interactive messages #2020

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,64 +147,66 @@ export const ListReplyTemplateDrawer: React.SFC<ListTemplate> = (props) => {
onItemClick(checkedItem);
};

const list = items.items.map((item: any, index: number) => {
const { options, title: sectionTitle } = item;

if (!sectionTitle) {
return null;
}

return (
<div key={uuidv4()}>
<div className={styles.SectionTitle}>{sectionTitle}</div>
<div className={styles.Options}>
{options
.map((option: any) => {
const payloadObject = {
payload: {
type: 'list_reply',
title: option.title,
id: '',
reply: `${option.title} ${index + 1} `,
postbackText: '',
description: option.description,
},
context: {
id: '',
gsId: items.bspMessageId,
},
};

if (option.title) {
return (
<Button
key={uuidv4()}
className={styles.ListItem}
onClick={() => setCheckedItem(payloadObject)}
>
<div>
<div>{option.title}</div>
<div>{option.description}</div>
</div>
<div>
<Radio
value={option.title}
name="radio-list-item"
size="small"
checked={checkedItem && option.title === checkedItem.payload.title}
color="primary"
/>
</div>
</Button>
);
}
return null;
})
.filter((a: any) => a)}
const list =
items.items &&
items.items.map((item: any, index: number) => {
const { options, title: sectionTitle } = item;

if (!sectionTitle) {
return null;
}

return (
<div key={uuidv4()}>
<div className={styles.SectionTitle}>{sectionTitle}</div>
<div className={styles.Options}>
{options
.map((option: any) => {
const payloadObject = {
payload: {
type: 'list_reply',
title: option.title,
id: '',
reply: `${option.title} ${index + 1} `,
postbackText: '',
description: option.description,
},
context: {
id: '',
gsId: items.bspMessageId,
},
};

if (option.title) {
return (
<Button
key={uuidv4()}
className={styles.ListItem}
onClick={() => setCheckedItem(payloadObject)}
>
<div>
<div>{option.title}</div>
<div>{option.description}</div>
</div>
<div>
<Radio
value={option.title}
name="radio-list-item"
size="small"
checked={checkedItem && option.title === checkedItem.payload.title}
color="primary"
/>
</div>
</Button>
);
}
return null;
})
.filter((a: any) => a)}
</div>
</div>
</div>
);
});
);
});

return (
<div className={styles.Drawer}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const InteractiveOptions: React.SFC<InteractiveOptionsProps> = ({
<TextField
placeholder="List header"
variant="outlined"
label="List header"
label="List header*"
className={styles.TextField}
onChange={(e: any) => {
setFieldValue('globalButton', e.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ListReplyTemplate: React.SFC<ListReplyTemplateProps> = (props) => {
return !!error;
})();

const sectionLabel = `Enter list ${index + 1} title`;
const sectionLabel = `Enter list ${index + 1} title*`;

const { templateButtons } = values;
const { options } = templateButtons[index];
Expand All @@ -74,8 +74,7 @@ export const ListReplyTemplate: React.SFC<ListReplyTemplateProps> = (props) => {

const isAddMoreOptionAllowed = inputFields.reduce((result: number, field: any) => {
const { options: optn } = field;
const sum = result + optn.length;
return sum;
return result + (optn ? optn.length : 0);
}, 0);

const handleAddListItem = (helper: any) => {
Expand Down Expand Up @@ -119,7 +118,7 @@ export const ListReplyTemplate: React.SFC<ListReplyTemplateProps> = (props) => {
<FormControl fullWidth error={isListTitleError} className={styles.FormControl}>
<TextField
label={sectionLabel}
placeholder={sectionLabel}
placeholder={t(`List ${index + 1} title (Max 24 char.)`)}
variant="outlined"
onChange={(e: any) => handleInputChange(e, 'title')}
className={styles.TextField}
Expand Down Expand Up @@ -153,17 +152,17 @@ export const ListReplyTemplate: React.SFC<ListReplyTemplateProps> = (props) => {
className={styles.FormControl}
>
<TextField
placeholder={`Title ${itemIndex + 1}`}
placeholder={`Title ${itemIndex + 1} (Max 24 char.)`}
variant="outlined"
label={`Enter list item ${itemIndex + 1} title`}
label={`Enter list item ${itemIndex + 1} title*`}
onChange={(e: any) => handleInputChange(e, 'title', itemIndex, true)}
className={styles.TextField}
error={isError('title', itemIndex)}
value={itemRow.title}
helperText={
isError('title', itemIndex)
? undefined
: t('Only alphanumeric characters and spaces are allowed')
: t('Alphanumeric characters and spaces are allowed')
}
InputProps={{
endAdornment: itemIndex !== 0 && showDeleteIcon && (
Expand Down Expand Up @@ -197,7 +196,7 @@ export const ListReplyTemplate: React.SFC<ListReplyTemplateProps> = (props) => {
className={styles.FormControl}
>
<TextField
placeholder={`Description ${itemIndex + 1}`}
placeholder={`Description ${itemIndex + 1} (Max 60 char.)`}
variant="outlined"
label={`Enter list item ${itemIndex + 1} description`}
onChange={(e: any) =>
Expand Down