Enhance audience management features with new components and API integrations
- Added `AssignCoursesModal`, `AudienceMemberRow`, `AudienceTable`, and related components for improved audience management UI. - Implemented audience invite actions including resend and revoke functionality. - Updated audience API to support importing members and assigning courses. - Refactored audience data handling to include status and invite management. - Improved overall user experience with pagination and selection features in the audience table.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
export type AudienceMemberStatus = 'active' | 'pending' | 'expired' | 'revoked';
|
||||
|
||||
export function deriveAudienceMemberStatus(
|
||||
profileId: string | null,
|
||||
invite: { acceptedAt: string | null; isRevoked: boolean; expiresAt: string } | undefined
|
||||
): AudienceMemberStatus {
|
||||
if (profileId) {
|
||||
return 'active';
|
||||
}
|
||||
if (invite?.acceptedAt) {
|
||||
return 'active';
|
||||
}
|
||||
if (!invite) {
|
||||
return 'pending';
|
||||
}
|
||||
if (invite.isRevoked) {
|
||||
return 'revoked';
|
||||
}
|
||||
if (new Date(invite.expiresAt) <= new Date()) {
|
||||
return 'expired';
|
||||
}
|
||||
return 'pending';
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/** Normalize JSONB organization-invite metadata for course ids (matches importAudienceMembers storage). */
|
||||
export function parseCourseIdsFromInviteMetadata(metadata: unknown): string[] {
|
||||
let obj: Record<string, unknown> | null = null;
|
||||
if (metadata == null) {
|
||||
return [];
|
||||
}
|
||||
if (typeof metadata === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(metadata) as unknown;
|
||||
obj = typeof parsed === 'object' && parsed !== null ? (parsed as Record<string, unknown>) : null;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
} else if (typeof metadata === 'object') {
|
||||
obj = metadata as Record<string, unknown>;
|
||||
}
|
||||
if (!obj) {
|
||||
return [];
|
||||
}
|
||||
const raw = obj.courseIds ?? obj.course_ids;
|
||||
if (!Array.isArray(raw)) {
|
||||
return [];
|
||||
}
|
||||
return raw.filter((id): id is string => typeof id === 'string' && id.length > 0);
|
||||
}
|
||||
Reference in New Issue
Block a user