From 669199e2730f307ad1c4624d630154c0b69d864d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Fri, 1 Jul 2022 10:02:44 -0600 Subject: [PATCH] Removes unused files (#3208) * Adds next-unused * Cleanup * Update next-unused * Removes next-unused Co-authored-by: Peer Richelsen --- apps/web/components/booking/DatePicker.tsx | 262 ------------------ apps/web/components/ui/WeekdaySelect.tsx | 64 ----- apps/web/components/ui/alerts/Error.tsx | 8 - .../web/lib/attendeeToPersonConversionType.ts | 16 -- apps/web/lib/core/browser/useDarkMode.tsx | 45 --- apps/web/lib/doWorkAsync.ts | 67 ----- apps/web/lib/member.ts | 8 - apps/web/lib/types/event-type.ts | 67 ----- apps/web/lib/webhook.ts | 3 - apps/web/styles/globals.css | 5 - 10 files changed, 545 deletions(-) delete mode 100644 apps/web/components/booking/DatePicker.tsx delete mode 100644 apps/web/components/ui/WeekdaySelect.tsx delete mode 100644 apps/web/components/ui/alerts/Error.tsx delete mode 100644 apps/web/lib/attendeeToPersonConversionType.ts delete mode 100644 apps/web/lib/core/browser/useDarkMode.tsx delete mode 100644 apps/web/lib/doWorkAsync.ts delete mode 100644 apps/web/lib/member.ts delete mode 100644 apps/web/lib/types/event-type.ts delete mode 100644 apps/web/lib/webhook.ts diff --git a/apps/web/components/booking/DatePicker.tsx b/apps/web/components/booking/DatePicker.tsx deleted file mode 100644 index 2db969e538..0000000000 --- a/apps/web/components/booking/DatePicker.tsx +++ /dev/null @@ -1,262 +0,0 @@ -import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/solid"; -import { PeriodType } from "@prisma/client"; -import { memoize } from "lodash"; -import { useEffect, useRef, useState } from "react"; - -import dayjs, { Dayjs } from "@calcom/dayjs"; -import { useEmbedStyles } from "@calcom/embed-core/embed-iframe"; -import { useLocale } from "@calcom/lib/hooks/useLocale"; - -import classNames from "@lib/classNames"; -import { timeZone } from "@lib/clock"; -import { weekdayNames } from "@lib/core/i18n/weekday"; -import { doWorkAsync } from "@lib/doWorkAsync"; -import isOutOfBounds from "@lib/isOutOfBounds"; -import getSlots from "@lib/slots"; -import { WorkingHours } from "@lib/types/schedule"; - -import Loader from "@components/Loader"; - -type DatePickerProps = { - weekStart: string; - onDatePicked: (pickedDate: Dayjs) => void; - workingHours: WorkingHours[]; - eventLength: number; - date: Dayjs | null; - periodType: PeriodType; - periodStartDate: Date | null; - periodEndDate: Date | null; - periodDays: number | null; - periodCountCalendarDays: boolean | null; - minimumBookingNotice: number; -}; - -function DatePicker({ - weekStart, - onDatePicked, - workingHours, - eventLength, - date, - periodType = PeriodType.UNLIMITED, - periodStartDate, - periodEndDate, - periodDays, - periodCountCalendarDays, - minimumBookingNotice, -}: DatePickerProps): JSX.Element { - const { i18n } = useLocale(); - const [browsingDate, setBrowsingDate] = useState(date); - const enabledDateButtonEmbedStyles = useEmbedStyles("enabledDateButton"); - const disabledDateButtonEmbedStyles = useEmbedStyles("disabledDateButton"); - const [month, setMonth] = useState(""); - const [year, setYear] = useState(""); - const [isFirstMonth, setIsFirstMonth] = useState(false); - const [daysFromState, setDays] = useState< - | { - disabled: boolean; - date: number; - }[] - | null - >(null); - useEffect(() => { - if (!browsingDate || (date && browsingDate.utcOffset() !== date?.utcOffset())) { - setBrowsingDate(date || dayjs().tz(timeZone())); - } - }, [date, browsingDate]); - - useEffect(() => { - if (browsingDate) { - setMonth(browsingDate.toDate().toLocaleString(i18n.language, { month: "long" })); - setYear(browsingDate.format("YYYY")); - setIsFirstMonth(browsingDate.startOf("month").isBefore(dayjs())); - setDays(null); - } - }, [browsingDate, i18n.language]); - - const isDisabled = ( - day: number, - { - browsingDate, - periodType, - periodStartDate, - periodEndDate, - periodCountCalendarDays, - periodDays, - eventLength, - minimumBookingNotice, - workingHours, - }: Omit & { - browsingDate: Dayjs; - } - ) => { - const date = browsingDate.startOf("day").date(day); - return ( - isOutOfBounds(date, { - periodType, - periodStartDate, - periodEndDate, - periodCountCalendarDays, - periodDays, - }) || - !getSlots({ - inviteeDate: date, - frequency: eventLength, - minimumBookingNotice, - workingHours, - eventLength, - }).length - ); - }; - - const isDisabledRef = useRef( - memoize(isDisabled, (day, { browsingDate }) => { - // Make a composite cache key - return day + "_" + browsingDate.toString(); - }) - ); - - const days = (() => { - if (!browsingDate) { - return []; - } - if (daysFromState) { - return daysFromState; - } - // Create placeholder elements for empty days in first week - let weekdayOfFirst = browsingDate.date(1).day(); - if (weekStart === "Monday") { - weekdayOfFirst -= 1; - if (weekdayOfFirst < 0) weekdayOfFirst = 6; - } - - const days = Array(weekdayOfFirst).fill(null); - - const isDisabledMemoized = isDisabledRef.current; - - const daysInMonth = browsingDate.daysInMonth(); - const daysInitialOffset = days.length; - - // Build UI with All dates disabled - for (let i = 1; i <= daysInMonth; i++) { - days.push({ - disabled: true, - date: i, - }); - } - - // Update dates with their availability - doWorkAsync({ - batch: 1, - name: "DatePicker", - length: daysInMonth, - callback: (i: number) => { - const day = i + 1; - days[daysInitialOffset + i] = { - disabled: isDisabledMemoized(day, { - browsingDate, - periodType, - periodStartDate, - periodEndDate, - periodCountCalendarDays, - periodDays, - eventLength, - minimumBookingNotice, - workingHours, - }), - date: day, - }; - }, - batchDone: () => { - setDays([...days]); - }, - }); - - return days; - // eslint-disable-next-line react-hooks/exhaustive-deps - })(); - - if (!browsingDate) { - return ; - } - - // Handle month changes - const incrementMonth = () => { - setBrowsingDate(browsingDate?.add(1, "month")); - }; - - const decrementMonth = () => { - setBrowsingDate(browsingDate?.subtract(1, "month")); - }; - - return ( -
-
- - {month}{" "} - {year} - -
- - -
-
-
- {weekdayNames(i18n.language, weekStart === "Sunday" ? 0 : 1, "short").map((weekDay) => ( -
- {weekDay} -
- ))} -
-
- {days.map((day, idx) => ( -
- {day === null ? ( -
- ) : ( - - )} -
- ))} -
-
- ); -} - -export default DatePicker; diff --git a/apps/web/components/ui/WeekdaySelect.tsx b/apps/web/components/ui/WeekdaySelect.tsx deleted file mode 100644 index 5a56af2e1a..0000000000 --- a/apps/web/components/ui/WeekdaySelect.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import React, { useEffect, useState } from "react"; - -interface WeekdaySelectProps { - defaultValue: number[]; - onSelect: (selected: number[]) => void; -} - -export const WeekdaySelect = (props: WeekdaySelectProps) => { - const { onSelect } = props; - const [activeDays, setActiveDays] = useState( - Array.from(Array(7).keys()).map((v, i) => (props.defaultValue || []).includes(i)) - ); - - const days = ["S", "M", "T", "W", "T", "F", "S"]; - - useEffect(() => { - onSelect(activeDays.map((v, idx) => (v ? idx : -1)).filter((v) => v !== -1)); - }, [onSelect, activeDays]); - - const toggleDay = (idx: number) => { - activeDays[idx] = !activeDays[idx]; - setActiveDays(([] as boolean[]).concat(activeDays)); - }; - - return ( -
-
- {days.map((day, idx) => - activeDays[idx] ? ( - - ) : ( - - ) - )} -
-
- ); -}; diff --git a/apps/web/components/ui/alerts/Error.tsx b/apps/web/components/ui/alerts/Error.tsx deleted file mode 100644 index 8e3e54b57f..0000000000 --- a/apps/web/components/ui/alerts/Error.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { Alert } from "@calcom/ui/Alert"; - -/** - * @deprecated use `` instead - */ -export default function ErrorAlert(props: { message: string; className?: string }) { - return ; -} diff --git a/apps/web/lib/attendeeToPersonConversionType.ts b/apps/web/lib/attendeeToPersonConversionType.ts deleted file mode 100644 index 5e1b2dd846..0000000000 --- a/apps/web/lib/attendeeToPersonConversionType.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Attendee } from "@prisma/client"; -import { TFunction } from "next-i18next"; - -import { Person } from "@calcom/types/Calendar"; - -export const attendeeToPersonConversionType = (attendees: Attendee[], t: TFunction): Person[] => { - return attendees.map((attendee) => { - return { - name: attendee.name, - email: attendee.email, - timeZone: attendee.timeZone, - locale: attendee.locale || "en", - language: { translate: t, locale: attendee.locale || "en" }, - }; - }); -}; diff --git a/apps/web/lib/core/browser/useDarkMode.tsx b/apps/web/lib/core/browser/useDarkMode.tsx deleted file mode 100644 index b0ccbb2276..0000000000 --- a/apps/web/lib/core/browser/useDarkMode.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { useEffect, useState } from "react"; - -const COLOR_SCHEME_QUERY = "(prefers-color-scheme: dark)"; - -interface UseDarkModeOutput { - isDarkMode: boolean; - toggle: () => void; - enable: () => void; - disable: () => void; -} - -function useDarkMode(defaultValue?: boolean): UseDarkModeOutput { - const getPrefersScheme = (): boolean => { - // Prevents SSR issues - if (process.browser) { - return window.matchMedia(COLOR_SCHEME_QUERY).matches; - } - - return !!defaultValue; - }; - - const [isDarkMode, setDarkMode] = useState(getPrefersScheme()); - - // Update darkMode if os prefers changes - useEffect(() => { - const handler = () => setDarkMode(getPrefersScheme); - const matchMedia = window.matchMedia(COLOR_SCHEME_QUERY); - - matchMedia.addEventListener("change", handler); - - return () => { - matchMedia.removeEventListener("change", handler); - }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - return { - isDarkMode, - toggle: () => setDarkMode((prev) => !prev), - enable: () => setDarkMode(true), - disable: () => setDarkMode(false), - }; -} - -export default useDarkMode; diff --git a/apps/web/lib/doWorkAsync.ts b/apps/web/lib/doWorkAsync.ts deleted file mode 100644 index dc9ee623f9..0000000000 --- a/apps/web/lib/doWorkAsync.ts +++ /dev/null @@ -1,67 +0,0 @@ -import noop from "lodash/noop"; - -const data: Record = {}; -/** - * Starts an iteration from `0` to `length - 1` with batch size `batch` - * - * `callback` is called per iteration - * - * `done` is called when all iterations are done - * - * `name` is a unique identifier for the work. It allows the work that is not required to be dropped. - */ -export const doWorkAsync = ({ - length, - name, - callback, - done, - batch, - offsetStart, - batchDone, - __pending, -}: { - name: string; - length: number; - callback: (i: number, b?: boolean) => void; - done?: () => void; - batchDone?: () => void; - batch: number; - offsetStart?: number; - __pending?: boolean; -}) => { - offsetStart = offsetStart || 0; - const stepLength = batch; - const lastIndex = length - 1; - const offsetEndExclusive = offsetStart + stepLength; - - batchDone = batchDone || noop; - done = done || noop; - - if (!__pending && data[name]) { - cancelAnimationFrame(data[name]); - } - - if (offsetStart >= length) { - done(); - return; - } - - for (let i = offsetStart; i < offsetEndExclusive && i < length; i++) { - callback(i, offsetEndExclusive > lastIndex); - } - - batchDone(); - - data[name] = requestAnimationFrame(() => { - doWorkAsync({ - length, - callback, - batchDone, - name, - batch, - done, - offsetStart: offsetEndExclusive, - __pending: true, - }); - }); -}; diff --git a/apps/web/lib/member.ts b/apps/web/lib/member.ts deleted file mode 100644 index 8b64c230b4..0000000000 --- a/apps/web/lib/member.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface Member { - id: number; - avatar: string | null; - role: string; - email: string; - name: string | null; - username: string | null; -} diff --git a/apps/web/lib/types/event-type.ts b/apps/web/lib/types/event-type.ts deleted file mode 100644 index a7186812cf..0000000000 --- a/apps/web/lib/types/event-type.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { EventType, SchedulingType } from "@prisma/client"; -import { JSONObject } from "superjson/dist/types"; - -import { WorkingHours } from "./schedule"; - -export type AdvancedOptions = { - metadata?: JSONObject; - eventName?: string; - periodType?: string; - periodDays?: number; - periodStartDate?: Date | string; - periodEndDate?: Date | string; - periodCountCalendarDays?: boolean; - requiresConfirmation?: boolean; - disableGuests?: boolean; - minimumBookingNotice?: number; - beforeBufferTime?: number; - afterBufferTime?: number; - slotInterval?: number | null; - price?: number; - currency?: string; - schedulingType?: SchedulingType; - users?: string[]; - availability?: { openingHours: WorkingHours[]; dateOverrides: WorkingHours[] }; - customInputs?: EventTypeCustomInput[]; - timeZone?: string; - seatsPerTimeSlot: number; - destinationCalendar?: { - userId?: number; - eventTypeId?: number; - integration: string; - externalId: string; - }; -}; - -export type EventTypeCustomInput = { - id: number; - label: string; - placeholder: string; - required: boolean; - type: string; -}; - -export type CreateEventType = { - title: string; - slug: string; - description: string; - length: number; - teamId?: number; - schedulingType?: SchedulingType; -}; - -export type CreateEventTypeResponse = { - eventType: EventType; -}; - -export type EventTypeInput = AdvancedOptions & { - id: number; - title: string; - slug: string; - description: string; - length: number; - teamId?: number; - hidden: boolean; - locations: unknown; - availability?: { openingHours: WorkingHours[]; dateOverrides: WorkingHours[] }; -}; diff --git a/apps/web/lib/webhook.ts b/apps/web/lib/webhook.ts deleted file mode 100644 index 91ee55f584..0000000000 --- a/apps/web/lib/webhook.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Webhook as PrismaWebhook } from "@prisma/client"; - -export type Webhook = PrismaWebhook & { prevState: null }; diff --git a/apps/web/styles/globals.css b/apps/web/styles/globals.css index 2a17f90eb8..a6b60b13e4 100644 --- a/apps/web/styles/globals.css +++ b/apps/web/styles/globals.css @@ -408,11 +408,6 @@ hr { box-shadow: none; } -.weekdaySelect button.active { - background: #000; - color: #fff; -} - /* react-date-picker forces a border upon us, cast it away */ .react-date-picker__wrapper { border: none !important;