Skip to content

Scheduling infrastructure for absolutely everyone.

Merge branch 'main' into feature/scheduling

Alex van Andel1dce84fa8f65
diff --cc components/booking/AvailableTimes.tsx
index 3acc07a2b36,f6f1057414f..1d8dc555740
--- a/components/booking/AvailableTimes.tsx
+++ b/components/booking/AvailableTimes.tsx
@@@ -86,4 -84,4 +84,4 @@@ const AvailableTimes = (props) =>
);
}
--export default AvailableTimes;
++export default AvailableTimes;
diff --cc pages/availability/event/[type].tsx
index 806e182312b,1ad8824a22c..144e80e0230
--- a/pages/availability/event/[type].tsx
+++ b/pages/availability/event/[type].tsx
@@@ -40,8 -32,8 +40,9 @@@ export default function EventType(props
const [ selectedLocation, setSelectedLocation ] = useState<OptionBase | undefined>(undefined);
const [ selectedInputOption, setSelectedInputOption ] = useState<OptionBase>(inputOptions[0]);
const [ locations, setLocations ] = useState(props.eventType.locations || []);
+ const [ schedule, setSchedule ] = useState(undefined);
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(props.eventType.customInputs.sort((a, b) => a.id - b.id) || []);
+ const locationOptions = props.locationOptions
const titleRef = useRef<HTMLInputElement>();
const slugRef = useRef<HTMLInputElement>();
@@@ -197,7 -162,7 +196,6 @@@
setCustomInputs(customInputs.concat(customInput));
-- console.log(customInput)
setShowAddCustomModal(false);
};
@@@ -501,64 -465,96 +505,137 @@@
);
}
+ const validJson = (jsonString: string) => {
+ try {
+ const o = JSON.parse(jsonString);
+ if (o && typeof o === "object") {
+ return o;
+ }
+ }
+ catch (e) {}
+ return false;
+ }
+
export async function getServerSideProps(context) {
- const session = await getSession(context);
- if (!session) {
- return { redirect: { permanent: false, destination: '/auth/login' } };
+ const session = await getSession(context);
+ if (!session) {
+ return { redirect: { permanent: false, destination: '/auth/login' } };
+ }
+
+ const user = await prisma.user.findFirst({
+ where: {
+ email: session.user.email,
+ },
+ select: {
+ username: true,
+ timeZone: true,
+ startTime: true,
+ endTime: true,
+ availability: true,
}
- const user = await prisma.user.findFirst({
- where: {
- email: session.user.email,
- },
- select: {
- username: true
- }
- });
+ });
+
+ const eventType = await prisma.eventType.findUnique({
+ where: {
+ id: parseInt(context.query.type),
+ },
+ select: {
+ id: true,
+ title: true,
+ slug: true,
+ description: true,
+ length: true,
+ hidden: true,
+ locations: true,
+ eventName: true,
+ availability: true,
+ customInputs: true
+ }
+ });
+ const credentials = await prisma.credential.findMany({
+ where: {
+ userId: user.id,
+ },
+ select: {
+ id: true,
+ type: true,
+ key: true
+ }
+ });
+
+ const integrations = [ {
+ installed: !!(process.env.GOOGLE_API_CREDENTIALS && validJson(process.env.GOOGLE_API_CREDENTIALS)),
+ enabled: credentials.find( (integration) => integration.type === "google_calendar" ) != null,
+ type: "google_calendar",
+ title: "Google Calendar",
+ imageSrc: "integrations/google-calendar.png",
+ description: "For personal and business accounts",
+ }, {
+ installed: !!(process.env.MS_GRAPH_CLIENT_ID && process.env.MS_GRAPH_CLIENT_SECRET),
+ type: "office365_calendar",
+ enabled: credentials.find( (integration) => integration.type === "office365_calendar" ) != null,
+ title: "Office 365 / Outlook.com Calendar",
+ imageSrc: "integrations/office-365.png",
+ description: "For personal and business accounts",
+ } ];
+
+ let locationOptions: OptionBase[] = [
+ { value: LocationType.InPerson, label: 'In-person meeting' },
+ { value: LocationType.Phone, label: 'Phone call', },
+ ];
-
++
+ const hasGoogleCalendarIntegration = integrations.find((i) => i.type === "google_calendar" && i.installed === true && i.enabled)
+ if (hasGoogleCalendarIntegration) {
+ locationOptions.push( { value: LocationType.GoogleMeet, label: 'Google Meet' })
+ }
+
+ const hasOfficeIntegration = integrations.find((i) => i.type === "office365_calendar" && i.installed === true && i.enabled)
+ if (hasOfficeIntegration) {
+ // TODO: Add default meeting option of the office integration.
+ // Assuming it's Microsoft Teams.
+ }
+
+ const eventType = await prisma.eventType.findUnique({
+ where: {
+ id: parseInt(context.query.type),
+ },
+ select: {
+ id: true,
+ title: true,
+ slug: true,
+ description: true,
+ length: true,
+ hidden: true,
+ locations: true,
+ eventName: true,
- customInputs: true
++ customInputs: true,
++ availability: true,
+ }
+ });
+
+ if (!eventType) {
return {
- props: {
- user,
- eventType,
- locationOptions
- },
+ notFound: true,
}
+ }
+
+ const getAvailability = (providesAvailability) => (
+ providesAvailability.availability && providesAvailability.availability.length
+ ) ? providesAvailability.availability : null;
+
+ const schedules = getAvailability(eventType) || getAvailability(user) || [ {
+ days: [ 1, 2, 3, 4, 5, 6, 7 ],
+ startTime: user.startTime,
+ length: user.endTime >= 1440 ? 1439 : user.endTime,
+ } ];
+
+ return {
+ props: {
+ user,
+ eventType,
- schedules
++ schedules,
++ locationOptions,
+ },
+ }
}