1
- import { Button , Group , IconClearAll , Modal , modals , Stack , Title , useDisclosure , useForm , Text } from "@quassel/ui" ;
1
+ import { Button , Group , IconClearAll , modals , Stack , Title , useForm , Text } from "@quassel/ui" ;
2
2
import { createFileRoute , Link , useNavigate } from "@tanstack/react-router" ;
3
3
import { i18n } from "../../../../../stores/i18n" ;
4
4
import { useStore } from "@nanostores/react" ;
@@ -14,7 +14,8 @@ const messages = i18n("questionnaireEntries", {
14
14
addEntityLabel : "Add" ,
15
15
notificationSuccessCreateLanguage : "Successfully add a new language." ,
16
16
notificationSuccessCreateCarer : "Successfully add a new carer." ,
17
- gapsDialogTitle : "Gaps detected in the calendar" ,
17
+ gapsDialogTitle : "Continue with gaps?" ,
18
+ gapsDialogDescription : "There were gaps detected in the calendar. Do you want to continue anyway or highlight the gaps?" ,
18
19
gapsDialogContinueAnyway : "Continue anyway" ,
19
20
gapsDialogHighlightGaps : "Highlight gaps" ,
20
21
confirmClearDialogTitle : "Clear all entries from this questionnaire?" ,
@@ -35,7 +36,6 @@ export function Entries() {
35
36
36
37
const [ gaps , setGaps ] = useState < GapsPerDay > ( ) ;
37
38
const [ highlightGaps , setHighlightGaps ] = useState ( false ) ;
38
- const [ gapsDialogOpened , { open, close } ] = useDisclosure ( ) ;
39
39
40
40
const f = useForm < { entries : components [ "schemas" ] [ "EntryResponseDto" ] [ ] } > ( {
41
41
initialValues : {
@@ -56,6 +56,18 @@ export function Entries() {
56
56
n ( { to : "/questionnaire/$id/remarks" , params : p } ) ;
57
57
} ;
58
58
59
+ const handleGapValidation = ( ) => {
60
+ modals . openConfirmModal ( {
61
+ title : t . gapsDialogTitle ,
62
+ children : < Text size = "sm" > { t . gapsDialogDescription } </ Text > ,
63
+ labels : { cancel : t . gapsDialogHighlightGaps , confirm : t . gapsDialogContinueAnyway } ,
64
+ confirmProps : { variant : "light" } ,
65
+ cancelProps : { variant : "filled" } ,
66
+ onConfirm : handleSubmit ,
67
+ onCancel : ( ) => setHighlightGaps ( true ) ,
68
+ } ) ;
69
+ } ;
70
+
59
71
const handleClearEntries = ( ) => {
60
72
modals . openConfirmModal ( {
61
73
title : t . confirmClearDialogTitle ,
@@ -72,41 +84,24 @@ export function Entries() {
72
84
} , [ questionnaire ] ) ;
73
85
74
86
return (
75
- < >
76
- < Modal opened = { gapsDialogOpened } onClose = { close } centered title = { t . gapsDialogTitle } >
77
- < Group justify = "flex-end" >
78
- < Button onClick = { handleSubmit } variant = "light" type = "submit" >
79
- { t . gapsDialogContinueAnyway }
80
- </ Button >
81
- < Button
82
- onClick = { ( ) => {
83
- setHighlightGaps ( true ) ;
84
- close ( ) ;
85
- } }
86
- >
87
- { t . gapsDialogHighlightGaps }
87
+ < form onSubmit = { f . onSubmit ( handleSubmit , handleGapValidation ) } >
88
+ < Stack >
89
+ < Group justify = "space-between" >
90
+ < Title order = { 3 } > { questionnaire . title } </ Title >
91
+ < Button variant = "default" onClick = { handleClearEntries } rightSection = { < IconClearAll /> } >
92
+ Clear all
88
93
</ Button >
89
94
</ Group >
90
- </ Modal >
91
- < form onSubmit = { f . onSubmit ( handleSubmit , open ) } >
92
- < Stack >
93
- < Group justify = "space-between" >
94
- < Title order = { 3 } > { questionnaire . title } </ Title >
95
- < Button variant = "default" onClick = { handleClearEntries } rightSection = { < IconClearAll /> } >
96
- Clear all
97
- </ Button >
98
- </ Group >
99
- < QuestionnaireEntries gaps = { highlightGaps ? gaps : undefined } questionnaire = { questionnaire } />
100
-
101
- < Group >
102
- < Link to = "/questionnaire/$id/period" params = { p } >
103
- < Button variant = "light" > { t . backAction } </ Button >
104
- </ Link >
105
- < Button type = "submit" > { t . formAction } </ Button >
106
- </ Group >
107
- </ Stack >
108
- </ form >
109
- </ >
95
+ < QuestionnaireEntries gaps = { highlightGaps ? gaps : undefined } questionnaire = { questionnaire } />
96
+
97
+ < Group >
98
+ < Link to = "/questionnaire/$id/period" params = { p } >
99
+ < Button variant = "light" > { t . backAction } </ Button >
100
+ </ Link >
101
+ < Button type = "submit" > { t . formAction } </ Button >
102
+ </ Group >
103
+ </ Stack >
104
+ </ form >
110
105
) ;
111
106
}
112
107
0 commit comments