mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
refactor(admin): share the invite link status between desktop and phone
Whether an invite is expired, used up or active, and which status label it shows, was worked out in both user views. It now lives in inviteStatus in the admin model; each view keeps its own row markup.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/** Shared types for the admin page + its data hook. No React, no side effects. */
|
||||
/** Shared types and pure helpers for the admin page + its data hook. No React, no side effects. */
|
||||
|
||||
export interface AdminUser {
|
||||
id: number
|
||||
@@ -36,3 +36,23 @@ export interface UpdateInfo {
|
||||
is_docker?: boolean
|
||||
is_prerelease?: boolean
|
||||
}
|
||||
|
||||
export interface InviteStatus {
|
||||
isExpired: boolean
|
||||
isUsedUp: boolean
|
||||
isActive: boolean
|
||||
/** i18n key of the status pill: used up wins over expired. */
|
||||
labelKey: 'admin.invite.usedUp' | 'admin.invite.expired' | 'admin.invite.active'
|
||||
}
|
||||
|
||||
/** Where an invite link stands: expired, used up (max_uses 0 is unlimited) or still active. */
|
||||
export function inviteStatus(
|
||||
invite: { expires_at?: string | null; max_uses: number; used_count: number },
|
||||
now: Date = new Date(),
|
||||
): InviteStatus {
|
||||
const isExpired = !!invite.expires_at && new Date(invite.expires_at) < now
|
||||
const isUsedUp = invite.max_uses > 0 && invite.used_count >= invite.max_uses
|
||||
const isActive = !isExpired && !isUsedUp
|
||||
const labelKey = isUsedUp ? 'admin.invite.usedUp' : isExpired ? 'admin.invite.expired' : 'admin.invite.active'
|
||||
return { isExpired, isUsedUp, isActive, labelKey }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user