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": { "i18n": {
"localized": true "localized": true
} }
} },
"repeatable": false,
"required": true
}, },
"contactEmail": { "contactEmail": {
"type": "email", "type": "email",

View File

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

View File

@ -7,7 +7,8 @@
}, },
"attributes": { "attributes": {
"label": { "label": {
"type": "string" "type": "string",
"default": "toto"
}, },
"start_date": { "start_date": {
"type": "date", "type": "date",
@ -19,11 +20,15 @@
}, },
"media": { "media": {
"type": "media", "type": "media",
"multiple": false,
"required": false "required": false
}, },
"dish": { "dish": {
"component": "default.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': { case 'time': {
cleanedData = value; cleanedData = value;
// FIXME
if (value && value.split(':').length < 3) { if (value && value.split(':').length < 3) {
cleanedData = `${value}:00`; cleanedData = `${value}:00`;
} }

View File

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

View File

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