Skip to content
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

fix: add default schedule while creating org member #16855

Merged
merged 15 commits into from
Nov 18, 2024
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
21 changes: 21 additions & 0 deletions packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TFunction } from "next-i18next";

import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
import { sendTeamInviteEmail } from "@calcom/emails";
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
import { ENABLE_PROFILE_SWITCHER, WEBAPP_URL } from "@calcom/lib/constants";
import { createAProfileForAnExistingUser } from "@calcom/lib/createAProfileForAnExistingUser";
import logger from "@calcom/lib/logger";
Expand Down Expand Up @@ -272,6 +273,7 @@ export async function createNewUsersConnectToOrgIfExists({
timeFormat,
weekStart,
timeZone,
language,
}: {
invitations: Invitation[];
isOrg: boolean;
Expand All @@ -283,6 +285,7 @@ export async function createNewUsersConnectToOrgIfExists({
timeFormat?: number;
weekStart?: string;
timeZone?: string;
language: string;
}) {
// fail if we have invalid emails
invitations.forEach((invitation) => checkInputEmailIsValid(invitation.usernameOrEmail));
Expand All @@ -307,6 +310,8 @@ export async function createNewUsersConnectToOrgIfExists({

const isBecomingAnOrgMember = parentId || isOrg;

const availability = getAvailabilityFromSchedule(DEFAULT_SCHEDULE);
Copy link
Contributor

@Ryukemeister Ryukemeister Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we rename this to defaultScheduleAvailability or defaultAvailability?

const t = await getTranslation(language, "common");
const createdUser = await tx.user.create({
data: {
username: isBecomingAnOrgMember ? orgMemberUsername : regularTeamMemberUsername,
Expand Down Expand Up @@ -340,6 +345,21 @@ export async function createNewUsersConnectToOrgIfExists({
accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted
},
},
// Default schedule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its alright if you remove the comment

schedules: {
create: {
name: t("default_schedule_name"),
availability: {
createMany: {
data: availability.map((schedule) => ({
days: schedule.days,
startTime: schedule.startTime,
endTime: schedule.endTime,
})),
},
},
},
},
},
});

Expand Down Expand Up @@ -908,6 +928,7 @@ export async function handleNewUsersInvites({
orgConnectInfoByUsernameOrEmail,
autoAcceptEmailDomain: autoAcceptEmailDomain,
parentId: team.parentId,
language,
});

const sendVerifyEmailsPromises = invitationsForNewUsers.map((invitation) => {
Expand Down
Loading