Skip to content

Commit

Permalink
chore(console): Add 3 member upper limit to groups (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu authored Sep 18, 2023
1 parent 5e970d8 commit b3a04b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
14 changes: 9 additions & 5 deletions apps/console/app/routes/__layout/spuorg/$groupID/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export const ActionCard = ({
return (
<button
className={classNames(
'bg-white border rounded-lg shadow p-4 flex flex-row items-center gap-3.5',
{ 'hover:bg-gray-50': onClick }
'border rounded-lg shadow p-4 flex flex-row items-center gap-3.5',
{ 'hover:bg-gray-50 bg-white': onClick },
{ 'bg-gray-100': !onClick }
)}
disabled={!onClick}
onClick={onClick}
Expand Down Expand Up @@ -378,7 +379,6 @@ export default () => {
const [selectedMemberAlias, setSelectedMemberAlias] = useState<string>('')
const [removeMemberModalOpen, setRemoveMemberModalOpen] = useState(false)

const ownApps = apps.filter((a) => !a.groupID)
const groupApps = apps.filter((a) => a.groupID === groupID)

const navigate = useNavigate()
Expand Down Expand Up @@ -431,7 +431,11 @@ export default () => {
Icon={TbUserPlus}
title="Add Group Member"
subtitle="Invite Members to the Group"
onClick={() => setInviteModalOpen(true)}
onClick={
group.members.length + invitations.length < 3
? () => setInviteModalOpen(true)
: undefined
}
/>

<ActionCard
Expand Down Expand Up @@ -606,7 +610,7 @@ export default () => {

<Pill className="bg-gray-200 rounded-lg !pr-2">
<Text size="xs" weight="medium" className="text-gray-800">
{group.members.length}
{group.members.length}/3
</Text>
</Pill>
</div>
Expand Down
1 change: 1 addition & 0 deletions platform/identity/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const IDENTITY_GROUP_OPTIONS = {
length: 24,
inviteCodeLength: 16,
maxFreeMembers: 3,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { Context } from '../../../context'
import { InternalServerError } from '@proofzero/errors'
import { BadRequestError, InternalServerError } from '@proofzero/errors'
import {
CryptoAccountType,
EmailAccountType,
Expand All @@ -14,6 +14,7 @@ import { AccountURN, AccountURNSpace } from '@proofzero/urns/account'
import generateRandomString from '@proofzero/utils/generateRandomString'
import { IdentityURN } from '@proofzero/urns/identity'
import { createAnalyticsEvent } from '@proofzero/utils/analytics'
import { EDGE_MEMBER_OF_IDENTITY_GROUP } from '@proofzero/types/graph'

export const InviteIdentityGroupMemberInputSchema = z.object({
identityGroupURN: IdentityGroupURNValidator,
Expand Down Expand Up @@ -47,21 +48,40 @@ export const inviteIdentityGroupMember = async ({
const { identityGroupURN, identifier, accountType } = input
const inviterIdentityURN = ctx.identityURN as IdentityURN

const node = await initIdentityGroupNodeByName(
identityGroupURN,
ctx.IdentityGroup
)
const node = initIdentityGroupNodeByName(identityGroupURN, ctx.IdentityGroup)
if (!node) {
throw new InternalServerError({
message: 'Identity group DO not found',
})
}

const invitations = await node.class.getInvitations()
const invitationCount = invitations.length

const caller = router.createCaller(ctx)

const { edges: memberEdges } = await caller.edges.getEdges({
query: {
src: {
baseUrn: inviterIdentityURN,
},
tag: EDGE_MEMBER_OF_IDENTITY_GROUP,
},
})

if (
invitationCount + memberEdges.length >
IDENTITY_GROUP_OPTIONS.maxFreeMembers
) {
throw new BadRequestError({
message: 'Max members reached',
})
}

const inviteCode = generateRandomString(
IDENTITY_GROUP_OPTIONS.inviteCodeLength
)

const caller = router.createCaller(ctx)
const inviterProfile = await caller.identity.getProfile({
identity: inviterIdentityURN,
})
Expand Down

0 comments on commit b3a04b8

Please sign in to comment.