From cba18edc95dc7874a74a74d118199c2e22b1e8c3 Mon Sep 17 00:00:00 2001
From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com>
Date: Mon, 7 Mar 2022 23:42:29 +0100
Subject: [PATCH] feat: twilio setup in notifications
---
.../src/pages/Notifications/Notifications.js | 48 ++++++++++++-
.../src/pages/Notifications/sections/Setup.js | 72 +++++++++++++++----
2 files changed, 107 insertions(+), 13 deletions(-)
diff --git a/new-lamassu-admin/src/pages/Notifications/Notifications.js b/new-lamassu-admin/src/pages/Notifications/Notifications.js
index df3dfbcc..b1def515 100644
--- a/new-lamassu-admin/src/pages/Notifications/Notifications.js
+++ b/new-lamassu-admin/src/pages/Notifications/Notifications.js
@@ -3,7 +3,11 @@ import gql from 'graphql-tag'
import * as R from 'ramda'
import React, { useState } from 'react'
+import Modal from 'src/components/Modal'
import TitleSection from 'src/components/layout/TitleSection'
+import { P } from 'src/components/typography'
+import FormRenderer from 'src/pages/Services/FormRenderer'
+import twilioSchema from 'src/pages/Services/schemas/twilio'
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
import Section from '../../components/layout/Section'
@@ -28,6 +32,7 @@ const GET_INFO = gql`
code
display
}
+ accounts
}
`
@@ -37,6 +42,12 @@ const SAVE_CONFIG = gql`
}
`
+const SAVE_ACCOUNT = gql`
+ mutation Save($accounts: JSONObject) {
+ saveAccounts(accounts: $accounts)
+ }
+`
+
const FIELDS_WIDTH = 130
const Notifications = ({
@@ -52,6 +63,7 @@ const Notifications = ({
const [section, setSection] = useState(null)
const [error, setError] = useState(null)
const [editingKey, setEditingKey] = useState(null)
+ const [smsSetupPopup, setSmsSetupPopup] = useState(false)
const { data, loading } = useQuery(GET_INFO)
@@ -61,9 +73,16 @@ const Notifications = ({
onError: error => setError(error)
})
+ const [saveAccount] = useMutation(SAVE_ACCOUNT, {
+ onCompleted: () => setSmsSetupPopup(false),
+ refetchQueries: ['getData'],
+ onError: error => setError(error)
+ })
+
const config = fromNamespace(SCREEN_KEY)(data?.config)
const machines = data?.machines
const cryptoCurrencies = data?.cryptoCurrencies
+ const twilioAvailable = R.has('twilio', data?.accounts || {})
const currency = R.path(['fiatCurrency'])(
fromNamespace(namespaces.LOCALE)(data?.config)
@@ -83,6 +102,14 @@ const Notifications = ({
setEditingKey(state ? key : null)
}
+ const twilioSave = it => {
+ setError(null)
+ R.compose(save(null), toNamespace('sms'))({ active: true })
+ return saveAccount({
+ variables: { accounts: { twilio: it } }
+ })
+ }
+
const isEditing = key => editingKey === key
const isDisabled = key => editingKey && editingKey !== key
@@ -97,7 +124,9 @@ const Notifications = ({
setEditing,
setSection,
machines,
- cryptoCurrencies
+ cryptoCurrencies,
+ twilioAvailable,
+ setSmsSetupPopup
}
return (
@@ -140,6 +169,23 @@ const Notifications = ({
)}
)}
+ {smsSetupPopup && (
+
+ In order for the SMS notifications to work, you'll first need to
+ configure Twilio.
+