Refactor Org Inbox Context and Enhance Club Creation Management
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 42s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Failing after 1m21s
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Successful in 42s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Failing after 1m21s
- Updated the OrgInboxContext to include handling for club creation requests, allowing for better management of inbox items. - Refactored components to utilize the new `canShowInboxNav` and `canAccessClubCreationInbox` flags for improved access control. - Enhanced the InboxPage to display club creation requests with appropriate actions for approval and rejection. - Updated the DashboardOrgInboxWidget to show both club creation and join requests, improving the user interface for managing inbox items.
This commit is contained in:
1 parent
8ee8f52e0f
commit
37785135b1
5 files changed
+206
-28
No files matched your search
@@ -17,6 +17,11 @@ export function canAccessOrgInbox(user) {
|
||||
return activeClubMemberships(user.clubs).some((c) => (c.roles || []).includes('club_admin'))
|
||||
}
|
||||
|
||||
/** Gründungsanträge freigeben — aktuell nur Superadmin (platform.club_creation.approve). */
|
||||
export function canAccessClubCreationInbox(user) {
|
||||
return user?.role === 'superadmin'
|
||||
}
|
||||
|
||||
function canSeeContentReports(user) {
|
||||
if (user?.role === 'admin' || user?.role === 'superadmin') return true
|
||||
return activeClubMemberships(user?.clubs || []).some((c) => (c.roles || []).includes('club_admin'))
|
||||
@@ -28,8 +33,13 @@ export function notifyOrgInboxChanged() {
|
||||
}
|
||||
|
||||
/** Eine konsistente Ladepfad-Logik für Join-Requests + Content-Reports (ein Codepfad für Mount + refresh). */
|
||||
async function fetchOrgInboxSnapshot(canAccess, canAccessReports) {
|
||||
const out = { items: [], contentReports: [], contentReportsError: null }
|
||||
async function fetchOrgInboxSnapshot(canAccess, canAccessReports, canAccessClubCreation) {
|
||||
const out = {
|
||||
items: [],
|
||||
clubCreationRequests: [],
|
||||
contentReports: [],
|
||||
contentReportsError: null,
|
||||
}
|
||||
if (canAccess) {
|
||||
try {
|
||||
const data = await api.getInboxJoinRequests()
|
||||
@@ -38,6 +48,14 @@ async function fetchOrgInboxSnapshot(canAccess, canAccessReports) {
|
||||
out.items = []
|
||||
}
|
||||
}
|
||||
if (canAccessClubCreation) {
|
||||
try {
|
||||
const data = await api.listAdminClubCreationRequests()
|
||||
out.clubCreationRequests = Array.isArray(data) ? data : []
|
||||
} catch {
|
||||
out.clubCreationRequests = []
|
||||
}
|
||||
}
|
||||
if (canAccessReports) {
|
||||
try {
|
||||
const data = await api.getInboxContentReports()
|
||||
@@ -52,27 +70,33 @@ async function fetchOrgInboxSnapshot(canAccess, canAccessReports) {
|
||||
|
||||
export function OrgInboxProvider({ user, children }) {
|
||||
const [items, setItems] = useState([])
|
||||
const [clubCreationRequests, setClubCreationRequests] = useState([])
|
||||
const [contentReports, setContentReports] = useState([])
|
||||
const [contentReportsError, setContentReportsError] = useState(null)
|
||||
const canAccess = useMemo(() => canAccessOrgInbox(user), [user])
|
||||
const canAccessReports = useMemo(() => canSeeContentReports(user), [user])
|
||||
const canAccessClubCreation = useMemo(() => canAccessClubCreationInbox(user), [user])
|
||||
const hasInboxAccess = canAccess || canAccessReports || canAccessClubCreation
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
if (!canAccess && !canAccessReports) {
|
||||
if (!hasInboxAccess) {
|
||||
setItems([])
|
||||
setClubCreationRequests([])
|
||||
setContentReports([])
|
||||
setContentReportsError(null)
|
||||
return
|
||||
}
|
||||
const snap = await fetchOrgInboxSnapshot(canAccess, canAccessReports)
|
||||
const snap = await fetchOrgInboxSnapshot(canAccess, canAccessReports, canAccessClubCreation)
|
||||
setItems(snap.items)
|
||||
setClubCreationRequests(snap.clubCreationRequests)
|
||||
setContentReports(snap.contentReports)
|
||||
setContentReportsError(canAccessReports ? snap.contentReportsError : null)
|
||||
}, [canAccess, canAccessReports])
|
||||
}, [hasInboxAccess, canAccess, canAccessReports, canAccessClubCreation])
|
||||
|
||||
useEffect(() => {
|
||||
if (!canAccess && !canAccessReports) {
|
||||
if (!hasInboxAccess) {
|
||||
setItems([])
|
||||
setClubCreationRequests([])
|
||||
setContentReports([])
|
||||
setContentReportsError(null)
|
||||
return undefined
|
||||
@@ -82,9 +106,10 @@ export function OrgInboxProvider({ user, children }) {
|
||||
let timeoutId = null
|
||||
|
||||
const load = async () => {
|
||||
const snap = await fetchOrgInboxSnapshot(canAccess, canAccessReports)
|
||||
const snap = await fetchOrgInboxSnapshot(canAccess, canAccessReports, canAccessClubCreation)
|
||||
if (cancelled) return
|
||||
setItems(snap.items)
|
||||
setClubCreationRequests(snap.clubCreationRequests)
|
||||
setContentReports(snap.contentReports)
|
||||
setContentReportsError(canAccessReports ? snap.contentReportsError : null)
|
||||
}
|
||||
@@ -116,7 +141,7 @@ export function OrgInboxProvider({ user, children }) {
|
||||
}
|
||||
if (timeoutId != null) window.clearTimeout(timeoutId)
|
||||
}
|
||||
}, [canAccess, canAccessReports, user?.id])
|
||||
}, [hasInboxAccess, canAccess, canAccessReports, canAccessClubCreation, user?.id])
|
||||
|
||||
useEffect(() => {
|
||||
const onChange = () => { refresh() }
|
||||
@@ -124,21 +149,42 @@ export function OrgInboxProvider({ user, children }) {
|
||||
return () => window.removeEventListener('shinkan:inbox-changed', onChange)
|
||||
}, [refresh])
|
||||
|
||||
const clubCreationCount = clubCreationRequests.length
|
||||
const joinCount = items.length
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
inboxJoinRequests: items,
|
||||
inboxCount: items.length,
|
||||
inboxClubCreationRequests: clubCreationRequests,
|
||||
clubCreationRequestCount: clubCreationCount,
|
||||
inboxCount: joinCount + clubCreationCount,
|
||||
contentReports,
|
||||
contentReportCount: contentReports.filter((r) => r.status === 'submitted').length,
|
||||
contentReportsError,
|
||||
refreshOrgInbox: refresh,
|
||||
canAccessOrgInbox: canAccess,
|
||||
canAccessContentReports: canAccessReports,
|
||||
canAccessClubCreationInbox: canAccessClubCreation,
|
||||
canShowInboxNav: hasInboxAccess,
|
||||
isSuperadmin: user?.role === 'superadmin',
|
||||
isPlatformAdmin: user?.role === 'admin' || user?.role === 'superadmin',
|
||||
isClubAdmin: activeClubMemberships(user?.clubs || []).some((c) => (c.roles || []).includes('club_admin')),
|
||||
}),
|
||||
[items, contentReports, contentReportsError, refresh, canAccess, canAccessReports, user?.role, user?.clubs]
|
||||
[
|
||||
items,
|
||||
clubCreationRequests,
|
||||
clubCreationCount,
|
||||
joinCount,
|
||||
contentReports,
|
||||
contentReportsError,
|
||||
refresh,
|
||||
canAccess,
|
||||
canAccessReports,
|
||||
canAccessClubCreation,
|
||||
hasInboxAccess,
|
||||
user?.role,
|
||||
user?.clubs,
|
||||
]
|
||||
)
|
||||
|
||||
return <OrgInboxContext.Provider value={value}>{children}</OrgInboxContext.Provider>
|
||||
|
||||
Reference in new issue
Block a user