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

fix: composer modal if attachment word present and file attached is missing #173

Merged
merged 1 commit into from
Sep 15, 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
35 changes: 27 additions & 8 deletions src/views/app/detail-panel/edit/parts/edit-view-header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/*
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
*
Expand Down Expand Up @@ -205,9 +206,20 @@ const EditViewHeader: FC<PropType> = ({

const createModal = useModal();
const sendMailAction = useCallback(() => {
if (editor?.subject) {
sendMailCb();
} else {
const attachWords = [
t('messages.modal.send_anyway.attach', 'attach'),
t('messages.modal.send_anyway.attachment', 'attachment'),
t('messages.modal.send_anyway.attachments', 'attachments'),
t('messages.modal.send_anyway.attached', 'attached'),
t('messages.modal.send_anyway.attaching', 'attaching'),
t('messages.modal.send_anyway.enclose', 'enclose'),
t('messages.modal.send_anyway.enclosed', 'enclosed'),
t('messages.modal.send_anyway.enclosing', 'enclosing')
];
const isattachWordsPresent = attachWords.some((el) =>
editor.text[0].toLowerCase().includes(el)
);
if ((isattachWordsPresent && !editor?.attachmentFiles.length) || !editor?.subject) {
const closeModal = createModal({
title: t('header.attention', 'Attention'),
confirmLabel: t('action.ok', 'Ok'),
Expand All @@ -226,19 +238,26 @@ const EditViewHeader: FC<PropType> = ({
children: (
<StoreProvider>
<Text overflow="break-word" style={{ paddingTop: '16px' }}>
{t(
'messages.modal.send_anyway.first',
"Email subject is empty and you didn't attach any files."
)}
{isattachWordsPresent && !editor?.attachmentFiles.length && !editor?.subject
? t(
'messages.modal.send_anyway.no_subject_no_attachments',
'Email subject is empty and you didn’t attach any files.'
)
: !editor?.subject
? t('messages.modal.send_anyway.no_subject', 'Email subject is empty.')
: t('messages.modal.send_anyway.no_attachments', 'You didn’t attach any files.')}
</Text>

<Text overflow="break-word" style={{ paddingBottom: '16px' }}>
{t('messages.modal.send_anyway.second', 'Do you still want to send the email?')}
</Text>
</StoreProvider>
)
});
} else {
sendMailCb();
}
}, [editor?.subject, createModal, sendMailCb]);
}, [editor?.attachmentFiles.length, editor?.subject, editor.text, createModal, sendMailCb]);

const onSave = useCallback(() => {
saveDraftCb(editor);
Expand Down
12 changes: 11 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,17 @@
"second": "The e-mail will appear as originally intended for the new recipient"
},
"send_anyway": {
"first": "Email subject is empty and you didn't attach any files.",
"attach": "attach",
"attached": "attached",
"attaching": "attaching",
"attachment": "attachment",
"attachments": "attachments",
"enclose": "enclose",
"enclosed": "enclosed",
"enclosing": "enclosing",
"no_attachments": "You didn’t attach any files.",
"no_subject": "Email subject is empty.",
"no_subject_no_attachments": "Email subject is empty and you didn’t attach any files.",
"second": "Do you still want to send the email?"
}
},
Expand Down