Merge pull request #1161 from ubavic/account_save_error
fix: account save error
This commit is contained in:
commit
a8048f320d
11 changed files with 38 additions and 30 deletions
|
|
@ -2,7 +2,7 @@ import { makeStyles, Grid } from '@material-ui/core'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import { Formik, Form, FastField } from 'formik'
|
import { Formik, Form, FastField } from 'formik'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
import ErrorMessage from 'src/components/ErrorMessage'
|
import ErrorMessage from 'src/components/ErrorMessage'
|
||||||
import { Button } from 'src/components/buttons'
|
import { Button } from 'src/components/buttons'
|
||||||
|
|
@ -48,6 +48,8 @@ const FormRenderer = ({
|
||||||
|
|
||||||
const values = R.merge(initialValues, value)
|
const values = R.merge(initialValues, value)
|
||||||
|
|
||||||
|
const [saveError, setSaveError] = useState([])
|
||||||
|
|
||||||
const saveNonEmptySecret = it => {
|
const saveNonEmptySecret = it => {
|
||||||
const emptySecretFields = R.compose(
|
const emptySecretFields = R.compose(
|
||||||
R.map(R.prop('code')),
|
R.map(R.prop('code')),
|
||||||
|
|
@ -57,7 +59,9 @@ const FormRenderer = ({
|
||||||
R.isEmpty(it[R.prop('code', elem)])
|
R.isEmpty(it[R.prop('code', elem)])
|
||||||
)
|
)
|
||||||
)(elements)
|
)(elements)
|
||||||
return save(R.omit(emptySecretFields, it))
|
return save(R.omit(emptySecretFields, it)).catch(s => {
|
||||||
|
setSaveError({ save: 'Failed to save changes' })
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -87,8 +91,10 @@ const FormRenderer = ({
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
<div className={classes.footer}>
|
<div className={classes.footer}>
|
||||||
{!R.isEmpty(errors) && (
|
{!R.isEmpty(R.mergeRight(errors, saveError)) && (
|
||||||
<ErrorMessage>{R.head(R.values(errors))}</ErrorMessage>
|
<ErrorMessage>
|
||||||
|
{R.head(R.values(R.mergeRight(errors, saveError)))}
|
||||||
|
</ErrorMessage>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
className={classnames(classes.button, buttonClass)}
|
className={classnames(classes.button, buttonClass)}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default {
|
||||||
.required('The API key is required'),
|
.required('The API key is required'),
|
||||||
privateKey: Yup.string('The private key must be a string')
|
privateKey: Yup.string('The private key must be a string')
|
||||||
.max(100, 'The private key is too long')
|
.max(100, 'The private key is too long')
|
||||||
.test(secretTest(account?.privateKey))
|
.test(secretTest(account?.privateKey, 'private key'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,12 @@ export default {
|
||||||
clientId: Yup.string('The client ID must be a string')
|
clientId: Yup.string('The client ID must be a string')
|
||||||
.max(100, 'The client ID is too long')
|
.max(100, 'The client ID is too long')
|
||||||
.required('The client ID is required'),
|
.required('The client ID is required'),
|
||||||
key: Yup.string('The key must be a string')
|
key: Yup.string('The API key must be a string')
|
||||||
.max(100, 'The key is too long')
|
.max(100, 'The API key is too long')
|
||||||
.required('The key is required'),
|
.required('The API key is required'),
|
||||||
secret: Yup.string('The secret must be a string')
|
secret: Yup.string('The API secret must be a string')
|
||||||
.max(100, 'The secret is too long')
|
.max(100, 'The API secret is too long')
|
||||||
.test(secretTest(account?.secret))
|
.test(secretTest(account?.secret, 'API secret'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default {
|
||||||
.required('The API key is required'),
|
.required('The API key is required'),
|
||||||
privateKey: Yup.string('The private key must be a string')
|
privateKey: Yup.string('The private key must be a string')
|
||||||
.max(100, 'The private key is too long')
|
.max(100, 'The private key is too long')
|
||||||
.test(secretTest(account?.privateKey))
|
.test(secretTest(account?.privateKey, 'private key'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export default {
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
authorizationValue: Yup.string('The authorization value must be a string')
|
authorizationValue: Yup.string('The authorization value must be a string')
|
||||||
.max(100, 'Too long')
|
.max(100, 'Too long')
|
||||||
.test(secretTest(account?.authorizationValue)),
|
.test(secretTest(account?.authorizationValue, 'authorization value')),
|
||||||
scoreThreshold: Yup.number('The score threshold must be a number')
|
scoreThreshold: Yup.number('The score threshold must be a number')
|
||||||
.required('A score threshold is required')
|
.required('A score threshold is required')
|
||||||
.min(1, 'The score threshold must be between 1 and 10')
|
.min(1, 'The score threshold must be between 1 and 10')
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default {
|
||||||
.required('The API key is required'),
|
.required('The API key is required'),
|
||||||
privateKey: Yup.string('The private key must be a string')
|
privateKey: Yup.string('The private key must be a string')
|
||||||
.max(100, 'The private key is too long')
|
.max(100, 'The private key is too long')
|
||||||
.test(secretTest(account?.privateKey))
|
.test(secretTest(account?.privateKey, 'private key'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
|
|
||||||
const secretTest = secret => ({
|
const secretTest = (secret, message) => ({
|
||||||
|
name: 'secret-test',
|
||||||
|
message: message ? `The ${message} is invalid` : 'Invalid field',
|
||||||
test(val) {
|
test(val) {
|
||||||
if (R.isNil(secret) && R.isNil(val)) {
|
if (R.isNil(secret) && R.isNil(val)) {
|
||||||
return this.createError()
|
return this.createError()
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@ export default {
|
||||||
],
|
],
|
||||||
getValidationSchema: account => {
|
getValidationSchema: account => {
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
apiKey: Yup.string('The API key must be a string')
|
apiKey: Yup.string('The project ID must be a string')
|
||||||
.max(100, 'The API key is too long')
|
.max(100, 'The project ID is too long')
|
||||||
.required('The API key is required'),
|
.required('The project ID is required'),
|
||||||
apiSecret: Yup.string('The API secret must be a string')
|
apiSecret: Yup.string('The project secret must be a string')
|
||||||
.max(100, 'The API secret is too long')
|
.max(100, 'The project secret is too long')
|
||||||
.test(secretTest(account?.apiSecret)),
|
.test(secretTest(account?.apiSecret, 'project secret')),
|
||||||
endpoint: Yup.string('The endpoint must be a string')
|
endpoint: Yup.string('The endpoint must be a string')
|
||||||
.max(100, 'The endpoint is too long')
|
.max(100, 'The endpoint is too long')
|
||||||
.required('The endpoint is required')
|
.required('The endpoint is required')
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export default {
|
||||||
.required('The client key is required'),
|
.required('The client key is required'),
|
||||||
clientSecret: Yup.string('The client secret must be a string')
|
clientSecret: Yup.string('The client secret must be a string')
|
||||||
.max(100, 'The client secret is too long')
|
.max(100, 'The client secret is too long')
|
||||||
.test(secretTest(account?.clientSecret))
|
.test(secretTest(account?.clientSecret, 'client secret'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default {
|
||||||
.required('The API key is required'),
|
.required('The API key is required'),
|
||||||
privateKey: Yup.string('The private key must be a string')
|
privateKey: Yup.string('The private key must be a string')
|
||||||
.max(100, 'The private key is too long')
|
.max(100, 'The private key is too long')
|
||||||
.test(secretTest(account?.privateKey))
|
.test(secretTest(account?.privateKey, 'private key'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ export default {
|
||||||
.required('The account SID is required'),
|
.required('The account SID is required'),
|
||||||
authToken: Yup.string('The auth token must be a string')
|
authToken: Yup.string('The auth token must be a string')
|
||||||
.max(100, 'The auth token is too long')
|
.max(100, 'The auth token is too long')
|
||||||
.test(secretTest(account?.authToken)),
|
.test(secretTest(account?.authToken, 'auth token')),
|
||||||
fromNumber: Yup.string('The from number must be a string')
|
fromNumber: Yup.string('The Twilio number must be a string')
|
||||||
.max(100, 'The from number is too long')
|
.max(100, 'The Twilio number is too long')
|
||||||
.required('The from number is required'),
|
.required('The Twilio number is required'),
|
||||||
toNumber: Yup.string('The to number must be a string')
|
toNumber: Yup.string('The notifications number must be a string')
|
||||||
.max(100, 'The to number is too long')
|
.max(100, 'The notifications number is too long')
|
||||||
.required('The to number is required')
|
.required('The notifications number is required')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue