Skip to content

Commit

Permalink
Merge pull request #1536 from glific/pre-2.0-changes
Browse files Browse the repository at this point in the history
Pre 2.0 changes
  • Loading branch information
mdshamoon authored Jul 15, 2021
2 parents b4e7482 + 34a817e commit 861ded5
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 72 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

#### [v2.0.0](https://github.com/glific/glific-frontend/compare/v1.8.1...v2.0.0)

> 15 July 2021
- Added expression in floweditor attachment [`#1534`](https://github.com/glific/glific-frontend/pull/1534)
- Added contact field support for interactive messages [`#1531`](https://github.com/glific/glific-frontend/pull/1531)
- Added support for preview for interactive messages [`#1526`](https://github.com/glific/glific-frontend/pull/1526)
- Now dialog boxes UI are responsive [`#1490`](https://github.com/glific/glific-frontend/pull/1490)
- Added interactive message support [`#1496`](https://github.com/glific/glific-frontend/pull/1496)
- Error handling for calendar and time picker [`#1520`](https://github.com/glific/glific-frontend/pull/1520)
- Fixed triggers date time [`#1512`](https://github.com/glific/glific-frontend/pull/1512)

#### [v1.8.1](https://github.com/glific/glific-frontend/compare/v1.8.0...v1.8.1)

> 12 July 2021
- Added wait for response expression in floweditor [`#1528`](https://github.com/glific/glific-frontend/pull/1528)

#### [v1.8.0](https://github.com/glific/glific-frontend/compare/v1.7.1...v1.8.0)

> 06 July 2021
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "glific-frontend",
"version": "1.8.0",
"version": "2.0.0",
"private": true,
"dependencies": {
"@absinthe/socket": "^0.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export const MessageType: React.FC<MessageTypeProps> = ({
</>
);
break;
case 'QUICK_REPLY':
message = 'Quick Reply';
break;
case 'LIST':
message = 'List';
break;
default:
message = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@
width: 280px !important;
}
}

.ProgressIcon {
width: 18px !important;
height: 18px !important;
margin: 0px 4px;
}

.HelperText {
display: flex;
flex-direction: row;
align-items: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,45 @@ test('it should render', () => {
expect(getByTestId('attachmentDialog')).toBeInTheDocument();
});

test('uploading a file', async () => {
const { getByTestId } = render(addAttachment('IMAGE'));
const file = { name: 'photo.png' };

fireEvent.change(getByTestId('uploadFile'), { target: { files: [file] } });

await waitFor(() => {
expect(setAttachmentURL).toHaveBeenCalled();
});
});

// Need to clean previous test cases renders

// test('add an attachment', async () => {
// const { getByTestId, getByText } = render(addAttachment('IMAGE', 'https://glific.com'));
// const responseData = { data: { is_valid: true } };
// act(() => {
// axios.get.mockImplementationOnce(() => Promise.resolve(responseData));
// });
// fireEvent.click(getByTestId('ok-button'));

// await waitFor(() => {
// expect(setAttachmentAdded).toHaveBeenCalled();
// });
// });

// test('attachment is invalid', async () => {
// const { getByTestId, getByText } = render(addAttachment('IMAGE', 'https://glific.com'));
// const responseData = { data: { is_valid: false, message: 'Content type not valid' } };
// act(() => {
// axios.get.mockImplementationOnce(() => Promise.resolve(responseData));
// });
// fireEvent.click(getByTestId('ok-button'));

// await waitFor(() => {
// expect(getByText('Content type not valid')).toBeInTheDocument();
// });
// });

test('it should reset type if cross icon is clicked', () => {
const { getByTestId } = render(addAttachment('IMAGE'));
fireEvent.click(getByTestId('crossIcon'));
Expand All @@ -59,32 +98,6 @@ test('cancel button', () => {
expect(setAttachment).toHaveBeenCalled();
});

test('add an attachment', async () => {
const { getByTestId, getByText } = render(addAttachment('IMAGE', 'https://glific.com'));
const responseData = { data: { is_valid: true } };
act(() => {
axios.get.mockImplementationOnce(() => Promise.resolve(responseData));
});
fireEvent.click(getByTestId('ok-button'));

await waitFor(() => {
expect(setAttachmentAdded).toHaveBeenCalled();
});
});

test('attachment is invalid', async () => {
const { getByTestId, getByText } = render(addAttachment('IMAGE', 'https://glific.com'));
const responseData = { data: { is_valid: false, message: 'Content type not valid' } };
act(() => {
axios.get.mockImplementationOnce(() => Promise.resolve(responseData));
});
fireEvent.click(getByTestId('ok-button'));

await waitFor(() => {
expect(getByText('Content type not valid')).toBeInTheDocument();
});
});

test('show warnings if attachment type is audio', async () => {
const { getByText } = render(addAttachment('AUDIO', 'https://glific.com'));

Expand All @@ -95,14 +108,3 @@ test('show warnings if attachment type is sticker', async () => {
const { getByText } = render(addAttachment('STICKER', 'https://glific.com'));
expect(getByText('Animated stickers are not supported.')).toBeInTheDocument();
});

test('uploading a file', async () => {
const { getByTestId } = render(addAttachment('IMAGE'));
const file = { name: 'photo.png' };

fireEvent.change(getByTestId('uploadFile'), { target: { files: [file] } });

await waitFor(() => {
expect(setAttachmentURL).toHaveBeenCalled();
});
});
37 changes: 27 additions & 10 deletions src/containers/Chat/ChatMessages/AddAttachment/AddAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Formik, Form, Field } from 'formik';
import * as Yup from 'yup';
import { useTranslation } from 'react-i18next';
import { useMutation } from '@apollo/client';
import CircularProgress from '@material-ui/core/CircularProgress';

import styles from './AddAttachment.module.css';
import { DialogBox } from '../../../../components/UI/DialogBox/DialogBox';
Expand Down Expand Up @@ -40,7 +41,6 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
attachmentType,
uploadPermission,
}: AddAttachmentPropTypes) => {
const [onSubmit, setOnSubmit] = useState(false);
const [errors, setErrors] = useState<any>(null);
const [uploading, setUploading] = useState(false);
const [fileName, setFileName] = useState<null | string>(null);
Expand All @@ -60,7 +60,7 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
});

const validateURL = () => {
if (attachmentURL && attachmentType && onSubmit) {
if (attachmentURL && attachmentType) {
setVerifying(true);
setErrors(null);

Expand All @@ -71,8 +71,7 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
} else if (response.data.is_valid) {
setVerifying(false);
setAttachmentAdded(true);
setAttachment(false);
setOnSubmit(false);

setErrors(null);
}
});
Expand All @@ -81,25 +80,41 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({

useEffect(() => {
validateURL();
}, [attachmentURL, attachmentType, onSubmit]);
}, [attachmentURL, attachmentType]);

const validate = (value: any) => {
if (value !== attachmentURL) {
setOnSubmit(false);
setAttachmentURL(value);
} else if (!value) {
setErrors(null);
}
};

const helperText = (
<div className={styles.HelperText}>
{t('Please wait for the attachment URL verification')}
<CircularProgress className={styles.ProgressIcon} />
</div>
);

let timer: any = null;
const input = {
component: Input,
name: 'attachmentURL',
type: 'text',
placeholder: t('Attachment URL'),
validate,
helperText: verifying && t('Please wait for the attachment URL verification'),
helperText: verifying && helperText,
disabled: fileName !== null,
inputProp: {
onBlur: (event: any) => {
setAttachmentURL(event.target.value);
},
onChange: (event: any) => {
clearTimeout(timer);
timer = setTimeout(() => setAttachmentURL(event.target.value), 1000);
},
},
};

let formFieldItems: any = [
Expand All @@ -111,7 +126,6 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
fieldValue: attachmentType,
fieldChange: (event: any) => {
setAttachmentType(event?.target.value);
setOnSubmit(false);
setErrors(null);
},
},
Expand Down Expand Up @@ -147,6 +161,7 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
const onSubmitHandle = (itemData: { attachmentURL: any; attachmentType: any }) => {
setAttachmentType(itemData.attachmentType);
setAttachmentURL(itemData.attachmentURL);
setAttachment(false);
};

const addAttachment = (event: any) => {
Expand All @@ -173,8 +188,9 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
initialValues={{ attachmentURL, attachmentType }}
validationSchema={validationSchema}
onSubmit={(itemData) => {
setOnSubmit(true);
onSubmitHandle(itemData);
if (!errors) {
onSubmitHandle(itemData);
}
}}
>
{({ submitForm }) => (
Expand All @@ -193,6 +209,7 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
}}
buttonOk={t('Add')}
alignButtons="left"
disableOk={verifying}
>
<div className={styles.DialogContent} data-testid="attachmentDialog">
{formFieldItems.map((field: any) => (
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Chat/ChatMessages/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const ChatInput: React.SFC<ChatInputProps> = (props) => {
let audioOption: any;
// enable audio only if GCS is configured
if (permission && permission.attachmentsEnabled) {
if (!selectedTemplate) {
if (!selectedTemplate && Object.keys(interactiveMessageContent).length === 0) {
audioOption = (
<VoiceRecorder
handleAudioRecording={handleAudioRecording}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
margin: 6px 0px !important;
}

.GlobalButton > span {
justify-content: center;
}

.SimulatorButton {
composes: GlobalButton;
font-size: 12.5px !important;
Expand All @@ -39,6 +35,7 @@
.ListItem {
font-size: 12px !important;
width: 100%;
font-weight: 300 !important;
}

.ListItem > span {
Expand All @@ -47,6 +44,7 @@

.ListItem > span > div {
text-align: left;
color: #073f24;
}

.Drawer {
Expand All @@ -63,6 +61,7 @@
.DrawerHeading {
display: flex;
justify-content: center;
color: #073f24;
}

.DrawerHeading > h3 {
Expand Down Expand Up @@ -144,3 +143,15 @@
.DialogContent {
width: 370px;
}

.SectionTitle {
color: #073f24;
font-size: 14px;
font-weight: 400;
padding: 4px 8px;
background-color: #edf6f2;
}

.Options > button:hover {
background-color: #edf6f2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const SimulatorTemplate: React.SFC<TemplateProps> = (props) => {
<div className={styles.SimulatorContent}>
<p>{title}</p>
<p>{body}</p>
<hr />
<Button
color="default"
disabled={disabled}
Expand All @@ -132,25 +131,32 @@ export const ListReplyTemplateDrawer: React.SFC<ListTemplate> = (props) => {
};

const list = items.map((item: any) => {
const { options } = item;
return options.map((option: any) => (
<Button
key={option.title}
className={styles.ListItem}
onClick={() => setCheckedItem(option.title)}
>
<div>{option.title}</div>
<div>
<Radio
value={option.title}
name="radio-list-item"
size="small"
checked={option.title === checkedItem}
color="primary"
/>
const { options, title: sectionTitle } = item;
return (
<div key={sectionTitle}>
<div className={styles.SectionTitle}>{sectionTitle}</div>
<div className={styles.Options}>
{options.map((option: any) => (
<Button
key={option.title}
className={styles.ListItem}
onClick={() => setCheckedItem(option.title)}
>
<div>{option.title}</div>
<div>
<Radio
value={option.title}
name="radio-list-item"
size="small"
checked={option.title === checkedItem}
color="primary"
/>
</div>
</Button>
))}
</div>
</Button>
));
</div>
);
});

return (
Expand Down

0 comments on commit 861ded5

Please sign in to comment.