fix(frontend): converts email smtp port to a number before posting to the api

- also adds toast notifications to both email/discord notifications pages to know when sucesses or
failures occur

re #251
This commit is contained in:
sct
2020-12-14 09:00:10 +00:00
parent 6c1ee830a1
commit 2098a2d3d2
3 changed files with 29 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import Button from '../../Common/Button';
import { defineMessages, useIntl } from 'react-intl';
import Axios from 'axios';
import * as Yup from 'yup';
import { useToasts } from 'react-toast-notifications';
const messages = defineMessages({
save: 'Save Changes',
@@ -20,10 +21,13 @@ const messages = defineMessages({
enableSsl: 'Enable SSL',
authUser: 'Auth User',
authPass: 'Auth Pass',
emailsettingssaved: 'Email notification settings saved!',
emailsettingsfailed: 'Email notification settings failed to save.',
});
const NotificationsEmail: React.FC = () => {
const intl = useIntl();
const { addToast } = useToasts();
const { data, error, revalidate } = useSWR(
'/api/v1/settings/notifications/email'
);
@@ -65,14 +69,21 @@ const NotificationsEmail: React.FC = () => {
options: {
emailFrom: values.emailFrom,
smtpHost: values.smtpHost,
smtpPort: values.smtpPort,
smtpPort: Number(values.smtpPort),
secure: values.secure,
authUser: values.authUser,
authPass: values.authPass,
},
});
addToast(intl.formatMessage(messages.emailsettingssaved), {
appearance: 'success',
autoDismiss: true,
});
} catch (e) {
// TODO show error
addToast(intl.formatMessage(messages.emailsettingsfailed), {
appearance: 'error',
autoDismiss: true,
});
} finally {
revalidate();
}