Made begin and end date required (#3283)

This commit is contained in:
Erik Jan de Wit 2022-09-12 15:35:30 +02:00 committed by GitHub
parent 0e1c788f5b
commit 76ce0e5315
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import {
Split, Split,
SplitItem, SplitItem,
TimePicker, TimePicker,
ValidatedOptions,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { HelpItem } from "../../../components/help-enabler/HelpItem"; import { HelpItem } from "../../../components/help-enabler/HelpItem";
@ -57,6 +58,7 @@ const DateTime = ({ name }: { name: string }) => {
name={name} name={name}
defaultValue="" defaultValue=""
control={control} control={control}
rules={{ required: true }}
render={({ onChange, value }) => { render={({ onChange, value }) => {
const dateTime = value.match(DATE_TIME_FORMAT) || ["", "", "0", "00"]; const dateTime = value.match(DATE_TIME_FORMAT) || ["", "", "0", "00"];
return ( return (
@ -147,7 +149,7 @@ const FromTo = ({ name, ...rest }: NumberControlProps) => {
export const Time = () => { export const Time = () => {
const { t } = useTranslation("clients"); const { t } = useTranslation("clients");
const { getValues } = useFormContext(); const { getValues, errors } = useFormContext();
const [repeat, setRepeat] = useState(getValues("month")); const [repeat, setRepeat] = useState(getValues("month"));
return ( return (
<> <>
@ -203,6 +205,11 @@ export const Time = () => {
fieldLabelId="clients:startTime" fieldLabelId="clients:startTime"
/> />
} }
isRequired
helperTextInvalid={t("common:required")}
validated={
errors.notBefore ? ValidatedOptions.error : ValidatedOptions.default
}
> >
<DateTime name="notBefore" /> <DateTime name="notBefore" />
</FormGroup> </FormGroup>
@ -215,6 +222,13 @@ export const Time = () => {
fieldLabelId="clients:expireTime" fieldLabelId="clients:expireTime"
/> />
} }
isRequired
helperTextInvalid={t("common:required")}
validated={
errors.notOnOrAfter
? ValidatedOptions.error
: ValidatedOptions.default
}
> >
<DateTime name="notOnOrAfter" /> <DateTime name="notOnOrAfter" />
</FormGroup> </FormGroup>