Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export function MembersSettings({ visibleItems }: MembersSettingsProps) {
const { data: session } = authClient.useSession();
const collections = useCollections();
const activeOrganizationId = session?.session?.activeOrganizationId;
const { data: activeOrg } = authClient.useActiveOrganization();

const showMembersList = isItemVisible(
SETTING_ITEM_ID.MEMBERS_LIST,
Expand All @@ -59,6 +58,16 @@ export function MembersSettings({ visibleItems }: MembersSettingsProps) {
[collections, activeOrganizationId],
);

// Get organization name from collections
const { data: orgData } = useLiveQuery(
(q) =>
q
.from({ organizations: collections.organizations })
.select(({ organizations }) => ({ ...organizations })),
[collections],
);
const organization = orgData?.find((org) => org.id === activeOrganizationId);

// Sort by role priority (owner > admin > member), then by join date
// Cast roles to OrganizationRole since database stores them as strings
const members: TeamMember[] = (membersData ?? [])
Expand All @@ -75,10 +84,9 @@ export function MembersSettings({ visibleItems }: MembersSettingsProps) {
const ownerCount = members.filter((m) => m.role === "owner").length;

const currentUserId = session?.user?.id;
const currentMember = activeOrg?.members?.find(
(m) => m.userId === currentUserId,
);
const currentUserRole = currentMember?.role as OrganizationRole;
// Find current user's role from the members data we already fetched
const currentMember = members.find((m) => m.userId === currentUserId);
const currentUserRole = currentMember?.role;

const formatDate = (date: Date | string) => {
const d = date instanceof Date ? date : new Date(date);
Expand All @@ -101,13 +109,13 @@ export function MembersSettings({ visibleItems }: MembersSettingsProps) {

<div className="flex-1 overflow-auto">
<div className="p-8 space-y-12">
{currentUserRole && activeOrganizationId && activeOrg?.name && (
{currentUserRole && activeOrganizationId && organization?.name && (
<div className="max-w-5xl">
<PendingInvitations
visibleItems={visibleItems}
currentUserRole={currentUserRole}
organizationId={activeOrganizationId}
organizationName={activeOrg.name}
organizationName={organization.name}
/>
</div>
)}
Expand Down Expand Up @@ -194,18 +202,20 @@ export function MembersSettings({ visibleItems }: MembersSettingsProps) {
{formatDate(member.createdAt)}
</TableCell>
<TableCell>
<MemberActions
member={member}
currentUserRole={currentUserRole}
ownerCount={ownerCount}
isCurrentUser={isCurrentUserRow}
canRemove={canRemoveMember(
currentUserRole,
member.role as OrganizationRole,
isCurrentUserRow,
ownerCount,
)}
/>
{currentUserRole && (
<MemberActions
member={member}
currentUserRole={currentUserRole}
ownerCount={ownerCount}
isCurrentUser={isCurrentUserRow}
canRemove={canRemoveMember(
currentUserRole,
member.role,
isCurrentUserRow,
ownerCount,
)}
/>
)}
</TableCell>
</TableRow>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/auth/src/lib/accept-invitation-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export const acceptInvitationEndpoint = {
});

if (!user) {
const userName =
invitation.name || invitation.email.split("@")[0] || "User";
const userName = invitation.email;
const [newUser] = await db
.insert(users)
.values({
Expand Down
1 change: 0 additions & 1 deletion packages/db/src/schema/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export const invitations = authSchema.table(
.notNull()
.references(() => organizations.id, { onDelete: "cascade" }),
email: text("email").notNull(),
name: text("name"),
role: text("role"),
status: text("status").default("pending").notNull(),
expiresAt: timestamp("expires_at").notNull(),
Expand Down
1 change: 0 additions & 1 deletion packages/trpc/src/router/organization/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const organizationRouter = {
return {
id: invitation.id,
email: invitation.email,
name: invitation.name,
role: invitation.role,
status: invitation.status,
expiresAt: invitation.expiresAt,
Expand Down