重构消息通知弹窗

This commit is contained in:
dengqichen 2025-11-13 16:55:47 +08:00
parent 828a0da526
commit 8b26c0d196
2 changed files with 243 additions and 200 deletions

View File

@ -145,10 +145,10 @@ export const NotificationConfigDialog: React.FC<
};
// 加载通知模板列表
const loadNotificationTemplates = async () => {
const loadNotificationTemplates = async (channelType?: string) => {
setLoadingTemplates(true);
try {
const templates = await getNotificationTemplates();
const templates = await getNotificationTemplates(channelType);
setNotificationTemplates(templates || []);
} catch (error: any) {
toast({
@ -207,11 +207,22 @@ export const NotificationConfigDialog: React.FC<
useEffect(() => {
if (open) {
loadNotificationChannels();
loadNotificationTemplates();
loadEnvironmentConfig();
}
}, [open, teamId, environmentId]);
// 监听通知渠道变化,重新加载模板列表
const selectedChannelId = form.watch('notificationConfig.notificationChannelId');
useEffect(() => {
if (open && notificationChannels.length > 0) {
const selectedChannel = notificationChannels.find(
(channel) => channel.id === selectedChannelId
);
loadNotificationTemplates(selectedChannel?.type);
}
}, [selectedChannelId, notificationChannels, open]);
const handleSubmit = async (data: FormData) => {
console.log('表单提交数据:', data);
console.log('当前配置:', currentConfig);
@ -346,18 +357,19 @@ export const NotificationConfigDialog: React.FC<
/>
{/* 部署通知 */}
<div className="grid grid-cols-2 gap-4 rounded-lg border p-4">
<div className="rounded-lg border p-4 space-y-2">
<div className="grid grid-cols-[1fr_auto_1fr] gap-4 items-center">
{/* 左侧:通知类型标题 */}
<div>
<FormLabel className="text-base"></FormLabel>
</div>
{/* 中间:开关 */}
<FormField
control={form.control}
name="notificationConfig.deployNotificationEnabled"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between space-y-0">
<div className="space-y-0.5 flex-1">
<FormLabel className="text-base"></FormLabel>
<div className="text-sm text-muted-foreground">
</div>
</div>
<FormItem className="mb-0">
<FormControl>
<Switch
checked={field.value}
@ -368,11 +380,13 @@ export const NotificationConfigDialog: React.FC<
)}
/>
{/* 右侧:模板选择 */}
<FormField
control={form.control}
name="notificationConfig.deployNotificationTemplateId"
render={({ field }) => (
<FormItem className="flex flex-col justify-center space-y-2">
<FormItem className="mb-0">
<FormControl>
<ClearableSelect
value={field.value?.toString()}
onValueChange={(value) =>
@ -380,7 +394,6 @@ export const NotificationConfigDialog: React.FC<
}
disabled={loadingTemplates}
>
<FormControl>
<SelectTrigger
clearable
hasValue={!!field.value}
@ -396,7 +409,6 @@ export const NotificationConfigDialog: React.FC<
}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
{notificationTemplates.map((template) => (
<SelectItem
@ -408,28 +420,38 @@ export const NotificationConfigDialog: React.FC<
))}
</SelectContent>
</ClearableSelect>
<div className="text-sm text-muted-foreground">
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 描述文字行 */}
<div className="grid grid-cols-[1fr_auto_1fr] gap-4">
<div className="text-sm text-muted-foreground">
</div>
<div></div>
<div className="text-sm text-muted-foreground">
</div>
</div>
</div>
{/* 构建通知 */}
<div className="grid grid-cols-2 gap-4 rounded-lg border p-4">
<div className="rounded-lg border p-4 space-y-2">
<div className="grid grid-cols-[1fr_auto_1fr] gap-4 items-center">
{/* 左侧:通知类型标题 */}
<div>
<FormLabel className="text-base"></FormLabel>
</div>
{/* 中间:开关 */}
<FormField
control={form.control}
name="notificationConfig.buildNotificationEnabled"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between space-y-0">
<div className="space-y-0.5 flex-1">
<FormLabel className="text-base"></FormLabel>
<div className="text-sm text-muted-foreground">
</div>
</div>
<FormItem className="mb-0">
<FormControl>
<Switch
checked={field.value}
@ -440,11 +462,13 @@ export const NotificationConfigDialog: React.FC<
)}
/>
{/* 右侧:模板选择 */}
<FormField
control={form.control}
name="notificationConfig.buildNotificationTemplateId"
render={({ field }) => (
<FormItem className="flex flex-col justify-center space-y-2">
<FormItem className="mb-0">
<FormControl>
<ClearableSelect
value={field.value?.toString()}
onValueChange={(value) =>
@ -452,7 +476,6 @@ export const NotificationConfigDialog: React.FC<
}
disabled={loadingTemplates}
>
<FormControl>
<SelectTrigger
clearable
hasValue={!!field.value}
@ -468,7 +491,6 @@ export const NotificationConfigDialog: React.FC<
}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
{notificationTemplates.map((template) => (
<SelectItem
@ -480,28 +502,38 @@ export const NotificationConfigDialog: React.FC<
))}
</SelectContent>
</ClearableSelect>
<div className="text-sm text-muted-foreground">
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 描述文字行 */}
<div className="grid grid-cols-[1fr_auto_1fr] gap-4">
<div className="text-sm text-muted-foreground">
</div>
<div></div>
<div className="text-sm text-muted-foreground">
</div>
</div>
</div>
{/* 失败日志 */}
<div className="grid grid-cols-2 gap-4 rounded-lg border p-4">
<div className="rounded-lg border p-4 space-y-2">
<div className="grid grid-cols-[1fr_auto_1fr] gap-4 items-center">
{/* 左侧:通知类型标题 */}
<div>
<FormLabel className="text-base"></FormLabel>
</div>
{/* 中间:开关 */}
<FormField
control={form.control}
name="notificationConfig.buildFailureFileEnabled"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between space-y-0">
<div className="space-y-0.5 flex-1">
<FormLabel className="text-base"></FormLabel>
<div className="text-sm text-muted-foreground">
</div>
</div>
<FormItem className="mb-0">
<FormControl>
<Switch
checked={field.value}
@ -512,11 +544,13 @@ export const NotificationConfigDialog: React.FC<
)}
/>
{/* 右侧:模板选择 */}
<FormField
control={form.control}
name="notificationConfig.buildFailureNotificationTemplateId"
render={({ field }) => (
<FormItem className="flex flex-col justify-center space-y-2">
<FormItem className="mb-0">
<FormControl>
<ClearableSelect
value={field.value?.toString()}
onValueChange={(value) =>
@ -524,7 +558,6 @@ export const NotificationConfigDialog: React.FC<
}
disabled={loadingTemplates}
>
<FormControl>
<SelectTrigger
clearable
hasValue={!!field.value}
@ -540,7 +573,6 @@ export const NotificationConfigDialog: React.FC<
}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
{notificationTemplates.map((template) => (
<SelectItem
@ -552,14 +584,23 @@ export const NotificationConfigDialog: React.FC<
))}
</SelectContent>
</ClearableSelect>
<div className="text-sm text-muted-foreground">
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* 描述文字行 */}
<div className="grid grid-cols-[1fr_auto_1fr] gap-4">
<div className="text-sm text-muted-foreground">
</div>
<div></div>
<div className="text-sm text-muted-foreground">
</div>
</div>
</div>
</DialogBody>
<DialogFooter>

View File

@ -177,7 +177,9 @@ export const deleteTeamEnvironmentConfig = (id: number) =>
/**
*
*/
export const getNotificationTemplates = () =>
request.get<any[]>('/api/v1/notification-template/list');
export const getNotificationTemplates = (channelType?: string) =>
request.get<any[]>('/api/v1/notification-template/list', {
params: channelType ? { channelType } : undefined
});