Merge pull request #1161 from ubavic/account_save_error

fix: account save error
This commit is contained in:
Rafael Taranto 2022-03-14 23:06:11 +00:00 committed by GitHub
commit a8048f320d
11 changed files with 38 additions and 30 deletions

View file

@ -2,7 +2,7 @@ import { makeStyles, Grid } from '@material-ui/core'
import classnames from 'classnames'
import { Formik, Form, FastField } from 'formik'
import * as R from 'ramda'
import React from 'react'
import React, { useState } from 'react'
import ErrorMessage from 'src/components/ErrorMessage'
import { Button } from 'src/components/buttons'
@ -48,6 +48,8 @@ const FormRenderer = ({
const values = R.merge(initialValues, value)
const [saveError, setSaveError] = useState([])
const saveNonEmptySecret = it => {
const emptySecretFields = R.compose(
R.map(R.prop('code')),
@ -57,7 +59,9 @@ const FormRenderer = ({
R.isEmpty(it[R.prop('code', elem)])
)
)(elements)
return save(R.omit(emptySecretFields, it))
return save(R.omit(emptySecretFields, it)).catch(s => {
setSaveError({ save: 'Failed to save changes' })
})
}
return (
@ -87,8 +91,10 @@ const FormRenderer = ({
)}
</Grid>
<div className={classes.footer}>
{!R.isEmpty(errors) && (
<ErrorMessage>{R.head(R.values(errors))}</ErrorMessage>
{!R.isEmpty(R.mergeRight(errors, saveError)) && (
<ErrorMessage>
{R.head(R.values(R.mergeRight(errors, saveError)))}
</ErrorMessage>
)}
<Button
className={classnames(classes.button, buttonClass)}

View file

@ -30,7 +30,7 @@ export default {
.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))
.test(secretTest(account?.privateKey, 'private key'))
})
}
}

View file

@ -35,12 +35,12 @@ export default {
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))
key: Yup.string('The API key must be a string')
.max(100, 'The API key is too long')
.required('The API key is required'),
secret: Yup.string('The API secret must be a string')
.max(100, 'The API secret is too long')
.test(secretTest(account?.secret, 'API secret'))
})
}
}

View file

@ -30,7 +30,7 @@ export default {
.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))
.test(secretTest(account?.privateKey, 'private key'))
})
}
}

View file

@ -39,7 +39,7 @@ export default {
return Yup.object().shape({
authorizationValue: Yup.string('The authorization value must be a string')
.max(100, 'Too long')
.test(secretTest(account?.authorizationValue)),
.test(secretTest(account?.authorizationValue, 'authorization value')),
scoreThreshold: Yup.number('The score threshold must be a number')
.required('A score threshold is required')
.min(1, 'The score threshold must be between 1 and 10')

View file

@ -30,7 +30,7 @@ export default {
.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))
.test(secretTest(account?.privateKey, 'private key'))
})
}
}

View file

@ -1,6 +1,8 @@
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) {
if (R.isNil(secret) && R.isNil(val)) {
return this.createError()

View file

@ -31,12 +31,12 @@ export default {
],
getValidationSchema: account => {
return Yup.object().shape({
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)),
apiKey: Yup.string('The project ID must be a string')
.max(100, 'The project ID is too long')
.required('The project ID is required'),
apiSecret: Yup.string('The project secret must be a string')
.max(100, 'The project secret is too long')
.test(secretTest(account?.apiSecret, 'project secret')),
endpoint: Yup.string('The endpoint must be a string')
.max(100, 'The endpoint is too long')
.required('The endpoint is required')

View file

@ -48,7 +48,7 @@ export default {
.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))
.test(secretTest(account?.clientSecret, 'client secret'))
})
}
}

View file

@ -30,7 +30,7 @@ export default {
.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))
.test(secretTest(account?.privateKey, 'private key'))
})
}
}

View file

@ -40,13 +40,13 @@ export default {
.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('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')
.test(secretTest(account?.authToken, 'auth token')),
fromNumber: Yup.string('The Twilio number must be a string')
.max(100, 'The Twilio number is too long')
.required('The Twilio number is required'),
toNumber: Yup.string('The notifications number must be a string')
.max(100, 'The notifications number is too long')
.required('The notifications number is required')
})
}
}