管理员可在周报页先发一封测试邮件验证邮箱配置;测试不写入发送记录、不改变确认状态,也不会把该周标记为已发送。
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user