Skip to content

Commit 2db11b5

Browse files
committed
chore(announcement): show all warnings
1 parent 115697c commit 2db11b5

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

ui/src/components/announcements/AnnouncementForm.tsx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { FormField } from "../atoms/FormField";
1111
import { Indeterminate } from "../atoms/Indeterminate";
1212
import { Title } from "../atoms/Title";
1313
import { EventSelector } from "../events/EventSelector";
14+
import { Confirm } from "../molecules/Confirm";
1415
import { PageHeader } from "../molecules/PageHeader";
1516
import { DateTimePicker } from "../organisms/DateTimePicker";
1617
import { MarkdownCombo } from "../organisms/markdown/MarkdownCombo";
1718
import { Button } from "../ui/button";
18-
import { Confirm } from "../molecules/Confirm";
1919
import { Checkbox } from "../ui/checkbox";
2020
import { 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
)

ui/src/components/molecules/Confirm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function Confirm({ title, description, confirmText, onConfirm, open, onOp
1515
<DialogContent>
1616
<DialogHeader>
1717
<DialogTitle>{title}</DialogTitle>
18-
<DialogDescription>{description}</DialogDescription>
18+
<DialogDescription className="whitespace-pre">{description}</DialogDescription>
1919
</DialogHeader>
2020
<DialogFooter>
2121
<DialogClose asChild>

0 commit comments

Comments
 (0)