Skip to content

Scheduling infrastructure for absolutely everyone.

Merge branch 'main' into feature/scheduling

Alex van Andelb2812deeff4b
diff --cc pages/availability/event/[type].tsx
index 3aec427079b,9518dadce72..806e182312b
--- a/pages/availability/event/[type].tsx
+++ b/pages/availability/event/[type].tsx
@@@ -1,35 -1,38 +1,47 @@@
import Head from 'next/head';
import Link from 'next/link';
- import { useRouter } from 'next/router';
- import { useRef, useState } from 'react';
- import Select, { OptionBase } from 'react-select';
+ import {useRouter} from 'next/router';
+ import {useRef, useState} from 'react';
+ import Select, {OptionBase} from 'react-select';
import prisma from '../../../lib/prisma';
- import { LocationType } from '../../../lib/location';
+ import {LocationType} from '../../../lib/location';
import Shell from '../../../components/Shell';
import { useSession, getSession } from 'next-auth/client';
+import {Scheduler} from "../../../components/ui/Scheduler";
+
import {
LocationMarkerIcon,
PlusCircleIcon,
XIcon,
PhoneIcon,
} from '@heroicons/react/outline';
+ import {EventTypeCustomInput, EventTypeCustomInputType} from "../../../lib/eventTypeInput";
+ import {PlusIcon} from "@heroicons/react/solid";
+import dayjs, {Dayjs} from "dayjs";
+import utc from 'dayjs/plugin/utc';
+dayjs.extend(utc);
+import timezone from 'dayjs/plugin/timezone';
+dayjs.extend(timezone);
+
export default function EventType(props) {
const router = useRouter();
+ const inputOptions: OptionBase[] = [
+ { value: EventTypeCustomInputType.Text, label: 'Text' },
+ { value: EventTypeCustomInputType.TextLong, label: 'Multiline Text' },
+ { value: EventTypeCustomInputType.Number, label: 'Number', },
+ { value: EventTypeCustomInputType.Bool, label: 'Checkbox', },
+ ]
+
const [ session, loading ] = useSession();
const [ showLocationModal, setShowLocationModal ] = useState(false);
+ const [ showAddCustomModal, setShowAddCustomModal ] = useState(false);
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 titleRef = useRef<HTMLInputElement>();
const slugRef = useRef<HTMLInputElement>();
@@@ -372,56 -461,40 +502,63 @@@
}
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,
- customInputs: 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
+ }
+ });
++ if (!eventType) {
+ return {
- props: {
- user,
- eventType
- },
++ 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
+ },
+ }
}
diff --cc prisma/schema.prisma
index 835f45334cc,6b33ce753cd..0ff777128e4
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@@ -21,8 -21,8 +21,9 @@@ model EventType
user User? @relation(fields: [userId], references: [id])
userId Int?
bookings Booking[]
+ availability Schedule[]
eventName String?
+ customInputs EventTypeCustomInput[]
}
model Credential {