Skip to content

Commit

Permalink
fix: Support adding an non-existent email as the owner of the organiz…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
hariombalhara committed Apr 13, 2024
1 parent c79d089 commit 9601522
Show file tree
Hide file tree
Showing 128 changed files with 1,349 additions and 557 deletions.
2 changes: 1 addition & 1 deletion packages/app-store/_components/OmniInstallAppButton.tsx
Expand Up @@ -24,7 +24,7 @@ export default function OmniInstallAppButton({
}) {
const { t } = useLocale();
const { data: app } = useApp(appId);
const utils = trpc.useContext();
const utils = trpc.useUtils();

const mutation = useAddAppMutation(null, {
returnTo,
Expand Down
Expand Up @@ -130,7 +130,7 @@ function PaymentChecker(props: PaymentCheckerProps) {
// TODO: subscribe rather than polling
const searchParams = useCompatSearchParams();
const bookingSuccessRedirect = useBookingSuccessRedirect();
const utils = trpc.useContext();
const utils = trpc.useUtils();
const { t } = useLocale();

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-store/dailyvideo/lib/VideoApiAdapter.ts
Expand Up @@ -107,8 +107,8 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {

const translateEvent = async (event: CalendarEvent) => {
// Documentation at: https://docs.daily.co/reference#list-rooms
// added a 1 hour buffer for room expiration
const exp = Math.round(new Date(event.endTime).getTime() / 1000) + 60 * 60;
// Adds 14 days from the end of the booking as the expiration date
const exp = Math.round(new Date(event.endTime).getTime() / 1000) + 60 * 60 * 24 * 14;
const { scale_plan: scalePlan } = await getDailyAppKeys();
const hasTeamPlan = await prisma.membership.findFirst({
where: {
Expand Down
94 changes: 52 additions & 42 deletions packages/app-store/googlecalendar/lib/CalendarService.ts
Expand Up @@ -9,6 +9,7 @@ import dayjs from "@calcom/dayjs";
import { getFeatureFlag } from "@calcom/features/flags/server/utils";
import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser";
import type CalendarService from "@calcom/lib/CalendarService";
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
Expand Down Expand Up @@ -187,61 +188,65 @@ export default class GoogleCalendarService implements Calendar {
};

async createEvent(calEventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
const formattedCalEvent = formatCalEvent(calEventRaw);

const payload: calendar_v3.Schema$Event = {
summary: calEventRaw.title,
description: getRichDescription(calEventRaw),
summary: formattedCalEvent.title,
description: getRichDescription(formattedCalEvent),
start: {
dateTime: calEventRaw.startTime,
timeZone: calEventRaw.organizer.timeZone,
dateTime: formattedCalEvent.startTime,
timeZone: formattedCalEvent.organizer.timeZone,
},
end: {
dateTime: calEventRaw.endTime,
timeZone: calEventRaw.organizer.timeZone,
dateTime: formattedCalEvent.endTime,
timeZone: formattedCalEvent.organizer.timeZone,
},
attendees: this.getAttendees(calEventRaw),
attendees: this.getAttendees(formattedCalEvent),
reminders: {
useDefault: true,
},
guestsCanSeeOtherGuests: !!calEventRaw.seatsPerTimeSlot ? calEventRaw.seatsShowAttendees : true,
iCalUID: calEventRaw.iCalUID,
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
? formattedCalEvent.seatsShowAttendees
: true,
iCalUID: formattedCalEvent.iCalUID,
};

if (calEventRaw.location) {
payload["location"] = getLocation(calEventRaw);
if (formattedCalEvent.location) {
payload["location"] = getLocation(formattedCalEvent);
}

if (calEventRaw.recurringEvent) {
if (formattedCalEvent.recurringEvent) {
const rule = new RRule({
freq: calEventRaw.recurringEvent.freq,
interval: calEventRaw.recurringEvent.interval,
count: calEventRaw.recurringEvent.count,
freq: formattedCalEvent.recurringEvent.freq,
interval: formattedCalEvent.recurringEvent.interval,
count: formattedCalEvent.recurringEvent.count,
});

payload["recurrence"] = [rule.toString()];
}

if (calEventRaw.conferenceData && calEventRaw.location === MeetLocationType) {
payload["conferenceData"] = calEventRaw.conferenceData;
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
payload["conferenceData"] = formattedCalEvent.conferenceData;
}
const calendar = await this.authedCalendar();
// Find in calEventRaw.destinationCalendar the one with the same credentialId
// Find in formattedCalEvent.destinationCalendar the one with the same credentialId

const selectedCalendar =
calEventRaw.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
formattedCalEvent.destinationCalendar?.find((cal) => cal.credentialId === credentialId)?.externalId ||
"primary";

try {
let event;
let recurringEventId = null;
if (calEventRaw.existingRecurringEvent) {
recurringEventId = calEventRaw.existingRecurringEvent.recurringEventId;
if (formattedCalEvent.existingRecurringEvent) {
recurringEventId = formattedCalEvent.existingRecurringEvent.recurringEventId;
const recurringEventInstances = await calendar.events.instances({
calendarId: selectedCalendar,
eventId: calEventRaw.existingRecurringEvent.recurringEventId,
eventId: formattedCalEvent.existingRecurringEvent.recurringEventId,
});
if (recurringEventInstances.data.items) {
const calComEventStartTime = dayjs(calEventRaw.startTime)
.tz(calEventRaw.organizer.timeZone)
const calComEventStartTime = dayjs(formattedCalEvent.startTime)
.tz(formattedCalEvent.organizer.timeZone)
.format();
for (let i = 0; i < recurringEventInstances.data.items.length; i++) {
const instance = recurringEventInstances.data.items[i];
Expand All @@ -266,9 +271,9 @@ export default class GoogleCalendarService implements Calendar {
calendarId: selectedCalendar,
eventId: event.id || "",
requestBody: {
location: getLocation(calEventRaw),
location: getLocation(formattedCalEvent),
description: getRichDescription({
...calEventRaw,
...formattedCalEvent,
}),
},
});
Expand Down Expand Up @@ -296,7 +301,7 @@ export default class GoogleCalendarService implements Calendar {
eventId: event.id || "",
requestBody: {
description: getRichDescription({
...calEventRaw,
...formattedCalEvent,
additionalInformation: { hangoutLink: event.hangoutLink },
}),
},
Expand Down Expand Up @@ -342,37 +347,42 @@ export default class GoogleCalendarService implements Calendar {
}

async updateEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<any> {
const formattedCalEvent = formatCalEvent(event);

const payload: calendar_v3.Schema$Event = {
summary: event.title,
description: getRichDescription(event),
summary: formattedCalEvent.title,
description: getRichDescription(formattedCalEvent),
start: {
dateTime: event.startTime,
timeZone: event.organizer.timeZone,
dateTime: formattedCalEvent.startTime,
timeZone: formattedCalEvent.organizer.timeZone,
},
end: {
dateTime: event.endTime,
timeZone: event.organizer.timeZone,
dateTime: formattedCalEvent.endTime,
timeZone: formattedCalEvent.organizer.timeZone,
},
attendees: this.getAttendees(event),
attendees: this.getAttendees(formattedCalEvent),
reminders: {
useDefault: true,
},
guestsCanSeeOtherGuests: !!event.seatsPerTimeSlot ? event.seatsShowAttendees : true,
guestsCanSeeOtherGuests: !!formattedCalEvent.seatsPerTimeSlot
? formattedCalEvent.seatsShowAttendees
: true,
};

if (event.location) {
payload["location"] = getLocation(event);
if (formattedCalEvent.location) {
payload["location"] = getLocation(formattedCalEvent);
}

if (event.conferenceData && event.location === MeetLocationType) {
payload["conferenceData"] = event.conferenceData;
if (formattedCalEvent.conferenceData && formattedCalEvent.location === MeetLocationType) {
payload["conferenceData"] = formattedCalEvent.conferenceData;
}

const calendar = await this.authedCalendar();

const selectedCalendar =
(externalCalendarId
? event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId
? formattedCalEvent.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)
?.externalId
: undefined) || "primary";

try {
Expand All @@ -397,7 +407,7 @@ export default class GoogleCalendarService implements Calendar {
eventId: evt.data.id || "",
requestBody: {
description: getRichDescription({
...event,
...formattedCalEvent,
additionalInformation: { hangoutLink: evt.data.hangoutLink },
}),
},
Expand All @@ -419,7 +429,7 @@ export default class GoogleCalendarService implements Calendar {
} catch (error) {
this.log.error(
"There was an error updating event in google calendar: ",
safeStringify({ error, event, uid })
safeStringify({ error, event: formattedCalEvent, uid })
);
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-store/make/pages/setup/index.tsx
Expand Up @@ -16,7 +16,7 @@ export default function MakeSetup({ inviteLink }: InferGetServerSidePropsType<ty
const [newApiKeys, setNewApiKeys] = useState<Record<string, string>>({});

const { t } = useLocale();
const utils = trpc.useContext();
const utils = trpc.useUtils();
const integrations = trpc.viewer.integrations.useQuery({ variant: "automation" });
const oldApiKey = trpc.viewer.apiKeys.findKeyOfType.useQuery({ appId: MAKE });
const teamsList = trpc.viewer.teams.listOwnedTeams.useQuery(undefined, {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-store/routing-forms/components/FormActions.tsx
Expand Up @@ -63,7 +63,7 @@ function NewFormDialog({ appUrl }: { appUrl: string }) {
const routerQuery = useRouterQuery();
const { t } = useLocale();
const router = useRouter();
const utils = trpc.useContext();
const utils = trpc.useUtils();

const mutation = trpc.viewer.appRoutingForms.formMutation.useMutation({
onSuccess: (_data, variables) => {
Expand Down Expand Up @@ -193,7 +193,7 @@ function Dialogs({
setDeleteDialogOpen: (open: boolean) => void;
deleteDialogFormId: string | null;
}) {
const utils = trpc.useContext();
const utils = trpc.useUtils();
const router = useRouter();
const { t } = useLocale();
const deleteMutation = trpc.viewer.appRoutingForms.deleteForm.useMutation({
Expand Down Expand Up @@ -276,7 +276,7 @@ export function FormActionsProvider({ appUrl, children }: { appUrl: string; chil
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [deleteDialogFormId, setDeleteDialogFormId] = useState<string | null>(null);
const { t } = useLocale();
const utils = trpc.useContext();
const utils = trpc.useUtils();

const toggleMutation = trpc.viewer.appRoutingForms.formMutation.useMutation({
onMutate: async ({ id: formId, disabled }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-store/routing-forms/components/SingleForm.tsx
Expand Up @@ -234,7 +234,7 @@ type SingleFormComponentProps = {
};

function SingleForm({ form, appUrl, Page, enrichedWithUserProfileForm }: SingleFormComponentProps) {
const utils = trpc.useContext();
const utils = trpc.useUtils();
const { t } = useLocale();

const [isTestPreviewOpen, setIsTestPreviewOpen] = useState(false);
Expand Down
Expand Up @@ -66,7 +66,7 @@ export default function RoutingForms({
const { hasPaidPlan } = useHasPaidPlan();
const routerQuery = useRouterQuery();
const hookForm = useFormContext<RoutingFormWithResponseCount>();
const utils = trpc.useContext();
const utils = trpc.useUtils();
const [parent] = useAutoAnimate<HTMLUListElement>();

const mutation = trpc.viewer.routingFormOrder.useMutation({
Expand Down
Expand Up @@ -49,7 +49,7 @@ export const ConfirmDialog = (props: IConfirmDialogWipe) => {
const endDate = today.endOf("day");
const dateFormat = "ddd, MMM D, YYYY h:mm A";

const utils = trpc.useContext();
const utils = trpc.useUtils();

const rescheduleApi = useMutation({
mutationFn: async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-store/zapier/pages/setup/index.tsx
Expand Up @@ -16,7 +16,7 @@ const ZAPIER = "zapier";
export default function ZapierSetup(props: IZapierSetupProps) {
const [newApiKeys, setNewApiKeys] = useState<Record<string, string>>({});
const { t } = useLocale();
const utils = trpc.useContext();
const utils = trpc.useUtils();
const integrations = trpc.viewer.integrations.useQuery({ variant: "automation" });
const oldApiKey = trpc.viewer.apiKeys.findKeyOfType.useQuery({ appId: ZAPIER });
const teamsList = trpc.viewer.teams.listOwnedTeams.useQuery(undefined, {
Expand Down
12 changes: 12 additions & 0 deletions packages/core/getUserAvailability.ts
Expand Up @@ -66,6 +66,7 @@ const _getEventType = async (id: number) => {
metadata: true,
schedule: {
select: {
id: true,
availability: {
select: {
days: true,
Expand Down Expand Up @@ -276,6 +277,8 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
const useHostSchedulesForTeamEvent = eventType?.metadata?.config?.useHostSchedulesForTeamEvent;
const schedule = !useHostSchedulesForTeamEvent && eventType?.schedule ? eventType.schedule : userSchedule;

const isDefaultSchedule = userSchedule && userSchedule.id === schedule.id;

log.debug(
"Using schedule:",
safeStringify({
Expand Down Expand Up @@ -344,6 +347,15 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
dateTo,
availability,
timeZone,
travelSchedules: isDefaultSchedule
? user.travelSchedules.map((schedule) => {
return {
startDate: dayjs(schedule.startDate),
endDate: schedule.endDate ? dayjs(schedule.endDate) : undefined,
timeZone: schedule.timeZone,
};
})
: [],
outOfOffice: datesOutOfOffice,
});

Expand Down

0 comments on commit 9601522

Please sign in to comment.