重构消息通知弹窗
This commit is contained in:
parent
0de08cb09b
commit
62c1a8b0d1
@ -5,34 +5,13 @@ import React from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { TagList } from '@/components/ui/tag-list';
|
||||
import type { ConfigComponentProps } from '../config-strategies/types';
|
||||
|
||||
export const EmailConfigForm: React.FC<ConfigComponentProps> = ({
|
||||
register,
|
||||
errors,
|
||||
setValue,
|
||||
configState,
|
||||
updateConfigState,
|
||||
}) => {
|
||||
const handleAddReceiver = () => {
|
||||
if (configState.newReceiver?.trim() && !configState.receivers?.includes(configState.newReceiver.trim())) {
|
||||
updateConfigState({
|
||||
receivers: [...(configState.receivers || []), configState.newReceiver.trim()],
|
||||
newReceiver: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveReceiver = (index: number) => {
|
||||
updateConfigState({
|
||||
receivers: configState.receivers?.filter((_: any, i: number) => i !== index) || [],
|
||||
});
|
||||
};
|
||||
|
||||
const validateEmail = (email: string): boolean => {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -132,19 +111,6 @@ export const EmailConfigForm: React.FC<ConfigComponentProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TagList
|
||||
tags={configState.receivers || []}
|
||||
newTag={configState.newReceiver || ''}
|
||||
label="默认收件人(可选)"
|
||||
placeholder="输入邮箱地址"
|
||||
inputType="email"
|
||||
maxTags={50}
|
||||
onNewTagChange={(value) => updateConfigState({ newReceiver: value })}
|
||||
onAddTag={handleAddReceiver}
|
||||
onRemoveTag={handleRemoveReceiver}
|
||||
validate={validateEmail}
|
||||
validationError="请输入有效的邮箱地址格式"
|
||||
/>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Switch
|
||||
|
||||
@ -4,49 +4,12 @@
|
||||
import React from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { TagList } from '@/components/ui/tag-list';
|
||||
import type { ConfigComponentProps } from '../config-strategies/types';
|
||||
|
||||
export const WeworkConfigForm: React.FC<ConfigComponentProps> = ({
|
||||
register,
|
||||
errors,
|
||||
configState,
|
||||
updateConfigState,
|
||||
}) => {
|
||||
const handleAddMobile = () => {
|
||||
if (configState.newMobile?.trim() && !configState.mentionedMobiles?.includes(configState.newMobile.trim())) {
|
||||
updateConfigState({
|
||||
mentionedMobiles: [...(configState.mentionedMobiles || []), configState.newMobile.trim()],
|
||||
newMobile: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveMobile = (index: number) => {
|
||||
updateConfigState({
|
||||
mentionedMobiles: configState.mentionedMobiles?.filter((_: any, i: number) => i !== index) || [],
|
||||
});
|
||||
};
|
||||
|
||||
const handleAddUser = () => {
|
||||
if (configState.newUser?.trim() && !configState.mentionedUsers?.includes(configState.newUser.trim())) {
|
||||
updateConfigState({
|
||||
mentionedUsers: [...(configState.mentionedUsers || []), configState.newUser.trim()],
|
||||
newUser: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveUser = (index: number) => {
|
||||
updateConfigState({
|
||||
mentionedUsers: configState.mentionedUsers?.filter((_: any, i: number) => i !== index) || [],
|
||||
});
|
||||
};
|
||||
|
||||
const validateMobile = (mobile: string): boolean => {
|
||||
return /^1[3-9]\d{9}$/.test(mobile);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
@ -67,31 +30,6 @@ export const WeworkConfigForm: React.FC<ConfigComponentProps> = ({
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<TagList
|
||||
tags={configState.mentionedMobiles || []}
|
||||
newTag={configState.newMobile || ''}
|
||||
label="@手机号列表(可选)"
|
||||
placeholder="输入手机号"
|
||||
inputType="tel"
|
||||
maxTags={10}
|
||||
onNewTagChange={(value) => updateConfigState({ newMobile: value })}
|
||||
onAddTag={handleAddMobile}
|
||||
onRemoveTag={handleRemoveMobile}
|
||||
validate={validateMobile}
|
||||
validationError="请输入有效的手机号格式"
|
||||
/>
|
||||
|
||||
<TagList
|
||||
tags={configState.mentionedUsers || []}
|
||||
newTag={configState.newUser || ''}
|
||||
label="@用户列表(可选)"
|
||||
placeholder="输入用户ID或@all"
|
||||
maxTags={20}
|
||||
onNewTagChange={(value) => updateConfigState({ newUser: value })}
|
||||
onAddTag={handleAddUser}
|
||||
onRemoveTag={handleRemoveUser}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@ -30,23 +30,14 @@ export class EmailConfigStrategy implements ConfigStrategy {
|
||||
}
|
||||
|
||||
loadFromData(data: any): ConfigState {
|
||||
if (data.channelType === NotificationChannelType.EMAIL && isEmailConfig(data.config)) {
|
||||
return {
|
||||
receivers: data.config.defaultReceivers || [],
|
||||
newReceiver: '',
|
||||
};
|
||||
}
|
||||
return {
|
||||
receivers: [],
|
||||
newReceiver: '',
|
||||
};
|
||||
// 邮件配置不再需要额外的状态管理
|
||||
return {};
|
||||
}
|
||||
|
||||
buildConfig(state: ConfigState, formConfig: any): any {
|
||||
return {
|
||||
...formConfig,
|
||||
channelType: NotificationChannelType.EMAIL,
|
||||
defaultReceivers: state.receivers || [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,28 +22,14 @@ export class WeworkConfigStrategy implements ConfigStrategy {
|
||||
}
|
||||
|
||||
loadFromData(data: any): ConfigState {
|
||||
if (data.channelType === NotificationChannelType.WEWORK && isWeworkConfig(data.config)) {
|
||||
return {
|
||||
mentionedMobiles: data.config.mentionedMobileList || [],
|
||||
mentionedUsers: data.config.mentionedList || [],
|
||||
newMobile: '',
|
||||
newUser: '',
|
||||
};
|
||||
}
|
||||
return {
|
||||
mentionedMobiles: [],
|
||||
mentionedUsers: [],
|
||||
newMobile: '',
|
||||
newUser: '',
|
||||
};
|
||||
// 企业微信配置不再需要额外的状态管理
|
||||
return {};
|
||||
}
|
||||
|
||||
buildConfig(state: ConfigState, formConfig: any): any {
|
||||
return {
|
||||
...formConfig,
|
||||
channelType: NotificationChannelType.WEWORK,
|
||||
mentionedMobileList: state.mentionedMobiles || [],
|
||||
mentionedList: state.mentionedUsers || [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,8 +10,6 @@ const weworkConfigSchema = z.object({
|
||||
key: z.string()
|
||||
.min(1, '请输入Webhook Key')
|
||||
.regex(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i, '请输入有效的UUID格式Key'),
|
||||
mentionedMobileList: z.array(z.string()).optional(),
|
||||
mentionedList: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
// 邮件配置 Schema
|
||||
@ -26,7 +24,6 @@ const emailConfigSchema = z.object({
|
||||
password: z.string().min(1, '请输入密码'),
|
||||
from: z.string().email('请输入有效的邮箱地址'),
|
||||
fromName: z.string().optional(),
|
||||
defaultReceivers: z.array(z.string().email()).optional(),
|
||||
useSsl: z.boolean().optional(),
|
||||
});
|
||||
|
||||
|
||||
@ -33,17 +33,6 @@ export interface WeworkNotificationConfigDTO extends BaseNotificationConfigDTO {
|
||||
* 完整URL格式: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={key}
|
||||
*/
|
||||
key: string;
|
||||
|
||||
/**
|
||||
* 默认@的手机号列表(可选)
|
||||
*/
|
||||
mentionedMobileList?: string[];
|
||||
|
||||
/**
|
||||
* 默认@的用户列表(可选)
|
||||
* 例如:["@all"] 表示@所有人
|
||||
*/
|
||||
mentionedList?: string[];
|
||||
}
|
||||
|
||||
// ============================================
|
||||
@ -71,9 +60,6 @@ export interface EmailNotificationConfigDTO extends BaseNotificationConfigDTO {
|
||||
/** 发件人名称(可选) */
|
||||
fromName?: string;
|
||||
|
||||
/** 默认收件人列表(可选) */
|
||||
defaultReceivers?: string[];
|
||||
|
||||
/** 是否使用SSL(可选,默认true) */
|
||||
useSsl?: boolean;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user