fix: validate signatures and restore report metrics
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
type ClientSmsSignatureView,
|
||||
type FileRef,
|
||||
} from '@/api/adminApi';
|
||||
import { isCompleteSmsSignature } from '@/utils/smsSignature';
|
||||
import { getSmsSignatureValidationError, hasForbiddenSmsSignatureCharacter, isCompleteSmsSignature, SMS_SIGNATURE_CHARACTER_ERROR } from '@/utils/smsSignature';
|
||||
|
||||
const EMPTY_WORKSPACE: ClientSignatureWorkspace = {
|
||||
items: [],
|
||||
@@ -98,6 +98,7 @@ function SignatureModal({
|
||||
const [uploadingCode, setUploadingCode] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [nameInputError, setNameInputError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const request = applicationId
|
||||
@@ -122,7 +123,7 @@ function SignatureModal({
|
||||
|
||||
async function save() {
|
||||
if (!isCompleteSmsSignature(name)) {
|
||||
setError('短信签名必须包含完整中文黑括号,例如:【某某科技】');
|
||||
setError(getSmsSignatureValidationError(name) ?? '短信签名格式不正确');
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -143,7 +144,8 @@ function SignatureModal({
|
||||
}
|
||||
|
||||
const missingRequired = fields.some((field) => field.required && !values[field.code]);
|
||||
const signatureNameValid = isCompleteSmsSignature(name);
|
||||
const signatureNameValid = !nameInputError && isCompleteSmsSignature(name);
|
||||
const signatureNameError = nameInputError || (name ? getSmsSignatureValidationError(name) : undefined);
|
||||
return <Modal
|
||||
footer={<><Button onClick={onClose} variant="ghost">取消</Button><Button disabled={!signatureNameValid || missingRequired || saving || Boolean(uploadingCode)} onClick={() => void save()}>{saving ? '提交中...' : '提交审核'}</Button></>}
|
||||
onClose={onClose}
|
||||
@@ -160,10 +162,18 @@ function SignatureModal({
|
||||
value={applicationId}
|
||||
/>
|
||||
<Input
|
||||
error={name.trim() && !signatureNameValid ? '必须填写完整中文黑括号签名,例如:【某某科技】' : undefined}
|
||||
hint="新增和编辑时都必须保留完整的【】"
|
||||
error={signatureNameError}
|
||||
hint="新增和编辑时必须保留完整的【】,且不能包含空格或不可见字符"
|
||||
label="短信签名"
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
onChange={(event) => {
|
||||
const value = event.target.value;
|
||||
if (hasForbiddenSmsSignatureCharacter(value)) {
|
||||
setNameInputError(SMS_SIGNATURE_CHARACTER_ERROR);
|
||||
return;
|
||||
}
|
||||
setNameInputError('');
|
||||
setName(value);
|
||||
}}
|
||||
placeholder="请输入完整签名,例如:【某某科技】"
|
||||
required
|
||||
value={name}
|
||||
|
||||
Reference in New Issue
Block a user