Remove moment from validation schema

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-09-24 15:21:34 +02:00
parent b37da48380
commit 2585780a79
7 changed files with 113 additions and 146 deletions

View File

@ -56,7 +56,9 @@
"i18n": {
"localized": true
}
}
},
"repeatable": false,
"required": true
},
"contactEmail": {
"type": "email",

View File

@ -11,91 +11,41 @@
"options": {
"draftAndPublish": false
},
"pluginOptions": {
"i18n": {
"localized": true
}
},
"pluginOptions": {},
"attributes": {
"name": {
"type": "string",
"pluginOptions": {
"i18n": {
"localized": true
}
}
"pluginOptions": {}
},
"temp": {
"type": "component",
"repeatable": true,
"component": "default.temp",
"pluginOptions": {
"i18n": {
"localized": true
}
}
"simple": {
"pluginOptions": {},
"type": "uid"
},
"dz": {
"pluginOptions": {
"i18n": {
"localized": true
}
},
"type": "dynamiczone",
"components": [
"basic.simple",
"blog.test-como",
"default.closingperiod",
"default.dish",
"default.openingtimes",
"default.restaurantservice",
"default.temp",
"default.apple",
"default.car"
],
"required": true,
"min": 2
"attached": {
"pluginOptions": {},
"type": "uid",
"targetField": "name"
},
"dz_req": {
"type": "dynamiczone",
"components": [
"default.apple",
"default.car",
"default.closingperiod",
"default.dish",
"default.openingtimes",
"default.restaurantservice",
"default.temp"
],
"required": true,
"pluginOptions": {
"i18n": {
"localized": true
}
}
"attached_req": {
"pluginOptions": {},
"type": "uid",
"targetField": "name",
"required": true
},
"dz_simple": {
"type": "dynamiczone",
"components": [
"basic.simple"
],
"pluginOptions": {
"i18n": {
"localized": true
}
}
"req": {
"pluginOptions": {},
"type": "uid",
"required": true
},
"dz_max": {
"type": "dynamiczone",
"components": [
"basic.simple"
],
"max": 2,
"pluginOptions": {
"i18n": {
"localized": true
}
}
"default_val": {
"pluginOptions": {},
"type": "uid",
"default": "to",
"minLength": 4
},
"date": {
"type": "date",
"required": true
}
}
}

View File

@ -7,7 +7,8 @@
},
"attributes": {
"label": {
"type": "string"
"type": "string",
"default": "toto"
},
"start_date": {
"type": "date",
@ -19,11 +20,15 @@
},
"media": {
"type": "media",
"multiple": false,
"required": false
},
"dish": {
"component": "default.dish",
"type": "component"
"type": "component",
"repeatable": true,
"required": true,
"min": 2
}
}
}

View File

@ -36,6 +36,7 @@ const cleanData = (retrievedData, currentSchema, componentsSchema) => {
case 'time': {
cleanedData = value;
// FIXME
if (value && value.split(':').length < 3) {
cleanedData = `${value}:00`;
}

View File

@ -9,7 +9,7 @@ import {
isNaN,
toNumber,
} from 'lodash';
import moment from 'moment';
import * as yup from 'yup';
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
@ -291,10 +291,6 @@ const createYupSchemaAttribute = (type, validations, options) => {
return !!value;
}
if (['date', 'datetime'].includes(type)) {
return moment(value)._isValid === true;
}
if (type === 'boolean') {
return value !== null;
}

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState, useRef } from 'react';
import React, { useEffect, useState, useRef, memo } from 'react';
import PropTypes from 'prop-types';
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
@ -7,42 +7,49 @@ import { axiosInstance } from '../../../core/utils';
import { getRequestUrl, getTrad } from '../../utils';
import UID_REGEX from './regex';
import { TextInput } from '@strapi/parts/TextInput';
import { Text } from '@strapi/parts/Text';
import { Text } from '@strapi/parts/Text';
import Reload from '@strapi/icons/Reload';
import AlertSucessIcon from '@strapi/icons/AlertSucessIcon';
import AlertWarningIcon from '@strapi/icons/AlertWarningIcon';
import LoadingIcon from '@strapi/icons/LoadingIcon';
import useDebounce from './useDebounce';
import { EndActionWrapper, FieldActionWrapper, TextValidation, LoadingWrapper } from './endActionStyle';
import {
EndActionWrapper,
FieldActionWrapper,
TextValidation,
LoadingWrapper,
} from './endActionStyle';
// {
// attribute,
// contentTypeUID,
// description,
// error: inputError,
// label: inputLabel,
// labelIcon,
// name,
// onChange,
// validations,
// value,
// editable,
// ...inputProps
// attribute,
// contentTypeUID,
// description,
// error: inputError,
// label: inputLabel,
// labelIcon,
// name,
// onChange,
// validations,
// value,
// editable,
// ...inputProps
// }
const InputUID = ({
attribute,
contentTypeUID,
description,
disabled,
error,
intlLabel,
labelAction,
name,
onChange,
value,
...rest
}) => {
const InputUID = props => {
const {
attribute,
contentTypeUID,
description,
disabled,
error,
intlLabel,
labelAction,
name,
onChange,
value,
...rest
} = props;
const { modifiedData, initialData, layout } = useCMEditViewDataManager();
const [isLoading, setIsLoading] = useState(false);
const [availability, setAvailability] = useState(null);
@ -57,11 +64,11 @@ const InputUID = ({
const [regenerateLabel, setRegenerateLabel] = useState(null);
const label = intlLabel.id
? formatMessage(
{ id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
{ ...intlLabel.values }
)
: name;
? formatMessage(
{ id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
{ ...intlLabel.values }
)
: name;
generateUid.current = async (shouldSetInitialValue = false) => {
setIsLoading(true);
@ -172,36 +179,42 @@ const InputUID = ({
onChange(e);
};
return (
<TextInput
label={label}
name={name}
<TextInput
label={label}
name={name}
onChange={handleChange}
value={value || ''}
disabled={disabled}
endAction={
<EndActionWrapper>
{availability && availability.isAvailable && !regenerateLabel &&
<TextValidation alignItems='center' justifyContent='flex-end'>
{availability && availability.isAvailable && !regenerateLabel && (
<TextValidation alignItems="center" justifyContent="flex-end">
<AlertSucessIcon />
<Text textColor='success600' small>Available</Text>
</TextValidation>
}
{availability && !availability.isAvailable && !regenerateLabel &&
<TextValidation notAvailable alignItems='center' justifyContent='flex-end'>
<Text textColor="success600" small>
Available
</Text>
</TextValidation>
)}
{availability && !availability.isAvailable && !regenerateLabel && (
<TextValidation notAvailable alignItems="center" justifyContent="flex-end">
<AlertWarningIcon />
<Text textColor='danger600' small>Unavailable</Text>
</TextValidation>
}
{regenerateLabel &&
<TextValidation alignItems='center' justifyContent='flex-end'>
<Text textColor='primary600' small>{regenerateLabel}</Text>
</TextValidation>
}
<FieldActionWrapper
onClick={() => generateUid.current()}
label='regenerate'
<Text textColor="danger600" small>
Unavailable
</Text>
</TextValidation>
)}
{regenerateLabel && (
<TextValidation alignItems="center" justifyContent="flex-end">
<Text textColor="primary600" small>
{regenerateLabel}
</Text>
</TextValidation>
)}
<FieldActionWrapper
onClick={() => generateUid.current()}
label="regenerate"
onMouseEnter={handleGenerateMouseEnter}
onMouseLeave={handleGenerateMouseLeave}
>
@ -209,9 +222,9 @@ const InputUID = ({
<LoadingWrapper>
<LoadingIcon />
</LoadingWrapper>
) :
) : (
<Reload />
}
)}
</FieldActionWrapper>
</EndActionWrapper>
}
@ -323,4 +336,5 @@ const InputUID = ({
// value: '',
// };
// export default memo(InputUID, isEqual);
export default InputUID;

View File

@ -15,7 +15,6 @@ import InputJSON from '../InputJSON';
import GenericInput from './GenericInput';
import InputUID from '../InputUID';
// import SelectWrapper from '../SelectWrapper';
// import WysiwygWithErrors from '../WysiwygWithErrors';
import {
connect,
@ -54,7 +53,7 @@ function Inputs({
const fieldName = useMemo(() => {
return getFieldName(keys);
}, [keys]);
const validations = useMemo(() => {
const inputValidations = omit(
fieldSchema,
@ -204,7 +203,7 @@ function Inputs({
// </div>
// );
}
return (
<GenericInput
// {...metadatas}