@@ -6,7 +6,7 @@ import { useSuspendedBackendaiClient } from '../hooks';
66import { useTanMutation } from '../hooks/reactQueryAlias' ;
77import BAICodeEditor from './BAICodeEditor' ;
88import { useQueryClient } from '@tanstack/react-query' ;
9- import { App , Form , Switch , Typography , theme } from 'antd' ;
9+ import { App , Form , Switch , theme } from 'antd' ;
1010import {
1111 BAIModal ,
1212 BAIModalProps ,
@@ -60,12 +60,19 @@ const AnnouncementEditModal: React.FC<AnnouncementEditModalProps> = ({
6060
6161 return (
6262 < BAIModal
63- width = { 800 }
63+ width = { 960 }
6464 title = { t ( 'summary.EditAnnouncement' ) }
6565 okText = { t ( 'button.Save' ) }
6666 confirmLoading = { updateMutation . isPending }
6767 onCancel = { ( ) => onRequestClose ( ) }
6868 onOk = { ( ) => {
69+ // The backend rejects enabling an announcement with an empty message
70+ // ("Empty message not allowed to enable announcement"); guard here so
71+ // the user gets immediate feedback instead of a server error.
72+ if ( enabled && ! message . trim ( ) ) {
73+ appMessage . error ( t ( 'summary.AnnouncementMessageRequired' ) ) ;
74+ return ;
75+ }
6976 updateMutation . mutate (
7077 { enabled, message } ,
7178 {
@@ -85,61 +92,67 @@ const AnnouncementEditModal: React.FC<AnnouncementEditModalProps> = ({
8592 } }
8693 { ...modalProps }
8794 >
88- < BAIFlex direction = "column" align = "stretch" gap = "sm" >
89- < Form layout = "vertical" >
90- < Form . Item label = { t ( 'summary.AnnouncementEnabled' ) } >
91- < Switch checked = { enabled } onChange = { setEnabled } />
92- </ Form . Item >
95+ < Form layout = "vertical" >
96+ < BAIFlex direction = "column" align = "stretch" gap = "sm" >
9397 < Form . Item
94- label = { t ( 'summary.AnnouncementMessage' ) }
95- help = { t ( 'summary.AnnouncementMarkdownHelp' ) }
98+ label = { t ( 'summary.AnnouncementEnabled' ) }
9699 style = { { marginBottom : 0 } }
97100 >
98- < BAICodeEditor
99- language = "markdown"
100- editable
101- value = { message }
102- onChange = { setMessage }
103- lineWrapping
104- height = { 240 }
105- />
101+ < Switch checked = { enabled } onChange = { setEnabled } />
106102 </ Form . Item >
107- </ Form >
108- { message ? (
109- < BAIFlex direction = "column" align = "stretch" gap = "xxs" >
110- < Typography . Text type = "secondary" >
111- { t ( 'summary.AnnouncementPreview' ) }
112- </ Typography . Text >
113- < div
114- style = { {
115- border : `1px solid ${ token . colorBorder } ` ,
116- borderRadius : token . borderRadius ,
117- padding : token . padding ,
118- } }
103+ < BAIFlex direction = "row" align = "stretch" gap = "sm" wrap = "wrap" >
104+ < Form . Item
105+ label = { t ( 'summary.AnnouncementMessage' ) }
106+ help = { t ( 'summary.AnnouncementMarkdownHelp' ) }
107+ required = { enabled }
108+ style = { { flex : 1 , minWidth : 0 , marginBottom : 0 } }
109+ >
110+ < BAICodeEditor
111+ language = "markdown"
112+ editable
113+ value = { message }
114+ onChange = { setMessage }
115+ lineWrapping
116+ height = { 280 }
117+ />
118+ </ Form . Item >
119+ < Form . Item
120+ label = { t ( 'summary.AnnouncementPreview' ) }
121+ style = { { flex : 1 , minWidth : 0 , marginBottom : 0 } }
119122 >
120- < div style = { { marginBottom : token . marginSM * - 1 } } >
121- < Markdown
122- options = { {
123- overrides : {
124- p : {
125- props : {
126- style : {
127- marginTop : 0 ,
128- marginBottom : token . marginSM ,
123+ < div
124+ style = { {
125+ border : `1px solid ${ token . colorBorder } ` ,
126+ borderRadius : token . borderRadius ,
127+ padding : token . padding ,
128+ height : 280 ,
129+ overflow : 'auto' ,
130+ } }
131+ >
132+ < div style = { { marginBottom : token . marginSM * - 1 } } >
133+ < Markdown
134+ options = { {
135+ overrides : {
136+ p : {
137+ props : {
138+ style : {
139+ marginTop : 0 ,
140+ marginBottom : token . marginSM ,
141+ } ,
129142 } ,
130143 } ,
131144 } ,
132- } ,
133- } }
134- >
135- { /* add dummy <p> to remove unnecessary margin bottom */ }
136- { message + '<p></p>' }
137- </ Markdown >
145+ } }
146+ >
147+ { /* add dummy <p> to remove unnecessary margin bottom */ }
148+ { ( message || '' ) + ' <p></p>' }
149+ </ Markdown >
150+ </ div >
138151 </ div >
139- </ div >
152+ </ Form . Item >
140153 </ BAIFlex >
141- ) : null }
142- </ BAIFlex >
154+ </ BAIFlex >
155+ </ Form >
143156 </ BAIModal >
144157 ) ;
145158} ;
0 commit comments