160 lines
3.9 KiB
JavaScript
160 lines
3.9 KiB
JavaScript
import { useMutation, useQuery, gql } from '@apollo/client'
|
||
import { makeStyles } from '@mui/styles'
|
||
import classnames from 'classnames'
|
||
import React, { useState } from 'react'
|
||
import { HelpTooltip } from 'src/components/Tooltip'
|
||
import { H1, H4, Label1, P } from 'src/components/typography'
|
||
import FormRenderer from 'src/pages/Services/FormRenderer'
|
||
import WarningIcon from 'src/styling/icons/warning-icon/comet.svg?react'
|
||
|
||
import { Button, SupportLinkButton } from 'src/components/buttons'
|
||
import { RadioGroup } from 'src/components/inputs'
|
||
import twilio from 'src/pages/Services/schemas/twilio'
|
||
|
||
import styles from './Wallet/Shared.styles'
|
||
|
||
const GET_CONFIG = gql`
|
||
{
|
||
config
|
||
accounts
|
||
}
|
||
`
|
||
|
||
const SAVE_ACCOUNTS = gql`
|
||
mutation Save($accounts: JSONObject) {
|
||
saveAccounts(accounts: $accounts)
|
||
}
|
||
`
|
||
|
||
const useStyles = makeStyles({
|
||
...styles,
|
||
content: {
|
||
width: 820
|
||
},
|
||
radioLabel: {
|
||
...styles.radioLabel,
|
||
width: 280
|
||
},
|
||
wrapper: {
|
||
width: 1200,
|
||
height: 100,
|
||
margin: [[0, 'auto']]
|
||
},
|
||
title: {
|
||
marginLeft: 8,
|
||
marginBottom: 5
|
||
},
|
||
info: {
|
||
marginTop: 20,
|
||
marginBottom: 20
|
||
}
|
||
})
|
||
|
||
const options = [
|
||
{
|
||
code: 'enable',
|
||
display: 'Yes, I will'
|
||
},
|
||
{
|
||
code: 'disable',
|
||
display: 'No, not for now'
|
||
}
|
||
]
|
||
|
||
function Twilio({ doContinue }) {
|
||
const classes = useStyles()
|
||
const [selected, setSelected] = useState(null)
|
||
const [error, setError] = useState(false)
|
||
|
||
const { data, refetch } = useQuery(GET_CONFIG)
|
||
const [saveAccounts] = useMutation(SAVE_ACCOUNTS, {
|
||
onCompleted: doContinue
|
||
})
|
||
|
||
const accounts = data?.accounts ?? []
|
||
|
||
const onSelect = e => {
|
||
setSelected(e.target.value)
|
||
setError(false)
|
||
}
|
||
|
||
const clickContinue = () => {
|
||
if (!selected) return setError(true)
|
||
doContinue()
|
||
}
|
||
|
||
const save = twilio => {
|
||
const accounts = { twilio }
|
||
return saveAccounts({ variables: { accounts } }).then(() => refetch())
|
||
}
|
||
|
||
const titleClasses = {
|
||
[classes.title]: true,
|
||
[classes.error]: error
|
||
}
|
||
|
||
return (
|
||
<div className={classes.wrapper}>
|
||
<div className={classes.content}>
|
||
<H1>Twilio (SMS service)</H1>
|
||
<div className="flex items-end">
|
||
<H4 noMargin className={classnames(titleClasses)}>
|
||
Will you setup a two way machine or compliance?
|
||
</H4>
|
||
<HelpTooltip width={304}>
|
||
<P>
|
||
Two-way machines allow your customers not only to buy (cash-in)
|
||
but also sell cryptocurrencies (cash-out).
|
||
</P>
|
||
<P>
|
||
You’ll need an SMS service for cash-out transactions and for any
|
||
compliance triggers
|
||
</P>
|
||
</HelpTooltip>
|
||
</div>
|
||
|
||
<RadioGroup
|
||
labelClassName={classes.radioLabel}
|
||
className={classes.radioGroup}
|
||
options={options}
|
||
value={selected}
|
||
onChange={onSelect}
|
||
/>
|
||
|
||
<div className="flex gap-4 mt-5 mb-8 items-center">
|
||
<WarningIcon />
|
||
<Label1 noMargin>
|
||
To set up Twilio please read the instructions from our support
|
||
portal.
|
||
</Label1>
|
||
</div>
|
||
<SupportLinkButton
|
||
link="https://support.lamassu.is/hc/en-us/articles/115001203951-Twilio-for-SMS"
|
||
label="Twilio for SMS"
|
||
/>
|
||
|
||
{selected === 'enable' && (
|
||
<>
|
||
<H4 noMargin>Enter credentials</H4>
|
||
<FormRenderer
|
||
xs={6}
|
||
save={save}
|
||
value={accounts.twilio}
|
||
elements={twilio.elements}
|
||
validationSchema={twilio.getValidationSchema(accounts.twilio)}
|
||
buttonLabel={'Continue'}
|
||
buttonClass={classes.formButton}
|
||
/>
|
||
</>
|
||
)}
|
||
{selected !== 'enable' && (
|
||
<Button size="lg" onClick={clickContinue} className={classes.button}>
|
||
Continue
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export default Twilio
|