fix(client): update store after any submission (#41329)
This commit is contained in:
@@ -15,7 +15,8 @@ import {
|
||||
editorValidator,
|
||||
localhostValidator,
|
||||
composeValidators,
|
||||
fCCValidator
|
||||
fCCValidator,
|
||||
httpValidator
|
||||
} from './FormValidators';
|
||||
|
||||
const propTypes = {
|
||||
@@ -39,7 +40,8 @@ function FormFields(props) {
|
||||
placeholders = {},
|
||||
required = [],
|
||||
types = {},
|
||||
isEditorLinkAllowed = false
|
||||
isEditorLinkAllowed = false,
|
||||
isLocalLinkAllowed = false
|
||||
} = options;
|
||||
|
||||
const nullOrWarning = (value, error, isURL, name) => {
|
||||
@@ -54,7 +56,8 @@ function FormFields(props) {
|
||||
const validationWarning = composeValidators(
|
||||
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
||||
fCCValidator,
|
||||
localhostValidator
|
||||
httpValidator,
|
||||
isLocalLinkAllowed ? null : localhostValidator
|
||||
)(value);
|
||||
const message = error || validationError || validationWarning;
|
||||
return message ? (
|
||||
|
@@ -5,6 +5,7 @@ import { Trans } from 'react-i18next';
|
||||
const editorRegex = /repl\.it\/(@|join\/)|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/;
|
||||
const fCCRegex = /codepen\.io\/freecodecamp|freecodecamp\.rocks|github\.com\/freecodecamp/i;
|
||||
const localhostRegex = /localhost:/;
|
||||
const httpRegex = /http(?!s|([^s]+?localhost))/;
|
||||
|
||||
export const editorValidator = value =>
|
||||
editorRegex.test(value) ? <Trans>validation.editor-url</Trans> : null;
|
||||
@@ -17,5 +18,8 @@ export const localhostValidator = value =>
|
||||
<Trans>validation.publicly-visible-url</Trans>
|
||||
) : null;
|
||||
|
||||
export const httpValidator = value =>
|
||||
httpRegex.test(value) ? <Trans>validation.http-url</Trans> : null;
|
||||
|
||||
export const composeValidators = (...validators) => value =>
|
||||
validators.reduce((error, validator) => error ?? validator?.(value), null);
|
||||
|
@@ -3,7 +3,8 @@ import {
|
||||
localhostValidator,
|
||||
editorValidator,
|
||||
composeValidators,
|
||||
fCCValidator
|
||||
fCCValidator,
|
||||
httpValidator
|
||||
} from './FormValidators';
|
||||
|
||||
export { default as BlockSaveButton } from './BlockSaveButton.js';
|
||||
@@ -16,13 +17,14 @@ const normalizeOptions = {
|
||||
};
|
||||
|
||||
export function formatUrlValues(values, options) {
|
||||
const { isEditorLinkAllowed, types } = options;
|
||||
const { isEditorLinkAllowed, isLocalLinkAllowed, types } = options;
|
||||
const validatedValues = { values: {}, errors: [], invalidValues: [] };
|
||||
const urlValues = Object.keys(values).reduce((result, key) => {
|
||||
let value = values[key];
|
||||
const nullOrWarning = composeValidators(
|
||||
fCCValidator,
|
||||
localhostValidator,
|
||||
httpValidator,
|
||||
isLocalLinkAllowed ? null : localhostValidator,
|
||||
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
|
||||
)(value);
|
||||
if (nullOrWarning) {
|
||||
|
Reference in New Issue
Block a user