-
Notifications
You must be signed in to change notification settings - Fork 248
CS-60 [Improvement] [Feature] - Send onboarding email for new employee #2102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cb7e7d6
6a45bf5
25e7c67
602c001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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: { | ||
|
|
@@ -112,7 +123,37 @@ export const addEmployeeWithoutInvite = async ({ | |
| await createTrainingVideoEntries(member.id); | ||
| } | ||
|
|
||
| return { success: true, data: member }; | ||
| // 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}`; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invite link uses wrong domainHigh Severity
|
||
| // Send the invitation email (non-fatal: member is already created) | ||
| let emailSent = true; | ||
| let emailError: string | undefined; | ||
| try { | ||
| await sendInviteMemberEmail({ | ||
| inviteeEmail: email.toLowerCase(), | ||
| inviteLink, | ||
| organizationName: organization.name, | ||
| }); | ||
| } catch (emailErr) { | ||
| emailSent = false; | ||
| emailError = emailErr instanceof Error ? emailErr.message : 'Failed to send invite email'; | ||
| console.error('Invite email failed after member was added:', { email, organizationId, error: emailErr }); | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| data: member, | ||
| emailSent, | ||
| ...(emailError && { emailError }), | ||
| }; | ||
| } catch (error) { | ||
| console.error('Error adding employee:', error); | ||
| return { success: false, error: 'Failed to add employee' }; | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.