From c4ca91b59be9f01854b063dc53b9bf658b4cc752 Mon Sep 17 00:00:00 2001 From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com> Date: Tue, 8 Mar 2022 14:40:24 +0100 Subject: [PATCH] feat: mailgun setup in notifications --- .../src/pages/Notifications/Notifications.js | 119 ++++++++++++------ .../src/pages/Notifications/sections/Setup.js | 10 +- 2 files changed, 86 insertions(+), 43 deletions(-) diff --git a/new-lamassu-admin/src/pages/Notifications/Notifications.js b/new-lamassu-admin/src/pages/Notifications/Notifications.js index b1def515..993fbc51 100644 --- a/new-lamassu-admin/src/pages/Notifications/Notifications.js +++ b/new-lamassu-admin/src/pages/Notifications/Notifications.js @@ -11,6 +11,7 @@ import twilioSchema from 'src/pages/Services/schemas/twilio' import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' import Section from '../../components/layout/Section' +import mailgunSchema from '../Services/schemas/mailgun' import NotificationsCtx from './NotificationsContext' import CryptoBalanceAlerts from './sections/CryptoBalanceAlerts' @@ -64,6 +65,7 @@ const Notifications = ({ const [error, setError] = useState(null) const [editingKey, setEditingKey] = useState(null) const [smsSetupPopup, setSmsSetupPopup] = useState(false) + const [emailSetupPopup, setEmailSetupPopup] = useState(false) const { data, loading } = useQuery(GET_INFO) @@ -74,7 +76,10 @@ const Notifications = ({ }) const [saveAccount] = useMutation(SAVE_ACCOUNT, { - onCompleted: () => setSmsSetupPopup(false), + onCompleted: () => { + setSmsSetupPopup(false) + setEmailSetupPopup(false) + }, refetchQueries: ['getData'], onError: error => setError(error) }) @@ -83,6 +88,7 @@ const Notifications = ({ const machines = data?.machines const cryptoCurrencies = data?.cryptoCurrencies const twilioAvailable = R.has('twilio', data?.accounts || {}) + const mailgunAvailable = R.has('mailgun', data?.accounts || {}) const currency = R.path(['fiatCurrency'])( fromNamespace(namespaces.LOCALE)(data?.config) @@ -110,6 +116,14 @@ const Notifications = ({ }) } + const mailgunSave = it => { + setError(null) + R.compose(save(null), toNamespace('email'))({ active: true }) + return saveAccount({ + variables: { accounts: { mailgun: it } } + }) + } + const isEditing = key => editingKey === key const isDisabled = key => editingKey && editingKey !== key @@ -126,49 +140,55 @@ const Notifications = ({ machines, cryptoCurrencies, twilioAvailable, - setSmsSetupPopup + setSmsSetupPopup, + mailgunAvailable, + setEmailSetupPopup } return ( !loading && ( - - {displayTitle && } - {displaySetup && ( -
- -
- )} - {displayTransactionAlerts && ( -
- -
- )} - {displayFiatAlerts && ( -
- - {displayOverrides && ( - - )} -
- )} - {displayCryptoAlerts && ( -
- - {displayOverrides && ( - - )} -
- )} + <> + + {displayTitle && } + {displaySetup && ( +
+ +
+ )} + {displayTransactionAlerts && ( +
+ +
+ )} + {displayFiatAlerts && ( +
+ + {displayOverrides && ( + + )} +
+ )} + {displayCryptoAlerts && ( +
+ + {displayOverrides && ( + + )} +
+ )} +
{smsSetupPopup && ( )} -
+ {emailSetupPopup && ( + setEmailSetupPopup(false)} + open={true}> +

+ In order for the mail notifications to work, you'll first need to + configure Mailgun. +

+ +
+ )} + ) ) } diff --git a/new-lamassu-admin/src/pages/Notifications/sections/Setup.js b/new-lamassu-admin/src/pages/Notifications/sections/Setup.js index a56f2221..2e8d7583 100644 --- a/new-lamassu-admin/src/pages/Notifications/sections/Setup.js +++ b/new-lamassu-admin/src/pages/Notifications/sections/Setup.js @@ -85,7 +85,9 @@ const Setup = ({ wizard, forceDisable }) => { data: rawData, save: rawSave, twilioAvailable, - setSmsSetupPopup + setSmsSetupPopup, + mailgunAvailable, + setEmailSetupPopup } = useContext(NotificationsCtx) const namespaces = [ @@ -93,7 +95,11 @@ const Setup = ({ wizard, forceDisable }) => { name: 'email', forceDisable: forceDisable, shouldUpperCase: false, - onActivation: () => true + onActivation: () => { + if (mailgunAvailable) return true + setEmailSetupPopup(true) + return false + } }, { name: 'sms',