-
Notifications
You must be signed in to change notification settings - Fork 3.7k
improvement(credentials): credentials invites, secrets tab wiring up #4874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
icecrasher321
merged 8 commits into
improvement/platform
from
improvement/credentials-auto-add
Jun 4, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cebde3a
improvement(credentials): move away from invite notion
icecrasher321 5d2bf30
wire up secrets ui/ux
icecrasher321 c03a3d4
Merge branch 'improvement/platform' into improvement/credentials-auto…
icecrasher321 27c862a
address comments
icecrasher321 3532f31
get consistent styling by removing emcninput + text area
icecrasher321 85408b7
styling consistency
icecrasher321 8e038d8
remove fallback
icecrasher321 e463a0c
address comment:
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
.../app/workspace/[workspaceId]/components/credential-detail/components/add-people-modal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| 'use client' | ||
|
|
||
| import { useCallback, useMemo, useState } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { getErrorMessage } from '@sim/utils/errors' | ||
| import { | ||
| Chip, | ||
| ChipModal, | ||
| ChipModalBody, | ||
| ChipModalField, | ||
| ChipModalFooter, | ||
| ChipModalHeader, | ||
| toast, | ||
| } from '@/components/emcn' | ||
| import { useWorkspacePermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider' | ||
| import { | ||
| useUpsertWorkspaceCredentialMember, | ||
| useWorkspaceCredentialMembers, | ||
| type WorkspaceCredentialRole, | ||
| } from '@/hooks/queries/credentials' | ||
| import { ROLE_OPTIONS } from '../roles' | ||
| import { partitionSettledFailures, resolveAddEmail } from '../sharing' | ||
|
|
||
| const logger = createLogger('AddPeopleModal') | ||
|
|
||
| interface AddPeopleModalProps { | ||
| credentialId: string | ||
| open: boolean | ||
| onOpenChange: (open: boolean) => void | ||
| } | ||
|
|
||
| /** | ||
| * Shared "Add people" modal: grants existing workspace members access to a | ||
| * credential with a chosen role. Emails are validated against the workspace | ||
| * roster and current membership; each add is an idempotent upsert and partial | ||
| * failures keep only the people that still need adding. | ||
| */ | ||
| export function AddPeopleModal({ credentialId, open, onOpenChange }: AddPeopleModalProps) { | ||
| const { workspacePermissions } = useWorkspacePermissionsContext() | ||
| const { data: members = [] } = useWorkspaceCredentialMembers(credentialId) | ||
| const upsertMember = useUpsertWorkspaceCredentialMember() | ||
|
|
||
| const [emailsToAdd, setEmailsToAdd] = useState<string[]>([]) | ||
| const [roleToAdd, setRoleToAdd] = useState<WorkspaceCredentialRole>('member') | ||
| const [isAdding, setIsAdding] = useState(false) | ||
|
|
||
| const workspaceUserIdByEmail = useMemo( | ||
| () => | ||
| new Map( | ||
| (workspacePermissions?.users ?? []).map((user) => [user.email.toLowerCase(), user.userId]) | ||
| ), | ||
| [workspacePermissions?.users] | ||
| ) | ||
|
|
||
| const existingMemberEmails = useMemo( | ||
| () => | ||
| new Set( | ||
| members | ||
| .filter((member) => member.status === 'active') | ||
| .map((member) => (member.userEmail ?? '').toLowerCase()) | ||
| .filter(Boolean) | ||
| ), | ||
| [members] | ||
| ) | ||
|
|
||
| const validateAddEmail = useCallback( | ||
| (email: string): string | null => { | ||
| const result = resolveAddEmail(email, { workspaceUserIdByEmail, existingMemberEmails }) | ||
| return 'error' in result ? result.error : null | ||
| }, | ||
| [workspaceUserIdByEmail, existingMemberEmails] | ||
| ) | ||
|
|
||
| const handleClose = useCallback(() => { | ||
| setEmailsToAdd([]) | ||
| setRoleToAdd('member') | ||
| onOpenChange(false) | ||
| }, [onOpenChange]) | ||
|
|
||
| const handleAddPeople = useCallback(async () => { | ||
| if (emailsToAdd.length === 0 || isAdding) return | ||
| const targets = emailsToAdd | ||
| .map((email) => { | ||
| const result = resolveAddEmail(email, { workspaceUserIdByEmail, existingMemberEmails }) | ||
| return 'userId' in result ? { email, userId: result.userId } : null | ||
| }) | ||
| .filter((target): target is { email: string; userId: string } => target !== null) | ||
| if (targets.length === 0) return | ||
|
|
||
| setIsAdding(true) | ||
| try { | ||
| const results = await Promise.allSettled( | ||
| targets.map((target) => | ||
| upsertMember.mutateAsync({ credentialId, userId: target.userId, role: roleToAdd }) | ||
| ) | ||
| ) | ||
| const failures = partitionSettledFailures(targets, results) | ||
| if (failures.length === 0) { | ||
| handleClose() | ||
| return | ||
| } | ||
| setEmailsToAdd(failures.map((target) => target.email)) | ||
| const firstError = results.find( | ||
| (result): result is PromiseRejectedResult => result.status === 'rejected' | ||
| ) | ||
| logger.error('Failed to add some credential members', firstError?.reason) | ||
| toast.error( | ||
| failures.length === targets.length | ||
| ? "Couldn't add people" | ||
| : `Couldn't add ${failures.length} of ${targets.length} people`, | ||
| { description: getErrorMessage(firstError?.reason, 'Please try again in a moment.') } | ||
| ) | ||
| } finally { | ||
| setIsAdding(false) | ||
| } | ||
| }, [ | ||
| credentialId, | ||
| emailsToAdd, | ||
| isAdding, | ||
| workspaceUserIdByEmail, | ||
| existingMemberEmails, | ||
| roleToAdd, | ||
| upsertMember, | ||
| handleClose, | ||
| ]) | ||
|
|
||
| return ( | ||
| <ChipModal | ||
| open={open} | ||
| onOpenChange={(next) => { | ||
| if (!next) handleClose() | ||
| }} | ||
| srTitle='Add people' | ||
| > | ||
| <ChipModalHeader onClose={handleClose}>Add people</ChipModalHeader> | ||
| <ChipModalBody> | ||
| <ChipModalField | ||
| type='emails' | ||
| title='Emails' | ||
| value={emailsToAdd} | ||
| onChange={setEmailsToAdd} | ||
| validate={validateAddEmail} | ||
| placeholder='Enter emails' | ||
| disabled={isAdding} | ||
| /> | ||
| <ChipModalField | ||
| type='dropdown' | ||
| title='Role' | ||
| options={ROLE_OPTIONS} | ||
| value={roleToAdd} | ||
| placeholder='Select role' | ||
| align='start' | ||
| onChange={(role) => setRoleToAdd(role as WorkspaceCredentialRole)} | ||
| disabled={isAdding} | ||
| /> | ||
| </ChipModalBody> | ||
| <ChipModalFooter> | ||
| <Chip | ||
| variant='primary' | ||
| onClick={handleAddPeople} | ||
| disabled={emailsToAdd.length === 0 || isAdding} | ||
| > | ||
| {isAdding ? 'Adding...' : 'Add'} | ||
| </Chip> | ||
| </ChipModalFooter> | ||
| </ChipModal> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.