Skip to content
Merged
Changes from 1 commit
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 @@ -2,6 +2,7 @@

import { createTrainingVideoEntries } from '@/lib/db/employee';
import { auth } from '@/utils/auth';
import { sendInviteMemberEmail } from '@comp/email';
import type { Role } from '@db';
import { db } from '@db';
import { headers } from 'next/headers';
Expand Down Expand Up @@ -48,6 +49,16 @@ export const addEmployeeWithoutInvite = async ({
}
}

// Get organization name
const organization = await db.organization.findUnique({
where: { id: organizationId },
select: { name: true },
});

if (!organization) {
throw new Error('Organization not found.');
}

let userId = '';
const existingUser = await db.user.findFirst({
where: {
Expand Down Expand Up @@ -112,6 +123,23 @@ export const addEmployeeWithoutInvite = async ({
await createTrainingVideoEntries(member.id);
}

// Generate invite link
const isLocalhost = process.env.NODE_ENV === 'development';
const protocol = isLocalhost ? 'http' : 'https';

const betterAuthUrl = process.env.NEXT_PUBLIC_PORTAL_URL;
const isProdEnv = betterAuthUrl?.includes('portal.trycomp.ai');

const domain = isProdEnv ? 'app.trycomp.ai' : 'localhost:3002';
const inviteLink = `${protocol}://${domain}/${organizationId}`;

// Send the invitation email
await sendInviteMemberEmail({
inviteeEmail: email.toLowerCase(),
inviteLink,
organizationName: organization.name,
});

return { success: true, data: member };
} catch (error) {
console.error('Error adding employee:', error);
Expand Down