fix(ui): Notification-related string/UI edits and field validation (#985)

This commit is contained in:
TheCatLady
2021-02-22 05:09:12 -05:00
committed by GitHub
parent 8589eabfff
commit c88fcb2e2d
11 changed files with 370 additions and 352 deletions

View File

@@ -40,16 +40,15 @@ const messages = defineMessages({
agentenabled: 'Enable Agent',
webhookUrl: 'Webhook URL',
authheader: 'Authorization Header',
validationJsonPayloadRequired: 'You must provide a JSON Payload',
webhookUrlPlaceholder: 'Remote webhook URL',
webhooksettingssaved: 'Webhook notification settings saved!',
validationJsonPayloadRequired: 'You must provide a valid JSON payload',
webhooksettingssaved: 'Webhook notification settings saved successfully!',
webhooksettingsfailed: 'Webhook notification settings failed to save.',
testsent: 'Test notification sent!',
test: 'Test',
notificationtypes: 'Notification Types',
resetPayload: 'Reset to Default JSON Payload',
resetPayloadSuccess: 'JSON reset to default payload.',
customJson: 'Custom JSON Payload',
resetPayload: 'Reset to Default',
resetPayloadSuccess: 'JSON payload reset successfully!',
customJson: 'JSON Payload',
templatevariablehelp: 'Template Variable Help',
validationWebhookUrl: 'You must provide a valid URL',
});
@@ -71,14 +70,18 @@ const NotificationsWebhook: React.FC = () => {
),
jsonPayload: Yup.string()
.required(intl.formatMessage(messages.validationJsonPayloadRequired))
.test('validate-json', 'Invalid JSON', (value) => {
try {
JSON.parse(value ?? '');
return true;
} catch (e) {
return false;
.test(
'validate-json',
intl.formatMessage(messages.validationJsonPayloadRequired),
(value) => {
try {
JSON.parse(value ?? '');
return true;
} catch (e) {
return false;
}
}
}),
),
});
if (!data && !error) {
@@ -173,14 +176,7 @@ const NotificationsWebhook: React.FC = () => {
</label>
<div className="form-input">
<div className="flex max-w-lg rounded-md shadow-sm">
<Field
id="webhookUrl"
name="webhookUrl"
type="text"
placeholder={intl.formatMessage(
messages.webhookUrlPlaceholder
)}
/>
<Field id="webhookUrl" name="webhookUrl" type="text" />
</div>
{errors.webhookUrl && touched.webhookUrl && (
<div className="error">{errors.webhookUrl}</div>