mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-28 10:35:21 +02:00
feat: implement invitation email functionality for organization creation
- Added `sendInvitationEmail` function to send invitation emails when a new organization is created in the cloud environment. - Updated email template to enhance the invitation message and included a direct link for users to accept the invitation. - Refactored email sending logic in the user router to utilize the new invitation email rendering function. - Improved organization invitation email design for better user experience.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { db } from "@dokploy/server/db";
|
||||
import { IS_CLOUD } from "@dokploy/server/index";
|
||||
import { IS_CLOUD, sendInvitationEmail } from "@dokploy/server/index";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { and, desc, eq, exists } from "drizzle-orm";
|
||||
import { nanoid } from "nanoid";
|
||||
@@ -325,6 +325,24 @@ export const organizationRouter = createTRPCRouter({
|
||||
})
|
||||
.returning();
|
||||
|
||||
if (IS_CLOUD && created) {
|
||||
const host =
|
||||
process.env.NODE_ENV === "development"
|
||||
? "http://localhost:3000"
|
||||
: "https://app.dokploy.com";
|
||||
const inviteLink = `${host}/invitation?token=${created.id}`;
|
||||
|
||||
const org = await db.query.organization.findFirst({
|
||||
where: eq(organization.id, orgId),
|
||||
});
|
||||
|
||||
await sendInvitationEmail({
|
||||
email,
|
||||
inviteLink,
|
||||
organizationName: org?.name || "organization",
|
||||
});
|
||||
}
|
||||
|
||||
await audit(ctx, {
|
||||
action: "create",
|
||||
resourceType: "organization",
|
||||
|
||||
@@ -9,12 +9,12 @@ import {
|
||||
getWebServerSettings,
|
||||
IS_CLOUD,
|
||||
removeUserById,
|
||||
renderInvitationEmail,
|
||||
sendEmailNotification,
|
||||
sendResendNotification,
|
||||
updateUser,
|
||||
} from "@dokploy/server";
|
||||
import { db } from "@dokploy/server/db";
|
||||
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
|
||||
import {
|
||||
account,
|
||||
apiAssignPermissions,
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
hasPermission,
|
||||
resolvePermissions,
|
||||
} from "@dokploy/server/services/permission";
|
||||
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import * as bcrypt from "bcrypt";
|
||||
import { and, asc, eq, gt } from "drizzle-orm";
|
||||
@@ -639,27 +640,26 @@ export const userRouter = createTRPCRouter({
|
||||
);
|
||||
|
||||
try {
|
||||
const htmlContent = `
|
||||
\t\t\t\t<p>You are invited to join ${organization?.name || "organization"} on Dokploy. Click the link to accept the invitation: <a href="${inviteLink}">Accept Invitation</a></p>
|
||||
\t\t\t\t`;
|
||||
const toEmail = currentInvitation?.email || "";
|
||||
const orgName = organization?.name || "organization";
|
||||
const subject = `You've been invited to join ${orgName} on Dokploy`;
|
||||
const html = await renderInvitationEmail({
|
||||
email: toEmail,
|
||||
inviteLink,
|
||||
organizationName: orgName,
|
||||
});
|
||||
|
||||
if (email) {
|
||||
await sendEmailNotification(
|
||||
{
|
||||
...email,
|
||||
toAddresses: [currentInvitation?.email || ""],
|
||||
},
|
||||
"Invitation to join organization",
|
||||
htmlContent,
|
||||
{ ...email, toAddresses: [toEmail] },
|
||||
subject,
|
||||
html,
|
||||
);
|
||||
} else if (resend) {
|
||||
await sendResendNotification(
|
||||
{
|
||||
...resend,
|
||||
toAddresses: [currentInvitation?.email || ""],
|
||||
},
|
||||
"Invitation to join organization",
|
||||
htmlContent,
|
||||
{ ...resend, toAddresses: [toEmail] },
|
||||
subject,
|
||||
html,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user