|
3 | 3 | Copyright (c) 2015-2026 Lablup Inc. All rights reserved. |
4 | 4 | */ |
5 | 5 | import { useSuspendedBackendaiClient } from '../hooks'; |
| 6 | +import { useSuspenseTanQuery } from '../hooks/reactQueryAlias'; |
6 | 7 | import { useSetBAINotification } from '../hooks/useBAINotification'; |
| 8 | +import AnnouncementEditModal from './AnnouncementEditModal'; |
7 | 9 | import SettingList, { SettingGroup } from './SettingList'; |
8 | | -import { RedoOutlined } from '@ant-design/icons'; |
| 10 | +import { NotificationOutlined, RedoOutlined } from '@ant-design/icons'; |
9 | 11 | import { Button } from 'antd'; |
| 12 | +import { BAIUnmountAfterClose } from 'backend.ai-ui'; |
10 | 13 | import { useState } from 'react'; |
11 | 14 | import { useTranslation } from 'react-i18next'; |
12 | 15 |
|
13 | 16 | const MaintenanceSettingList = () => { |
| 17 | + 'use memo'; |
14 | 18 | const [isRecalculating, setIsRecalculating] = useState(false); |
15 | 19 | const [isRescanning, setIsRescanning] = useState(false); |
| 20 | + const [isAnnouncementModalOpen, setIsAnnouncementModalOpen] = useState(false); |
16 | 21 |
|
17 | 22 | const { t } = useTranslation(); |
18 | 23 | const { upsertNotification } = useSetBAINotification(); |
19 | 24 | const baiClient = useSuspendedBackendaiClient(); |
20 | 25 |
|
| 26 | + const { data: announcement } = useSuspenseTanQuery({ |
| 27 | + queryKey: ['baiClient', 'service', 'get_announcement'], |
| 28 | + queryFn: () => { |
| 29 | + return baiClient.service.get_announcement(); |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
21 | 33 | const recalculateUsage = () => { |
22 | 34 | setIsRecalculating(true); |
23 | 35 |
|
@@ -130,9 +142,41 @@ const MaintenanceSettingList = () => { |
130 | 142 | }, |
131 | 143 | ], |
132 | 144 | }, |
| 145 | + { |
| 146 | + 'data-testid': 'maintenance-announcement', |
| 147 | + title: t('maintenance.Announcement'), |
| 148 | + settingItems: [ |
| 149 | + { |
| 150 | + type: 'custom', |
| 151 | + title: t('maintenance.SystemAnnouncement'), |
| 152 | + description: t('maintenance.DescSystemAnnouncement'), |
| 153 | + children: ( |
| 154 | + <Button |
| 155 | + icon={<NotificationOutlined />} |
| 156 | + onClick={() => setIsAnnouncementModalOpen(true)} |
| 157 | + > |
| 158 | + {t('summary.EditAnnouncement')} |
| 159 | + </Button> |
| 160 | + ), |
| 161 | + showResetButton: false, |
| 162 | + }, |
| 163 | + ], |
| 164 | + }, |
133 | 165 | ]; |
134 | 166 |
|
135 | | - return <SettingList settingGroups={settingGroupList} showSearchBar />; |
| 167 | + return ( |
| 168 | + <> |
| 169 | + <SettingList settingGroups={settingGroupList} showSearchBar /> |
| 170 | + <BAIUnmountAfterClose> |
| 171 | + <AnnouncementEditModal |
| 172 | + open={isAnnouncementModalOpen} |
| 173 | + initialMessage={announcement?.message ?? ''} |
| 174 | + initialEnabled={announcement?.enabled ?? true} |
| 175 | + onRequestClose={() => setIsAnnouncementModalOpen(false)} |
| 176 | + /> |
| 177 | + </BAIUnmountAfterClose> |
| 178 | + </> |
| 179 | + ); |
136 | 180 | }; |
137 | 181 |
|
138 | 182 | export default MaintenanceSettingList; |
0 commit comments