feat: admin picked sms provider
This commit is contained in:
parent
3b19caf3a7
commit
f716e4202c
3 changed files with 89 additions and 1 deletions
|
|
@ -25,7 +25,8 @@ function getSms (event, phone, content) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlugin (settings) {
|
function getPlugin (settings) {
|
||||||
const pluginCode = argv.mockSms ? 'mock-sms' : argv.telnyxSms ? 'telnyx' : 'twilio'
|
const smsProvider = settings.config.notifications_thirdParty_provider
|
||||||
|
const pluginCode = smsProvider ?? 'twilio'
|
||||||
const plugin = ph.load(ph.SMS, pluginCode)
|
const plugin = ph.load(ph.SMS, pluginCode)
|
||||||
const account = settings.accounts[pluginCode]
|
const account = settings.accounts[pluginCode]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,19 @@ import CryptoBalanceOverrides from './sections/CryptoBalanceOverrides'
|
||||||
import FiatBalanceAlerts from './sections/FiatBalanceAlerts'
|
import FiatBalanceAlerts from './sections/FiatBalanceAlerts'
|
||||||
import FiatBalanceOverrides from './sections/FiatBalanceOverrides'
|
import FiatBalanceOverrides from './sections/FiatBalanceOverrides'
|
||||||
import Setup from './sections/Setup'
|
import Setup from './sections/Setup'
|
||||||
|
import ThirdPartyProvider from './sections/ThirdPartyProvider'
|
||||||
import TransactionAlerts from './sections/TransactionAlerts'
|
import TransactionAlerts from './sections/TransactionAlerts'
|
||||||
|
|
||||||
const GET_INFO = gql`
|
const GET_INFO = gql`
|
||||||
query getData {
|
query getData {
|
||||||
config
|
config
|
||||||
|
accountsConfig {
|
||||||
|
code
|
||||||
|
display
|
||||||
|
class
|
||||||
|
cryptos
|
||||||
|
deprecated
|
||||||
|
}
|
||||||
machines {
|
machines {
|
||||||
name
|
name
|
||||||
deviceId
|
deviceId
|
||||||
|
|
@ -59,6 +67,7 @@ const Notifications = ({
|
||||||
displayCryptoAlerts = true,
|
displayCryptoAlerts = true,
|
||||||
displayOverrides = true,
|
displayOverrides = true,
|
||||||
displayTitle = true,
|
displayTitle = true,
|
||||||
|
displayThirdPartyProvider = true,
|
||||||
wizard = false
|
wizard = false
|
||||||
}) => {
|
}) => {
|
||||||
const [section, setSection] = useState(null)
|
const [section, setSection] = useState(null)
|
||||||
|
|
@ -86,6 +95,7 @@ const Notifications = ({
|
||||||
|
|
||||||
const config = fromNamespace(SCREEN_KEY)(data?.config)
|
const config = fromNamespace(SCREEN_KEY)(data?.config)
|
||||||
const machines = data?.machines
|
const machines = data?.machines
|
||||||
|
const accountsConfig = data?.accountsConfig
|
||||||
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 mailgunAvailable = R.has('mailgun', data?.accounts || {})
|
||||||
|
|
@ -136,6 +146,7 @@ const Notifications = ({
|
||||||
setEditing,
|
setEditing,
|
||||||
setSection,
|
setSection,
|
||||||
machines,
|
machines,
|
||||||
|
accountsConfig,
|
||||||
cryptoCurrencies,
|
cryptoCurrencies,
|
||||||
twilioAvailable,
|
twilioAvailable,
|
||||||
setSmsSetupPopup,
|
setSmsSetupPopup,
|
||||||
|
|
@ -148,6 +159,13 @@ const Notifications = ({
|
||||||
<>
|
<>
|
||||||
<NotificationsCtx.Provider value={contextValue}>
|
<NotificationsCtx.Provider value={contextValue}>
|
||||||
{displayTitle && <TitleSection title="Notifications" />}
|
{displayTitle && <TitleSection title="Notifications" />}
|
||||||
|
{displayThirdPartyProvider && (
|
||||||
|
<Section
|
||||||
|
title="Third party providers"
|
||||||
|
error={error && !section === 'thirdParty'}>
|
||||||
|
<ThirdPartyProvider section="thirdParty" />
|
||||||
|
</Section>
|
||||||
|
)}
|
||||||
{displaySetup && (
|
{displaySetup && (
|
||||||
<Section title="Setup" error={error && !section}>
|
<Section title="Setup" error={error && !section}>
|
||||||
<Setup forceDisable={!!editingKey} wizard={wizard} />
|
<Setup forceDisable={!!editingKey} wizard={wizard} />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
import * as R from 'ramda'
|
||||||
|
import React, { useContext } from 'react'
|
||||||
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
|
import { Table as EditableTable } from 'src/components/editableTable'
|
||||||
|
import Autocomplete from 'src/components/inputs/formik/Autocomplete'
|
||||||
|
import { toNamespace, fromNamespace } from 'src/utils/config'
|
||||||
|
|
||||||
|
import NotificationsCtx from '../NotificationsContext'
|
||||||
|
|
||||||
|
const filterClass = type => R.filter(it => it.class === type)
|
||||||
|
|
||||||
|
const ThirdPartyProvider = () => {
|
||||||
|
const { save, data: _data, error, accountsConfig } = useContext(
|
||||||
|
NotificationsCtx
|
||||||
|
)
|
||||||
|
|
||||||
|
const data = fromNamespace('thirdParty')(_data)
|
||||||
|
|
||||||
|
const filterOptions = type => filterClass(type)(accountsConfig || [])
|
||||||
|
|
||||||
|
const getDisplayName = type => it =>
|
||||||
|
R.compose(
|
||||||
|
R.prop('display'),
|
||||||
|
R.find(R.propEq('code', it))
|
||||||
|
)(filterOptions(type))
|
||||||
|
|
||||||
|
const innerSave = async value => {
|
||||||
|
const config = toNamespace('thirdParty')(value?.thirdParty[0])
|
||||||
|
await save('thirdParty', config)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ThirdPartySchema = Yup.object().shape({
|
||||||
|
sms: Yup.string('The ticker must be a string').required(
|
||||||
|
'The ticker is required'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const elements = [
|
||||||
|
{
|
||||||
|
name: 'sms',
|
||||||
|
size: 'sm',
|
||||||
|
view: getDisplayName('sms'),
|
||||||
|
width: 175,
|
||||||
|
input: Autocomplete,
|
||||||
|
inputProps: {
|
||||||
|
options: filterOptions('sms'),
|
||||||
|
valueProp: 'code',
|
||||||
|
labelProp: 'display'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EditableTable
|
||||||
|
name="thirdParty"
|
||||||
|
initialValues={data?.thirdParty ?? { sms: 'twilio' }}
|
||||||
|
data={R.of(data || [])}
|
||||||
|
error={error?.message}
|
||||||
|
enableEdit
|
||||||
|
editWidth={174}
|
||||||
|
save={innerSave}
|
||||||
|
validationSchema={ThirdPartySchema}
|
||||||
|
elements={elements}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ThirdPartyProvider
|
||||||
Loading…
Add table
Add a link
Reference in a new issue