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

Display warning & attachment fixes #933

Merged
merged 5 commits into from
Jan 25, 2021
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 @@ -22,3 +22,12 @@
align-items: center;
margin-left: 10px;
}

.FormHelperText {
position: absolute;
margin-top: 65px;
color: #ff0000;
width: 85%;
left: 0px;
line-height: 1.3;
}
24 changes: 22 additions & 2 deletions src/containers/Chat/ChatMessages/AddAttachment/AddAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
attachmentURL: Yup.string().required('URL is required.'),
});

const displayWarning = () => {
if (attachmentType === 'STICKER') {
return (
<div className={styles.FormHelperText}>
<ol>
<li>Animated stickers are not supported.</li>
<li>Captions along with stickers are not supported.</li>
</ol>
</div>
);
}
return (
<div className={styles.FormHelperText}>
<ol>
<li>Captions along with audio are not supported.</li>
</ol>
</div>
);
};

const form = (
<Formik
enableReinitialize
Expand All @@ -80,8 +100,6 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
}}
handleCancel={() => {
setAttachment(false);
setAttachmentType('');
setAttachmentURL('');
}}
buttonOk="Add"
alignButtons="left"
Expand All @@ -95,11 +113,13 @@ export const AddAttachment: React.FC<AddAttachmentPropTypes> = ({
<CrossIcon
onClick={() => {
setAttachmentType('');
setAttachmentURL('');
setAttachmentAdded(false);
}}
/>
</div>
) : null}
{attachmentType === 'STICKER' || attachmentType === 'AUDIO' ? displayWarning() : null}
</div>
</DialogBox>
</Form>
Expand Down
3 changes: 2 additions & 1 deletion src/containers/Chat/ChatMessages/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ChatInput: React.SFC<ChatInputProps> = (props) => {
const [searchVal, setSearchVal] = useState('');
const [attachment, setAttachment] = useState(false);
const [attachmentAdded, setAttachmentAdded] = useState(false);
const [attachmentType, setAttachmentType] = useState('');
const [attachmentType, setAttachmentType] = useState<any>();
const [attachmentURL, setAttachmentURL] = useState('');
const [variable, setVariable] = useState(false);
const [updatedEditorState, setUpdatedEditorState] = useState<any>();
Expand Down Expand Up @@ -354,6 +354,7 @@ export const ChatInput: React.SFC<ChatInputProps> = (props) => {
className={updatedEditorState ? styles.CrossIcon : styles.CrossIconWithVariable}
onClick={() => {
resetVariable();
resetAttachment();
}}
>
<CrossIcon />
Expand Down
47 changes: 25 additions & 22 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ import { CREATE_MEDIA_MESSAGE } from '../../../graphql/mutations/Chat';
import { Checkbox } from '../../../components/UI/Form/Checkbox/Checkbox';
import { USER_LANGUAGES } from '../../../graphql/queries/Organization';

const validation = {
language: Yup.object().nullable().required('Language is required.'),
label: Yup.string().required('Title is required.').max(50, 'Title length is too long.'),
body: Yup.string()
.transform((current, original) => {
return original.getCurrentContent().getPlainText();
})
.required('Message is required.'),
type: Yup.object()
.nullable()
.when('attachmentURL', {
is: (val) => val && val !== '',
then: Yup.object().required('Type is required.'),
}),
attachmentURL: Yup.string()
.nullable()
.when('type', {
is: (val) => val && val.id,
then: Yup.string().required('Attachment URL is required.'),
}),
};

const HSMValidation = {
example: Yup.string()
.transform((current, original) => {
Expand Down Expand Up @@ -436,6 +414,31 @@ const Template: React.SFC<TemplateProps> = (props) => {
return data;
};

const validation = {
language: Yup.object().nullable().required('Language is required.'),
label: Yup.string().required('Title is required.').max(50, 'Title length is too long.'),
body: Yup.string()
.transform((current, original) => {
return original.getCurrentContent().getPlainText();
})
.when('type', {
is: (val) => (!defaultAttribute.isHsm && !val) || defaultAttribute.isHsm,
then: Yup.string().required('Message is required.'),
}),
type: Yup.object()
.nullable()
.when('attachmentURL', {
is: (val) => val && val !== '',
then: Yup.object().required('Type is required.'),
}),
attachmentURL: Yup.string()
.nullable()
.when('type', {
is: (val) => val && val.id,
then: Yup.string().required('Attachment URL is required.'),
}),
};

const validationObj = defaultAttribute.isHsm ? { ...validation, ...HSMValidation } : validation;
const FormSchema = Yup.object().shape(validationObj, [['type', 'attachmentURL']]);

Expand Down