feat: add additional attributes to intercom (#14794)
* feat: add additional attributes to intercom * remove console.log * added is_premium
This commit is contained in:
1 parent
22425bb693
commit
46ffeaee82
2 files changed
+44
No files matched your search
@@ -5,6 +5,7 @@ import { z } from "zod";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
|
||||
import { useHasTeamPlan, useHasPaidPlan } from "@calcom/lib/hooks/useHasPaidPlan";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
@@ -56,6 +57,13 @@ export const useIntercom = () => {
|
||||
metadata: data?.metadata,
|
||||
completed_onboarding: data.completedOnboarding,
|
||||
is_logged_in: !!data,
|
||||
sum_of_bookings: data.sumOfBookings,
|
||||
sum_of_calendars: data.sumOfCalendars,
|
||||
sum_of_teams: data.sumOfTeams,
|
||||
has_org: !data.organizationId,
|
||||
sum_of_event_types: data.sumOfEventTypes,
|
||||
sum_of_team_event_types: data.sumOfTeamEventTypes,
|
||||
is_premium: hasKeyInMetadata(data, "isPremium") ? !!data.metadata.isPremium : false,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -71,6 +71,37 @@ export const meHandler = async ({ ctx, input }: MeOptions) => {
|
||||
identityProviderEmail = account?.providerEmail || "";
|
||||
}
|
||||
|
||||
const additionalUserInfo = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
select: {
|
||||
bookings: {
|
||||
select: { id: true },
|
||||
},
|
||||
selectedCalendars: true,
|
||||
teams: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
eventTypes: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
eventTypes: {
|
||||
select: { id: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
let sumOfTeamEventTypes = 0;
|
||||
for (const team of additionalUserInfo?.teams || []) {
|
||||
for (const _eventType of team.team.eventTypes) {
|
||||
sumOfTeamEventTypes++;
|
||||
}
|
||||
}
|
||||
|
||||
// Destructuring here only makes it more illegible
|
||||
// pick only the part we want to expose in the API
|
||||
return {
|
||||
@@ -113,6 +144,11 @@ export const meHandler = async ({ ctx, input }: MeOptions) => {
|
||||
profile: user.profile ?? null,
|
||||
profiles: allUserEnrichedProfiles,
|
||||
secondaryEmails,
|
||||
sumOfBookings: additionalUserInfo?.bookings.length,
|
||||
sumOfCalendars: additionalUserInfo?.selectedCalendars.length,
|
||||
sumOfTeams: additionalUserInfo?.teams.length,
|
||||
sumOfEventTypes: additionalUserInfo?.eventTypes.length,
|
||||
sumOfTeamEventTypes,
|
||||
...(passwordAdded ? { passwordAdded } : {}),
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user