feat(qa): 周报邮件支持立即发送测试
build / build (push) Successful in 1m17s

管理员可在周报页先发一封测试邮件验证邮箱配置;测试不写入发送记录、不改变确认状态,也不会把该周标记为已发送。
This commit is contained in:
hermes
2026-10-26 15:31:46 +08:00
parent eed83039ab
commit 600e9a2dc2
6 changed files with 106 additions and 3 deletions
+24 -3
View File
@@ -6,6 +6,7 @@ import {
fetchWeeklyMailSends,
fetchWeeklyMailSettings,
saveWeeklyMailSettings,
sendWeeklyMailTest,
weeklyMailWeekdayLabels,
} from './qaWeeklyMail'
import type { WeeklyMailConfirmation, WeeklyMailSend, WeeklyMailSettings } from './qaWeeklyMail'
@@ -23,6 +24,7 @@ export function QAWeeklyMail({ week, busy }: { week: string; busy: boolean }) {
const [notice, setNotice] = useState('')
const [working, setWorking] = useState(false)
const [editing, setEditing] = useState(false)
const [testing, setTesting] = useState(false)
const reload = useCallback(async () => {
setError('')
@@ -61,6 +63,20 @@ export function QAWeeklyMail({ week, busy }: { week: string; busy: boolean }) {
}
}
const testSend = async () => {
if (testing) return
setTesting(true)
setError('')
setNotice('')
try {
const id = await sendWeeklyMailTest(week)
setNotice(`测试邮件已发出(${id});成功后不影响正式发送记录`)
} catch (reason) {
setError(reason instanceof Error ? reason.message : '测试发送失败')
} finally {
setTesting(false)
}
}
const stale = confirmation !== null && !confirmation.current
return (
<section className="qa-weekly-mail" aria-label="周报自动发送">
@@ -84,9 +100,14 @@ export function QAWeeklyMail({ week, busy }: { week: string; busy: boolean }) {
</button>
)}
{admin ? (
<button type="button" disabled={working} onClick={() => setEditing(!editing)}>
{editing ? '收起发送设置' : '发送设置'}
</button>
<>
<button type="button" disabled={working || testing} onClick={() => void testSend()}>
{testing ? '正在发送测试…' : '发送测试邮件'}
</button>
<button type="button" disabled={working} onClick={() => setEditing(!editing)}>
{editing ? '收起发送设置' : '发送设置'}
</button>
</>
) : null}
</div>
</header>
+10
View File
@@ -152,3 +152,13 @@ export async function fetchWeeklyMailSends(week: string): Promise<WeeklyMailSend
}
export const weeklyMailWeekdayLabels = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
export async function sendWeeklyMailTest(week: string): Promise<string> {
const payload = (await getPayload(endpoint('test'), undefined, {
method: 'POST',
headers,
body: JSON.stringify({ week }),
})) as { message_id: string }
if (typeof payload.message_id !== 'string' || !payload.message_id) bad()
return payload.message_id
}