Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scheduling): update error message #20208

Draft
wants to merge 5 commits into
base: v5/main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
import { formatISO } from 'date-fns';
import { utcToZonedTime, zonedTimeToUtc } from 'date-fns-tz';
import { Formik, Form, useFormikContext } from 'formik';
import { useIntl } from 'react-intl';
import { MessageDescriptor, useIntl } from 'react-intl';
import { useLocation } from 'react-router-dom';

import { RELEASE_SCHEMA } from '../../../shared/validation-schemas';
import { RELEASE_SCHEMA } from '../validation/schemas';
import { pluginId } from '../pluginId';
import { getTimezoneOffset } from '../utils/time';

Expand Down Expand Up @@ -111,7 +111,13 @@ export const ReleaseModal = ({
<Form>
<Modal.Body>
<Flex direction="column" alignItems="stretch" gap={6}>
<Field.Root name="name" error={errors.name} required>
<Field.Root
name="name"
error={
errors.name ? formatMessage(errors.name as MessageDescriptor) : undefined
}
required
>
<Field.Label>
{formatMessage({
id: 'content-releases.modal.form.input.label.release-name',
Expand Down Expand Up @@ -158,7 +164,15 @@ export const ReleaseModal = ({
<>
<Flex gap={4} alignItems="start">
<Box width="100%">
<Field.Root name="date" error={errors.date} required>
<Field.Root
name="date"
error={
errors.date
? formatMessage(errors.date as MessageDescriptor)
: undefined
}
required
>
<Field.Label>
{formatMessage({
id: 'content-releases.modal.form.input.label.date',
Expand Down Expand Up @@ -186,7 +200,15 @@ export const ReleaseModal = ({
</Field.Root>
</Box>
<Box width="100%">
<Field.Root name="time" error={errors.time} required>
<Field.Root
name="time"
error={
errors.time
? formatMessage(errors.time as MessageDescriptor)
: undefined
}
required
>
<Field.Label>
{formatMessage({
id: 'content-releases.modal.form.input.label.time',
Expand Down Expand Up @@ -286,7 +308,11 @@ const TimezoneComponent = ({ timezoneOptions }: { timezoneOptions: ITimezoneOpti
}, [setFieldValue, values.date, values.timezone]);

return (
<Field.Root name="timezone" error={errors.timezone} required>
<Field.Root
name="timezone"
error={errors.timezone ? formatMessage(errors.timezone as MessageDescriptor) : undefined}
required
>
<Field.Label>
{formatMessage({
id: 'content-releases.modal.form.input.label.timezone',
Expand Down
53 changes: 53 additions & 0 deletions packages/core/content-releases/admin/src/validation/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as yup from 'yup';
import { translatedErrors } from '@strapi/admin/strapi-admin';

export const RELEASE_SCHEMA = yup
.object()
.shape({
name: yup.string().trim().required({
id: translatedErrors.required.id,
defaultMessage: 'This field is required',
}),
scheduledAt: yup.string().nullable(),
isScheduled: yup.boolean().optional(),
time: yup.string().when('isScheduled', {
is: true,
then: yup.string().trim().required({
id: translatedErrors.required.id,
defaultMessage: 'This field is required',
}),
otherwise: yup.string().nullable(),
}),
timezone: yup.string().when('isScheduled', {
is: true,
then: yup
.string()
.required({
id: translatedErrors.required.id,
defaultMessage: 'This field is required',
})
.nullable(),
otherwise: yup.string().nullable(),
}),
date: yup.string().when('isScheduled', {
is: true,
then: yup
.string()
.required({
id: translatedErrors.required.id,
defaultMessage: 'This field is required',
})
.nullable(),
otherwise: yup.string().nullable(),
}),
})
.required()
.noUnknown();

export const SETTINGS_SCHEMA = yup
.object()
.shape({
defaultTimezone: yup.string().nullable().default(null),
})
.required()
.noUnknown();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { yup, validateYupSchema } from '@strapi/utils';
import { RELEASE_SCHEMA } from '../../../../shared/validation-schemas';
import { RELEASE_SCHEMA } from '../validation/schemas';

const FIND_BY_DOCUMENT_ATTACHED_PARAMS_SCHEMA = yup
.object()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as yup from 'yup';

export const RELEASE_SCHEMA = yup
.object()
.shape({
name: yup.string().trim().required(),
scheduledAt: yup.string().nullable(),
timezone: yup.string().when('scheduledAt', {
is: (value: any) => value !== null && value !== undefined,
then: yup.string().required(),
otherwise: yup.string().nullable(),
}),
})
.required()
.noUnknown();

export const SETTINGS_SCHEMA = yup
.object()
.shape({
defaultTimezone: yup.string().nullable().default(null),
})
.required()
.noUnknown();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateYupSchema } from '@strapi/utils';
import { SETTINGS_SCHEMA } from '../../../../shared/validation-schemas';
import { SETTINGS_SCHEMA } from '../validation/schemas';

export const validateSettings = validateYupSchema(SETTINGS_SCHEMA);
34 changes: 0 additions & 34 deletions packages/core/content-releases/shared/validation-schemas.ts

This file was deleted.