@@ -11,11 +11,11 @@ import { FormField } from "../atoms/FormField";
1111import { Indeterminate } from "../atoms/Indeterminate" ;
1212import { Title } from "../atoms/Title" ;
1313import { EventSelector } from "../events/EventSelector" ;
14+ import { Confirm } from "../molecules/Confirm" ;
1415import { PageHeader } from "../molecules/PageHeader" ;
1516import { DateTimePicker } from "../organisms/DateTimePicker" ;
1617import { MarkdownCombo } from "../organisms/markdown/MarkdownCombo" ;
1718import { Button } from "../ui/button" ;
18- import { Confirm } from "../molecules/Confirm" ;
1919import { Checkbox } from "../ui/checkbox" ;
2020import { Label } from "../ui/label" ;
2121
@@ -42,12 +42,13 @@ export function AnnouncementForm({ announcement, defaultEvents, onSubmit }: Prop
4242
4343 const [ referenceDate , setReferenceDate ] = useState < Date | undefined > ( undefined )
4444
45- const [ openAtChannel , setOpenAtChannel ] = useState ( false )
45+ const [ openWarning , setOpenWarning ] = useState ( false )
46+ const [ warningText , setWarningText ] = useState ( "" )
4647 const handleAtChannel = ( ) => {
47- handleSubmit ( true )
48+ handleSubmit ( false )
4849 }
4950
50- const handleSubmit = ( ignoreAtChannel : boolean ) => {
51+ const handleSubmit = ( optionalChecks : boolean ) => {
5152 if ( form . state . values . draft ) {
5253 form . setFieldValue ( "sendTime" , undefined )
5354 } else {
@@ -65,21 +66,29 @@ export function AnnouncementForm({ announcement, defaultEvents, onSubmit }: Prop
6566 return
6667 }
6768
68- if ( ! ignoreAtChannel ) {
69+ if ( optionalChecks ) {
70+ let warningText = ""
71+
6972 // Check mattermost mention
7073 let mentions = [ "@channel" ]
7174 if ( ! includesMention ( form . state . values . content , mentions ) ) {
72- setOpenAtChannel ( true )
73- return
75+ warningText += "No mattermost mention.\n"
7476 }
7577 // Check discord mentions
7678 mentions = [ "@here" , "@everyone" ]
7779 if ( ! includesMention ( form . state . values . content , mentions ) ) {
78- setOpenAtChannel ( true )
80+ warningText += "No discord mention.\n"
81+ }
82+
83+ if ( warningText . length > 0 ) {
84+ warningText += "\nDo you still want to send it?"
85+ setWarningText ( warningText )
86+ setOpenWarning ( true )
7987 return
8088 }
8189 }
8290
91+
8392 onSubmit ( form . state . values )
8493 }
8594
@@ -94,7 +103,7 @@ export function AnnouncementForm({ announcement, defaultEvents, onSubmit }: Prop
94103 validators : {
95104 onSubmit : announcementSchema ,
96105 } ,
97- onSubmit : ( ) => handleSubmit ( false ) ,
106+ onSubmit : ( ) => handleSubmit ( true ) ,
98107 } )
99108
100109 const isDraft = useStore ( form . store , ( s ) => s . values . draft )
@@ -174,11 +183,11 @@ export function AnnouncementForm({ announcement, defaultEvents, onSubmit }: Prop
174183 </ div >
175184 < Confirm
176185 title = "Send confirmation"
177- description = "The announcement has no mattermost or discord mentions. Do you still want to send it?"
186+ description = { warningText }
178187 confirmText = "Send"
179188 onConfirm = { handleAtChannel }
180- open = { openAtChannel }
181- onOpenChange = { setOpenAtChannel }
189+ open = { openWarning }
190+ onOpenChange = { setOpenWarning }
182191 />
183192 </ >
184193 )
0 commit comments