Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ model agents {
deleted_at DateTime?
/// @prismabox.hide
organization_id String
/// @prismabox.hide
/// @prismabox.input.hide
team_id String
}

Expand Down
3 changes: 2 additions & 1 deletion apps/console/app/lib/auth/better-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ export const authService: AuthService = {
globalThis.location.replace("/");
},

async inviteMember(email, role) {
async inviteMember(email, role, teamId) {
const { error } = await authClient.organization.inviteMember({
email,
role: role as "member" | "admin" | "owner",
...(teamId && { teamId }),
Comment thread
heiwen marked this conversation as resolved.
});
if (error) throw new Error(error.message);
},
Expand Down
2 changes: 1 addition & 1 deletion apps/console/app/lib/auth/dummy-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const authService = {
globalThis.location.replace("/");
},

async inviteMember(email, role) {
async inviteMember(email, role, _teamId) {
const organizationId = shellStore.user?.organizationId;
if (!organizationId) throw new Error("No active organization");
void invitations.create({
Expand Down
2 changes: 1 addition & 1 deletion apps/console/app/lib/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface AuthService {
// Organization
getOrganization(): Promise<{ members: OrgMember[]; invitations: OrgInvitation[] }>;
setActiveOrganization(orgId: string): Promise<void>;
inviteMember(email: string, role: string): Promise<void>;
inviteMember(email: string, role: string, teamId?: string): Promise<void>;
removeMember(memberIdOrEmail: string): Promise<void>;
cancelInvitation(invitationId: string): Promise<void>;
acceptInvitation(invitationId: string): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export async function clientAction({ request }: { request: Request }) {
if (intent === "invite") {
const submission = parseWithZod(formData, { schema: inviteSchema });
if (submission.status !== "success") return { intent, submission: submission.reply() };
const teamId = formData.get("teamId");
try {
await authService.inviteMember(submission.value.email, submission.value.role);
await authService.inviteMember(
submission.value.email,
submission.value.role,
typeof teamId === "string" ? teamId : undefined,
);
} catch (error) {
return { intent, submission: submission.reply({ formErrors: [parseError(error).message] }) };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ type MembersSettingsProps = {
invitations: OrgInvitation[];
isOwner: boolean;
canManage: boolean;
agent: { team_id: string };
};

export function MembersSettings({
members,
invitations,
isOwner,
canManage,
agent,
}: MembersSettingsProps) {
const fetcher = useFetcher<{ intent: string; submission: any }>();
const [role, setRole] = useState("member");
Expand Down Expand Up @@ -159,6 +160,7 @@ export function MembersSettings({
className="flex items-end gap-3"
>
<input type="hidden" name="intent" value="invite" />
<input type="hidden" name="teamId" value={agent.team_id} />
Comment thread
heiwen marked this conversation as resolved.
<Field name={fields.email.name} className="flex-1">
<FieldLabel>Email</FieldLabel>
<FieldControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function Settings({ loaderData }: Route.ComponentProps) {
invitations={loaderData.invitations}
isOwner={loaderData.isOwner}
canManage={loaderData.canManage}
agent={agent}
/>
<DangerSettings agent={agent} />
</div>
Expand Down