feat: Add configurable maximum email limit for users

This commit is contained in:
beilunyang
2025-02-28 00:16:06 +08:00
parent f86d944c25
commit b1d898e298
5 changed files with 60 additions and 12 deletions

View File

@@ -49,9 +49,22 @@ export function EmailList({ onEmailSelect, selectedEmailId }: EmailListProps) {
const [nextCursor, setNextCursor] = useState<string | null>(null)
const [loadingMore, setLoadingMore] = useState(false)
const [total, setTotal] = useState(0)
const [maxEmails, setMaxEmails] = useState<number>(EMAIL_CONFIG.MAX_ACTIVE_EMAILS)
const [emailToDelete, setEmailToDelete] = useState<Email | null>(null)
const { toast } = useToast()
const fetchMaxEmails = async () => {
try {
const res = await fetch("/api/config")
if (res.ok) {
const data = await res.json() as { maxEmails: string }
setMaxEmails(Number(data.maxEmails))
}
} catch (error) {
console.error("Failed to fetch max emails:", error)
}
}
const fetchEmails = async (cursor?: string) => {
try {
const url = new URL("/api/emails", window.location.origin)
@@ -112,6 +125,9 @@ export function EmailList({ onEmailSelect, selectedEmailId }: EmailListProps) {
useEffect(() => {
if (session) fetchEmails()
if (session && role !== ROLES.EMPEROR) {
fetchMaxEmails()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session])
@@ -173,7 +189,7 @@ export function EmailList({ onEmailSelect, selectedEmailId }: EmailListProps) {
{role === ROLES.EMPEROR ? (
`${total}/∞ 个邮箱`
) : (
`${total}/${EMAIL_CONFIG.MAX_ACTIVE_EMAILS} 个邮箱`
`${total}/${maxEmails} 个邮箱`
)}
</span>
</div>