Skip to content

Commit 6d3e1d1

Browse files
committed
feat(webapp): set workspace email_domain from admin email
1 parent 9e6e96b commit 6d3e1d1

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

apps/webapp/app/services/attio.server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from "zod";
2+
import { prisma } from "~/db.server";
23
import { env } from "~/env.server";
34
import { logger } from "./logger.server";
45

@@ -49,7 +50,7 @@ class AttioClient {
4950
return ((await response.json()) as any).data?.id?.record_id as string;
5051
}
5152

52-
async upsertWorkspace(payload: AttioWorkspaceSync) {
53+
async upsertWorkspace(payload: AttioWorkspaceSync, emailDomain?: string) {
5354
// The creating user is an admin of the new org — set their role and link them to the workspace.
5455
const adminRecordId = await this.#assert("users", "user_id", {
5556
user_id: payload.adminUserId,
@@ -62,6 +63,7 @@ class AttioClient {
6263
name: payload.title,
6364
org_slug: payload.slug,
6465
company_size: payload.companySize ?? undefined,
66+
email_domain: emailDomain,
6567
signup_date: toDate(payload.createdAt),
6668
plan: "Free",
6769
account_status: "Active",
@@ -87,6 +89,11 @@ function toDate(date: Date): string {
8789
return date.toISOString().slice(0, 10);
8890
}
8991

92+
// Domain from an email; the cloud-side matcher normalizes it further.
93+
function domainFromEmail(email: string | undefined): string | undefined {
94+
return email?.split("@")[1]?.toLowerCase().trim() || undefined;
95+
}
96+
9097
export const attioClient = env.ATTIO_API_KEY ? new AttioClient(env.ATTIO_API_KEY) : null;
9198

9299
export async function enqueueAttioWorkspaceSync(payload: AttioWorkspaceSync) {
@@ -112,7 +119,11 @@ export async function enqueueAttioUserSync(payload: AttioUserSync) {
112119

113120
export async function runAttioWorkspaceSync(payload: AttioWorkspaceSync) {
114121
if (!attioClient) return;
115-
await attioClient.upsertWorkspace(payload);
122+
const admin = await prisma.user.findUnique({
123+
where: { id: payload.adminUserId },
124+
select: { email: true },
125+
});
126+
await attioClient.upsertWorkspace(payload, domainFromEmail(admin?.email));
116127
}
117128

118129
export async function runAttioUserSync(payload: AttioUserSync) {

0 commit comments

Comments
 (0)