Revert "fix: Autodetection of time zone only updated default time zone (#15392)" (#15720)

This reverts commit 285d1ec4c9.
This commit is contained in:
Amit Sharma authored and GitHub committed 2024-07-10 15:28:41 +00:00
1 parent 8ee27d3997
commit 92845d3adc
8 files changed
+139 -148

No files matched your search

@@ -24,6 +24,7 @@ import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
import { getDefaultScheduleId } from "../viewer/availability/util";
import { updateUserMetadataAllowedKeys, type TUpdateProfileInputSchema } from "./updateProfile.schema";
const log = logger.getSubLogger({ prefix: ["updateProfile"] });
@@ -41,7 +42,7 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
const locale = input.locale || user.locale;
const emailVerification = await getFeatureFlag(prisma, "email-verification");
const { travelSchedules, availabilityIds, ...rest } = input;
const { travelSchedules, ...rest } = input;
const secondaryEmails = input?.secondaryEmails || [];
delete input.secondaryEmails;
@@ -256,11 +257,24 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
}
if (user.timeZone !== data.timeZone && updatedUser.schedules.length > 0) {
// on timezone change update timezone of default schedule
const defaultScheduleId = await getDefaultScheduleId(user.id, prisma);
if (!user.defaultScheduleId) {
// set default schedule if not already set
await prisma.user.update({
where: {
id: user.id,
},
data: {
defaultScheduleId,
},
});
}
await prisma.schedule.updateMany({
where: {
id: {
in: input.availabilityIds,
},
id: defaultScheduleId,
},
data: {
timeZone: data.timeZone,
@@ -15,7 +15,6 @@ export const ZUpdateProfileInputSchema = z.object({
bio: z.string().optional(),
avatarUrl: z.string().nullable().optional(),
timeZone: z.string().optional(),
availabilityIds: z.array(z.number()).optional(),
weekStart: z.string().optional(),
hideBranding: z.boolean().optional(),
allowDynamicBooking: z.boolean().optional(),