feat: mailgun setup in notifications
This commit is contained in:
parent
4517a373cc
commit
c4ca91b59b
2 changed files with 86 additions and 43 deletions
|
|
@ -11,6 +11,7 @@ import twilioSchema from 'src/pages/Services/schemas/twilio'
|
||||||
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
||||||
|
|
||||||
import Section from '../../components/layout/Section'
|
import Section from '../../components/layout/Section'
|
||||||
|
import mailgunSchema from '../Services/schemas/mailgun'
|
||||||
|
|
||||||
import NotificationsCtx from './NotificationsContext'
|
import NotificationsCtx from './NotificationsContext'
|
||||||
import CryptoBalanceAlerts from './sections/CryptoBalanceAlerts'
|
import CryptoBalanceAlerts from './sections/CryptoBalanceAlerts'
|
||||||
|
|
@ -64,6 +65,7 @@ const Notifications = ({
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
const [editingKey, setEditingKey] = useState(null)
|
const [editingKey, setEditingKey] = useState(null)
|
||||||
const [smsSetupPopup, setSmsSetupPopup] = useState(false)
|
const [smsSetupPopup, setSmsSetupPopup] = useState(false)
|
||||||
|
const [emailSetupPopup, setEmailSetupPopup] = useState(false)
|
||||||
|
|
||||||
const { data, loading } = useQuery(GET_INFO)
|
const { data, loading } = useQuery(GET_INFO)
|
||||||
|
|
||||||
|
|
@ -74,7 +76,10 @@ const Notifications = ({
|
||||||
})
|
})
|
||||||
|
|
||||||
const [saveAccount] = useMutation(SAVE_ACCOUNT, {
|
const [saveAccount] = useMutation(SAVE_ACCOUNT, {
|
||||||
onCompleted: () => setSmsSetupPopup(false),
|
onCompleted: () => {
|
||||||
|
setSmsSetupPopup(false)
|
||||||
|
setEmailSetupPopup(false)
|
||||||
|
},
|
||||||
refetchQueries: ['getData'],
|
refetchQueries: ['getData'],
|
||||||
onError: error => setError(error)
|
onError: error => setError(error)
|
||||||
})
|
})
|
||||||
|
|
@ -83,6 +88,7 @@ const Notifications = ({
|
||||||
const machines = data?.machines
|
const machines = data?.machines
|
||||||
const cryptoCurrencies = data?.cryptoCurrencies
|
const cryptoCurrencies = data?.cryptoCurrencies
|
||||||
const twilioAvailable = R.has('twilio', data?.accounts || {})
|
const twilioAvailable = R.has('twilio', data?.accounts || {})
|
||||||
|
const mailgunAvailable = R.has('mailgun', data?.accounts || {})
|
||||||
|
|
||||||
const currency = R.path(['fiatCurrency'])(
|
const currency = R.path(['fiatCurrency'])(
|
||||||
fromNamespace(namespaces.LOCALE)(data?.config)
|
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 isEditing = key => editingKey === key
|
||||||
const isDisabled = key => editingKey && editingKey !== key
|
const isDisabled = key => editingKey && editingKey !== key
|
||||||
|
|
||||||
|
|
@ -126,11 +140,14 @@ const Notifications = ({
|
||||||
machines,
|
machines,
|
||||||
cryptoCurrencies,
|
cryptoCurrencies,
|
||||||
twilioAvailable,
|
twilioAvailable,
|
||||||
setSmsSetupPopup
|
setSmsSetupPopup,
|
||||||
|
mailgunAvailable,
|
||||||
|
setEmailSetupPopup
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
!loading && (
|
!loading && (
|
||||||
|
<>
|
||||||
<NotificationsCtx.Provider value={contextValue}>
|
<NotificationsCtx.Provider value={contextValue}>
|
||||||
{displayTitle && <TitleSection title="Notifications" />}
|
{displayTitle && <TitleSection title="Notifications" />}
|
||||||
{displaySetup && (
|
{displaySetup && (
|
||||||
|
|
@ -139,7 +156,9 @@ const Notifications = ({
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
{displayTransactionAlerts && (
|
{displayTransactionAlerts && (
|
||||||
<Section title="Transaction alerts" error={error && section === 'tx'}>
|
<Section
|
||||||
|
title="Transaction alerts"
|
||||||
|
error={error && section === 'tx'}>
|
||||||
<TransactionAlerts section="tx" fieldWidth={FIELDS_WIDTH} />
|
<TransactionAlerts section="tx" fieldWidth={FIELDS_WIDTH} />
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
|
|
@ -169,6 +188,7 @@ const Notifications = ({
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
|
</NotificationsCtx.Provider>
|
||||||
{smsSetupPopup && (
|
{smsSetupPopup && (
|
||||||
<Modal
|
<Modal
|
||||||
title={`Configure Twilio`}
|
title={`Configure Twilio`}
|
||||||
|
|
@ -186,7 +206,24 @@ const Notifications = ({
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
</NotificationsCtx.Provider>
|
{emailSetupPopup && (
|
||||||
|
<Modal
|
||||||
|
title={`Configure Mailgun`}
|
||||||
|
width={478}
|
||||||
|
handleClose={() => setEmailSetupPopup(false)}
|
||||||
|
open={true}>
|
||||||
|
<P>
|
||||||
|
In order for the mail notifications to work, you'll first need to
|
||||||
|
configure Mailgun.
|
||||||
|
</P>
|
||||||
|
<FormRenderer
|
||||||
|
save={mailgunSave}
|
||||||
|
elements={mailgunSchema.elements}
|
||||||
|
validationSchema={mailgunSchema.getValidationSchema}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@ const Setup = ({ wizard, forceDisable }) => {
|
||||||
data: rawData,
|
data: rawData,
|
||||||
save: rawSave,
|
save: rawSave,
|
||||||
twilioAvailable,
|
twilioAvailable,
|
||||||
setSmsSetupPopup
|
setSmsSetupPopup,
|
||||||
|
mailgunAvailable,
|
||||||
|
setEmailSetupPopup
|
||||||
} = useContext(NotificationsCtx)
|
} = useContext(NotificationsCtx)
|
||||||
|
|
||||||
const namespaces = [
|
const namespaces = [
|
||||||
|
|
@ -93,7 +95,11 @@ const Setup = ({ wizard, forceDisable }) => {
|
||||||
name: 'email',
|
name: 'email',
|
||||||
forceDisable: forceDisable,
|
forceDisable: forceDisable,
|
||||||
shouldUpperCase: false,
|
shouldUpperCase: false,
|
||||||
onActivation: () => true
|
onActivation: () => {
|
||||||
|
if (mailgunAvailable) return true
|
||||||
|
setEmailSetupPopup(true)
|
||||||
|
return false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'sms',
|
name: 'sms',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue