feat: add error messages to all 3rd party services
This commit is contained in:
parent
4015e23d34
commit
bb17c71cb1
15 changed files with 160 additions and 127 deletions
|
|
@ -4,12 +4,19 @@ import { Formik, Form, FastField } from 'formik'
|
|||
import * as R from 'ramda'
|
||||
import React from 'react'
|
||||
|
||||
import ErrorMessage from 'src/components/ErrorMessage'
|
||||
import { Button } from 'src/components/buttons'
|
||||
import { SecretInput } from 'src/components/inputs/formik'
|
||||
import { spacer } from 'src/styling/variables'
|
||||
|
||||
const styles = {
|
||||
footer: {
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
margin: [['auto', 0, spacer * 4, 0]]
|
||||
},
|
||||
button: {
|
||||
margin: [['auto', 0, 32, 'auto']]
|
||||
margin: [['auto', 0, 0, 'auto']]
|
||||
},
|
||||
form: {
|
||||
flex: 1,
|
||||
|
|
@ -61,6 +68,7 @@ const FormRenderer = ({
|
|||
initialValues={values}
|
||||
validationSchema={validationSchema}
|
||||
onSubmit={saveNonEmptySecret}>
|
||||
{({ errors }) => (
|
||||
<Form className={classes.form}>
|
||||
<Grid container spacing={3} className={classes.grid}>
|
||||
{elements.map(
|
||||
|
|
@ -78,12 +86,18 @@ const FormRenderer = ({
|
|||
)
|
||||
)}
|
||||
</Grid>
|
||||
<div className={classes.footer}>
|
||||
{!R.isEmpty(errors) && (
|
||||
<ErrorMessage>{R.head(R.values(errors))}</ErrorMessage>
|
||||
)}
|
||||
<Button
|
||||
className={classnames(classes.button, buttonClass)}
|
||||
type="submit">
|
||||
{buttonLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ const Services = () => {
|
|||
{editingSchema && (
|
||||
<Modal
|
||||
title={`Edit ${editingSchema.name}`}
|
||||
width={478}
|
||||
width={525}
|
||||
handleClose={() => setEditingSchema(null)}
|
||||
open={true}>
|
||||
<FormRenderer
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
privateKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
privateKey: Yup.string('The private key must be a string')
|
||||
.max(100, 'The private key is too long')
|
||||
.test(secretTest(account?.privateKey))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,37 +98,52 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
token: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
BTCWalletId: Yup.string().max(100, 'Too long'),
|
||||
token: Yup.string('The token must be a string')
|
||||
.max(100, 'The token is too long')
|
||||
.required('The token is required'),
|
||||
BTCWalletId: Yup.string('The BTC wallet ID must be a string').max(
|
||||
100,
|
||||
'The BTC wallet ID is too long'
|
||||
),
|
||||
BTCWalletPassphrase: buildTestValidation(
|
||||
'BTCWalletId',
|
||||
account?.BTCWalletPassphrase
|
||||
),
|
||||
LTCWalletId: Yup.string().max(100, 'Too long'),
|
||||
LTCWalletId: Yup.string('The LTC wallet ID must be a string').max(
|
||||
100,
|
||||
'The LTC wallet ID is too long'
|
||||
),
|
||||
LTCWalletPassphrase: buildTestValidation(
|
||||
'LTCWalletId',
|
||||
account?.LTCWalletPassphrase
|
||||
),
|
||||
ZECWalletId: Yup.string().max(100, 'Too long'),
|
||||
ZECWalletId: Yup.string('The ZEC wallet ID must be a string').max(
|
||||
100,
|
||||
'The ZEC wallet ID is too long'
|
||||
),
|
||||
ZECWalletPassphrase: buildTestValidation(
|
||||
'ZECWalletId',
|
||||
account?.ZECWalletPassphrase
|
||||
),
|
||||
BCHWalletId: Yup.string().max(100, 'Too long'),
|
||||
BCHWalletId: Yup.string('The BCH wallet ID must be a string').max(
|
||||
100,
|
||||
'The BCH wallet ID is too long'
|
||||
),
|
||||
BCHWalletPassphrase: buildTestValidation(
|
||||
'BCHWalletId',
|
||||
account?.BCHWalletPassphrase
|
||||
),
|
||||
DASHWalletId: Yup.string().max(100, 'Too long'),
|
||||
DASHWalletId: Yup.string('The DASH wallet ID must be a string').max(
|
||||
100,
|
||||
'The DASH wallet ID is too long'
|
||||
),
|
||||
DASHWalletPassphrase: buildTestValidation(
|
||||
'DASHWalletId',
|
||||
account?.DASHWalletPassphrase
|
||||
),
|
||||
environment: Yup.string()
|
||||
environment: Yup.string('The environment must be a string')
|
||||
.matches(/(prod|test)/)
|
||||
.required()
|
||||
.required('The environment is required')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
clientId: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
key: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
secret: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
clientId: Yup.string('The client ID must be a string')
|
||||
.max(100, 'The client ID is too long')
|
||||
.required('The client ID is required'),
|
||||
key: Yup.string('The key must be a string')
|
||||
.max(100, 'The key is too long')
|
||||
.required('The key is required'),
|
||||
secret: Yup.string('The secret must be a string')
|
||||
.max(100, 'The secret is too long')
|
||||
.test(secretTest(account?.secret))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ export default {
|
|||
],
|
||||
getValidationSchema: () => {
|
||||
return Yup.object().shape({
|
||||
token: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
confidenceFactor: Yup.number()
|
||||
.integer('Please input a positive integer')
|
||||
.positive('Please input a positive integer')
|
||||
.required()
|
||||
token: Yup.string('The token must be a string')
|
||||
.max(100, 'The token is too long')
|
||||
.required('The token is required'),
|
||||
confidenceFactor: Yup.number('The confidence factor must be a number')
|
||||
.integer('The confidence factor must be an integer')
|
||||
.positive('The confidence factor must be positive')
|
||||
.required('The confidence factor is required')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
privateKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
privateKey: Yup.string('The private key must be a string')
|
||||
.max(100, 'The private key is too long')
|
||||
.test(secretTest(account?.privateKey))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,10 +37,12 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
authorizationValue: Yup.string()
|
||||
authorizationValue: Yup.string('The score threshold must be a string')
|
||||
.required('The authorization value is required')
|
||||
.max(100, 'Too long')
|
||||
.test(secretTest(account?.authorizationValue)),
|
||||
scoreThreshold: Yup.number()
|
||||
scoreThreshold: Yup.number('The score threshold must be a number')
|
||||
.required('A score threshold is required')
|
||||
.min(1, 'The number should be between 1 and 10')
|
||||
.max(10, 'The number should be between 1 and 10')
|
||||
.test(secretTest(account?.scoreThreshold))
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
privateKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
privateKey: Yup.string('The private key must be a string')
|
||||
.max(100, 'The private key is too long')
|
||||
.test(secretTest(account?.privateKey))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
apiSecret: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
apiSecret: Yup.string('The API secret must be a string')
|
||||
.max(100, 'The API secret is too long')
|
||||
.test(secretTest(account?.apiSecret)),
|
||||
endpoint: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required()
|
||||
endpoint: Yup.string('The endpoint must be a string')
|
||||
.max(100, 'The endpoint is too long')
|
||||
.required('The endpoint is required')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,17 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
userId: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
walletId: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
clientKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
clientSecret: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
userId: Yup.string('The user ID must be a string')
|
||||
.max(100, 'The user ID is too long')
|
||||
.required('The user ID is required'),
|
||||
walletId: Yup.string('The wallet ID must be a string')
|
||||
.max(100, 'The wallet ID is too long')
|
||||
.required('The wallet ID is required'),
|
||||
clientKey: Yup.string('The client key must be a string')
|
||||
.max(100, 'The client key is too long')
|
||||
.required('The client key is required'),
|
||||
clientSecret: Yup.string('The client secret must be a string')
|
||||
.max(100, 'The client secret is too long')
|
||||
.test(secretTest(account?.clientSecret))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
privateKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
privateKey: Yup.string('The private key must be a string')
|
||||
.max(100, 'The private key is too long')
|
||||
.test(secretTest(account?.privateKey))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,20 +32,20 @@ export default {
|
|||
],
|
||||
getValidationSchema: () => {
|
||||
return Yup.object().shape({
|
||||
apiKey: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
domain: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
fromEmail: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.email('Please input a valid email address')
|
||||
.required(),
|
||||
toEmail: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.email('Please input a valid email address')
|
||||
.required()
|
||||
apiKey: Yup.string('The API key must be a string')
|
||||
.max(100, 'The API key is too long')
|
||||
.required('The API key is required'),
|
||||
domain: Yup.string('The domain must be a string')
|
||||
.max(100, 'The domain is too long')
|
||||
.required('The domain is required'),
|
||||
fromEmail: Yup.string('The from email must be a string')
|
||||
.max(100, 'The from email is too long')
|
||||
.email('The from email must be a valid email address')
|
||||
.required('The from email is required'),
|
||||
toEmail: Yup.string('The to email must be a string')
|
||||
.max(100, 'The to email is too long')
|
||||
.email('The to email must be a valid email address')
|
||||
.required('The to email is required')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,18 +44,20 @@ const singleBitgo = code => ({
|
|||
}
|
||||
],
|
||||
validationSchema: Yup.object().shape({
|
||||
token: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
environment: Yup.string()
|
||||
token: Yup.string('The token must be a string')
|
||||
.max(100, 'The token is too long')
|
||||
.required('The token is required'),
|
||||
environment: Yup.string('The environment must be a string')
|
||||
.matches(/(prod|test)/)
|
||||
.required(),
|
||||
[`${code}WalletId`]: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
[`${code}WalletPassphrase`]: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required()
|
||||
.required('The environment is required'),
|
||||
[`${code}WalletId`]: Yup.string(`The ${code} wallet ID must be a string`)
|
||||
.max(100, `The ${code} wallet ID is too long`)
|
||||
.required(`The ${code} wallet ID is required`),
|
||||
[`${code}WalletPassphrase`]: Yup.string(
|
||||
`The ${code} passphrase must be a string`
|
||||
)
|
||||
.max(100, `The ${code} wallet passphrase is too long`)
|
||||
.required(`The ${code} wallet passphrase is required`)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -35,18 +35,18 @@ export default {
|
|||
],
|
||||
getValidationSchema: account => {
|
||||
return Yup.object().shape({
|
||||
accountSid: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
authToken: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
accountSid: Yup.string('The account SID must be a string')
|
||||
.max(100, 'The account SID is too long')
|
||||
.required('The account SID is required'),
|
||||
authToken: Yup.string('The auth token must be a string')
|
||||
.max(100, 'The auth token is too long')
|
||||
.test(secretTest(account?.authToken)),
|
||||
fromNumber: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required(),
|
||||
toNumber: Yup.string()
|
||||
.max(100, 'Too long')
|
||||
.required()
|
||||
fromNumber: Yup.string('The from number must be a string')
|
||||
.max(100, 'The from number is too long')
|
||||
.required('The from number is required'),
|
||||
toNumber: Yup.string('The to number must be a string')
|
||||
.max(100, 'The to number is too long')
|
||||
.required('The to number is required')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue