Skip to content

Commit

Permalink
Invite links in store (keybase#23518)
Browse files Browse the repository at this point in the history
* put invite data in store

* add expired to obj

* oof. fix emptyTeamDetails

* Invite links in the team settings page (keybase#23517)

* invite links in settings page

* date-fns

* danny feedback

Co-authored-by: Jakob Weisblat <[email protected]>
  • Loading branch information
buoyad and aaazalea authored Apr 7, 2020
1 parent a2b96b4 commit 109ffd4
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 327 deletions.
81 changes: 52 additions & 29 deletions shared/constants/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -733,42 +733,65 @@ export const teamListToMeta = (
)
}

export const annotatedInvitesToInviteInfo = (
invites: Array<RPCTypes.AnnotatedTeamInvite>
): Array<Types.InviteInfo> =>
Object.values(invites).reduce<Array<Types.InviteInfo>>((arr, invite) => {
const role = teamRoleByEnum[invite.invite.role]
if (!role || role === 'none') {
return arr
}
type InviteDetails = {inviteLinks: Set<Types.InviteLink>; invites: Set<Types.InviteInfo>}
const annotatedInvitesToInviteDetails = (
invitesData: Array<RPCTypes.AnnotatedTeamInvite> = []
): InviteDetails =>
invitesData.reduce<InviteDetails>(
(invitesAndLinks, invite) => {
const {invites, inviteLinks} = invitesAndLinks
const role = teamRoleByEnum[invite.invite.role]
if (!role || role === 'none') {
return invitesAndLinks
}

let username = ''
if (invite.invite.type.c === RPCTypes.TeamInviteCategory.sbs) {
username = invite.displayName
}
arr.push({
email: invite.invite.type.c === RPCTypes.TeamInviteCategory.email ? invite.displayName : '',
id: invite.invite.id,
name: [RPCTypes.TeamInviteCategory.seitan, RPCTypes.TeamInviteCategory.invitelink].includes(
invite.invite.type.c
)
? invite.displayName
: '',
phone: invite.invite.type.c === RPCTypes.TeamInviteCategory.phone ? invite.displayName : '',
role,
username,
})
return arr
}, [])
if (invite.invite.type.c === RPCTypes.TeamInviteCategory.invitelink) {
const lastJoinedUsername = invite.usedInvites
? invite.usedInvites[invite.usedInvites.length - 1]?.username
: ''
inviteLinks.add({
creatorUsername: invite.inviterUsername,
expirationTime: invite.invite.etime ?? 0,
expired: Date.now() / 1000 > (invite.invite.etime ?? 0), // TODO Y2K-1715 get from invite
id: invite.invite.id,
lastJoinedUsername,
maxUses: invite.invite.maxUses ?? 0,
numUses: invite.usedInvites?.length ?? 0,
role,
url: invite.displayName,
})
} else {
let username = ''
if (invite.invite.type.c === RPCTypes.TeamInviteCategory.sbs) {
username = invite.displayName
}
invites.add({
email: invite.invite.type.c === RPCTypes.TeamInviteCategory.email ? invite.displayName : '',
id: invite.invite.id,
name: [RPCTypes.TeamInviteCategory.seitan, RPCTypes.TeamInviteCategory.invitelink].includes(
invite.invite.type.c
)
? invite.displayName
: '',
phone: invite.invite.type.c === RPCTypes.TeamInviteCategory.phone ? invite.displayName : '',
role,
username,
})
}
return invitesAndLinks
},
{inviteLinks: new Set(), invites: new Set()}
)

export const emptyTeamDetails = Object.freeze<Types.TeamDetails>({
export const emptyTeamDetails: Types.TeamDetails = {
description: '',
inviteLinks: new Set(),
invites: new Set(),
members: new Map(),
requests: new Set(),
settings: {open: false, openJoinAs: 'reader', tarsDisabled: false, teamShowcased: false},
subteams: new Set(),
} as Types.TeamDetails)
}

export const emptyTeamSettings = Object.freeze(emptyTeamDetails.settings)

Expand All @@ -790,8 +813,8 @@ export const annotatedTeamToDetails = (t: RPCTypes.AnnotatedTeam): Types.TeamDet
})
})
return {
...annotatedInvitesToInviteDetails(t.invites ?? undefined),
description: t.showcase.description ?? '',
invites: t.invites ? new Set(annotatedInvitesToInviteInfo(t.invites)) : new Set(),
members,
requests: t.joinRequests ? new Set(t.joinRequests) : new Set(),
settings: {
Expand Down
13 changes: 13 additions & 0 deletions shared/constants/types/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,23 @@ export type TeamMeta = {
teamname: string
}

export type InviteLink = {
creatorUsername: string
expirationTime: number // unix time
expired: boolean
id: string
lastJoinedUsername: string
maxUses: number
numUses: number
role: TeamRoleType
url: string
}

export type TeamDetails = {
members: Map<string, MemberInfo>
settings: TeamSettings2
invites: Set<InviteInfo>
inviteLinks: Set<InviteLink>
subteams: Set<TeamID>
requests: Set<JoinRequest>
description: string
Expand Down
Loading

0 comments on commit 109ffd4

Please sign in to comment.