feat: invite workspace members via link (#196)
* feat: add workspace invite links schema * feat: update workspace invite schema * feat: add repo funcs and share link toggle * feat: redirect to next param on authentication * feat: add invite page * feat: switch to workspace on invite success * refactor: tweak light mode styles * feat(cloud): update subscription for cloud * feat: only allow admin users to create links * chore: add translations
This commit is contained in:
71
packages/db/src/repository/inviteLink.repo.ts
Normal file
71
packages/db/src/repository/inviteLink.repo.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { and, eq, gt } from "drizzle-orm";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import { workspaceInviteLinks } from "@kan/db/schema";
|
||||
import { generateUID } from "@kan/shared/utils";
|
||||
|
||||
export const createInviteLink = async (
|
||||
db: dbClient,
|
||||
args: {
|
||||
workspaceId: number;
|
||||
code: string;
|
||||
expiresAt: Date | null;
|
||||
createdBy: string;
|
||||
},
|
||||
) => {
|
||||
const [result] = await db
|
||||
.insert(workspaceInviteLinks)
|
||||
.values({
|
||||
publicId: generateUID(),
|
||||
workspaceId: args.workspaceId,
|
||||
code: args.code,
|
||||
expiresAt: args.expiresAt ?? null,
|
||||
status: "active",
|
||||
createdBy: args.createdBy,
|
||||
})
|
||||
.returning({
|
||||
publicId: workspaceInviteLinks.publicId,
|
||||
code: workspaceInviteLinks.code,
|
||||
status: workspaceInviteLinks.status,
|
||||
expiresAt: workspaceInviteLinks.expiresAt,
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
export const deactivateAllActiveForWorkspace = async (
|
||||
db: dbClient,
|
||||
args: { workspaceId: number; updatedBy: string },
|
||||
) => {
|
||||
await db
|
||||
.update(workspaceInviteLinks)
|
||||
.set({
|
||||
status: "inactive",
|
||||
updatedBy: args.updatedBy,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(
|
||||
and(
|
||||
eq(workspaceInviteLinks.workspaceId, args.workspaceId),
|
||||
eq(workspaceInviteLinks.status, "active"),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
export const getActiveForWorkspace = async (
|
||||
db: dbClient,
|
||||
workspaceId: number,
|
||||
) => {
|
||||
return db.query.workspaceInviteLinks.findFirst({
|
||||
where: and(
|
||||
eq(workspaceInviteLinks.workspaceId, workspaceId),
|
||||
eq(workspaceInviteLinks.status, "active"),
|
||||
),
|
||||
orderBy: (links, { desc }) => [desc(links.createdAt)],
|
||||
});
|
||||
};
|
||||
|
||||
export const getByCode = async (db: dbClient, code: string) => {
|
||||
return db.query.workspaceInviteLinks.findFirst({
|
||||
where: eq(workspaceInviteLinks.code, code),
|
||||
});
|
||||
};
|
||||
@@ -87,11 +87,25 @@ export const getByPublicId = (db: dbClient, workspacePublicId: string) => {
|
||||
publicId: true,
|
||||
name: true,
|
||||
plan: true,
|
||||
slug: true,
|
||||
},
|
||||
where: eq(workspaces.publicId, workspacePublicId),
|
||||
});
|
||||
};
|
||||
|
||||
export const getById = (db: dbClient, workspaceId: number) => {
|
||||
return db.query.workspaces.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
publicId: true,
|
||||
name: true,
|
||||
plan: true,
|
||||
slug: true,
|
||||
},
|
||||
where: eq(workspaces.id, workspaceId),
|
||||
});
|
||||
};
|
||||
|
||||
export const getByPublicIdWithMembers = (
|
||||
db: dbClient,
|
||||
workspacePublicId: string,
|
||||
|
||||
Reference in New Issue
Block a user