1
1
import { useForm } from "@mantine/form" ;
2
- import { Button , Flex , formatDate , getNext , MonthPicker , Stack , TextInput } from "@quassel/ui" ;
2
+ import { Button , Flex , formatDate , getNext , InputError , MonthPicker , Stack , TextInput } from "@quassel/ui" ;
3
3
import { i18n } from "../../stores/i18n" ;
4
4
import { useStore } from "@nanostores/react" ;
5
5
import { useEffect } from "react" ;
@@ -20,6 +20,7 @@ type PeriodFormProps = {
20
20
const messages = i18n ( "periodForm" , {
21
21
labelTitle : "Title" ,
22
22
defaultTitle : params ( "Period ({start} - {end})" ) ,
23
+ validationStartDate : "There are no gaps allowed between questionnaires. The questionnaire must start when the previous ended." ,
23
24
} ) ;
24
25
25
26
export function PeriodForm ( { onSave, actionLabel, period, prevEndDate } : PeriodFormProps ) {
@@ -30,6 +31,16 @@ export function PeriodForm({ onSave, actionLabel, period, prevEndDate }: PeriodF
30
31
range : [ prevEndDate ? getNext ( "month" , prevEndDate ) : null , null ] ,
31
32
title : "" ,
32
33
} ,
34
+ validate : {
35
+ range ( [ start ] ) {
36
+ console . log ( start ) ;
37
+ console . log ( prevEndDate && getNext ( "month" , prevEndDate ) ) ;
38
+
39
+ if ( prevEndDate && + getNext ( "month" , prevEndDate ) !== + start ! ) {
40
+ return t . validationStartDate ;
41
+ }
42
+ } ,
43
+ } ,
33
44
onValuesChange ( newValues , prevValues ) {
34
45
const [ newStart , newEnd ] = newValues . range ?? [ ] ;
35
46
const [ prevStart , prevEnd ] = prevValues . range ?? [ ] ;
@@ -51,17 +62,20 @@ export function PeriodForm({ onSave, actionLabel, period, prevEndDate }: PeriodF
51
62
< form onSubmit = { f . onSubmit ( ( values ) => onSave ( values ) ) } >
52
63
< Stack >
53
64
< Flex justify = "center" >
54
- < MonthPicker
55
- { ...f . getInputProps ( "range" ) }
56
- size = "md"
57
- type = "range"
58
- minDate = { prevEndDate }
59
- defaultDate = { prevEndDate }
60
- numberOfColumns = { 2 }
61
- columnsToScroll = { 1 }
62
- allowSingleDateInRange
63
- selectEndOfMonth
64
- />
65
+ < Stack >
66
+ < MonthPicker
67
+ { ...f . getInputProps ( "range" ) }
68
+ size = "md"
69
+ type = "range"
70
+ minDate = { prevEndDate }
71
+ defaultDate = { prevEndDate }
72
+ numberOfColumns = { 2 }
73
+ columnsToScroll = { 1 }
74
+ allowSingleDateInRange
75
+ selectEndOfMonth
76
+ />
77
+ < InputError > { f . getInputProps ( "range" ) . error } </ InputError >
78
+ </ Stack >
65
79
</ Flex >
66
80
< TextInput { ...f . getInputProps ( "title" ) } label = { t . labelTitle } />
67
81
< Button type = "submit" > { actionLabel } </ Button >
0 commit comments