summaryrefslogtreecommitdiff
path: root/components/project/dataroom-members.ts
diff options
context:
space:
mode:
Diffstat (limited to 'components/project/dataroom-members.ts')
-rw-r--r--components/project/dataroom-members.ts74
1 files changed, 74 insertions, 0 deletions
diff --git a/components/project/dataroom-members.ts b/components/project/dataroom-members.ts
new file mode 100644
index 00000000..2512a5cd
--- /dev/null
+++ b/components/project/dataroom-members.ts
@@ -0,0 +1,74 @@
+"use server";
+
+import { sendEmail } from "@/lib/mail/sendEmail";
+import { getServerSession } from "next-auth/next"
+import { authOptions } from "@/app/api/auth/[...nextauth]/route"
+
+
+interface SendDataRoomInvitationInput {
+ email: string;
+ name: string;
+ dataRoomName: string;
+ role: string;
+ dataRoomUrl?: string;
+}
+
+export async function sendDataRoomInvitation(input: SendDataRoomInvitationInput) {
+ try {
+ const session = await getServerSession(authOptions)
+ if (!session?.user?.id) {
+ throw new Error("인증이 필요합니다.")
+ }
+
+ const dataRoomUrl = input.dataRoomUrl || `${process.env.NEXT_PUBLIC_APP_URL}/data-rooms`;
+
+ const subject = `You've been invited to access "${input.dataRoomName}" Data Room`;
+
+ await sendEmail({
+ to: input.email,
+ subject,
+ template: "data-room-invitation",
+ context: {
+ name: input.name,
+ dataRoomName: input.dataRoomName,
+ role: input.role,
+ inviterName: session.user.name || "Admin",
+ dataRoomUrl,
+ loginUrl: `${process.env.NEXT_PUBLIC_APP_URL}/login`,
+ },
+ });
+
+ return { success: true, message: "Invitation email sent successfully" };
+ } catch (error) {
+ console.error("Failed to send data room invitation:", error);
+ return { success: false, message: "Failed to send invitation email" };
+ }
+}
+
+// 여러 멤버에게 동시에 이메일 전송
+export async function sendBulkDataRoomInvitations(
+ members: SendDataRoomInvitationInput[]
+) {
+ try {
+ const session = await getServerSession(authOptions)
+ if (!session?.user?.id) {
+ throw new Error("인증이 필요합니다.")
+ }
+
+ const results = await Promise.allSettled(
+ members.map((member) => sendDataRoomInvitation(member))
+ );
+
+ const successful = results.filter((r) => r.status === "fulfilled").length;
+ const failed = results.filter((r) => r.status === "rejected").length;
+
+ return {
+ success: true,
+ message: `Sent ${successful} invitations successfully. ${failed} failed.`,
+ details: { successful, failed, total: members.length },
+ };
+ } catch (error) {
+ console.error("Failed to send bulk invitations:", error);
+ return { success: false, message: "Failed to send invitations" };
+ }
+} \ No newline at end of file