mirror of
https://github.com/beilunyang/moemail.git
synced 2026-07-08 07:41:47 +08:00
feat: Add configurable maximum email limit for users
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user