From 51c0556d307f1cc5c89bebb064b625101e3bd261 Mon Sep 17 00:00:00 2001 From: Bailey Pumfleet Date: Tue, 29 Jun 2021 17:08:55 +0100 Subject: [PATCH] Hide Calendso branding --- pages/[user]/[type].tsx | 73 ++-- pages/api/user/profile.ts | 2 + pages/settings/profile.tsx | 24 ++ pages/success.tsx | 366 +++++++++++------- .../migration.sql | 2 + prisma/schema.prisma | 1 + 6 files changed, 300 insertions(+), 168 deletions(-) create mode 100644 prisma/migrations/20210629160507_hide_branding/migration.sql diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index 04a13d3b05..bf09b98776 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -119,21 +119,46 @@ export default function Type(props): Type { {rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username} | Calendso - + - - - " + props.eventType.description).replace(/'/g, "%27") + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + encodeURIComponent(props.user.avatar)} /> + + + " + props.eventType.description + ).replace(/'/g, "%27") + + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + + encodeURIComponent(props.user.avatar) + } + /> - - + + - " + props.eventType.description).replace(/'/g, "%27") + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + encodeURIComponent(props.user.avatar)} /> - + " + props.eventType.description + ).replace(/'/g, "%27") + + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + + encodeURIComponent(props.user.avatar) + } + />
- {/* note(peer): - you can remove calendso branding here, but we'd also appreciate it, if you don't <3 - */} -
- - - powered by{" "} - Calendso Logo - - -
+ {!props.user.hideBranding && ( +
+ + + powered by{" "} + Calendso Logo + + +
+ )}
); @@ -245,6 +269,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { timeZone: true, endTime: true, weekStart: true, + hideBranding: true, }, }); diff --git a/pages/api/user/profile.ts b/pages/api/user/profile.ts index cc9aef6a5d..dfb13315c2 100644 --- a/pages/api/user/profile.ts +++ b/pages/api/user/profile.ts @@ -41,6 +41,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const avatar = req.body.avatar; const timeZone = req.body.timeZone; const weekStart = req.body.weekStart; + const hideBranding = req.body.hideBranding; const updateUser = await prisma.user.update({ where: { @@ -53,6 +54,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) bio: description, timeZone: timeZone, weekStart: weekStart, + hideBranding: hideBranding, }, }); diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index c8cc0586ab..8278a55cb9 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -17,6 +17,7 @@ export default function Settings(props) { const nameRef = useRef(); const descriptionRef = useRef(); const avatarRef = useRef(); + const hideBrandingRef = useRef(); const [selectedTimeZone, setSelectedTimeZone] = useState({ value: props.user.timeZone }); const [selectedWeekStartDay, setSelectedWeekStartDay] = useState(props.user.weekStart || "Sunday"); @@ -43,6 +44,7 @@ export default function Settings(props) { const enteredAvatar = avatarRef.current.value; const enteredTimeZone = selectedTimeZone.value; const enteredWeekStartDay = selectedWeekStartDay; + const enteredHideBranding = hideBrandingRef.current.checked; // TODO: Add validation @@ -55,6 +57,7 @@ export default function Settings(props) { avatar: enteredAvatar, timeZone: enteredTimeZone, weekStart: enteredWeekStartDay, + hideBranding: enteredHideBranding, }), headers: { "Content-Type": "application/json", @@ -154,6 +157,26 @@ export default function Settings(props) { +
+
+
+ +
+
+ +

Hide all Calendso branding from your public pages.

+
+
+
@@ -247,6 +270,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { avatar: true, timeZone: true, weekStart: true, + hideBranding: true, }, }); diff --git a/pages/success.tsx b/pages/success.tsx index c8f27ecdc5..52c1f22b70 100644 --- a/pages/success.tsx +++ b/pages/success.tsx @@ -1,166 +1,244 @@ -import Head from 'next/head'; -import Link from 'next/link'; -import prisma from '../lib/prisma'; -import {useEffect, useState} from "react"; -import {useRouter} from 'next/router'; -import {CheckIcon} from '@heroicons/react/outline'; -import {CalendarIcon, ClockIcon, LocationMarkerIcon} from '@heroicons/react/solid'; -import dayjs from 'dayjs'; -import utc from 'dayjs/plugin/utc'; -import toArray from 'dayjs/plugin/toArray'; -import timezone from 'dayjs/plugin/timezone'; -import {createEvent} from 'ics'; -import {getEventName} from "../lib/event"; +import Head from "next/head"; +import Link from "next/link"; +import prisma from "../lib/prisma"; +import { useEffect, useState } from "react"; +import { useRouter } from "next/router"; +import { CheckIcon } from "@heroicons/react/outline"; +import { CalendarIcon, ClockIcon, LocationMarkerIcon } from "@heroicons/react/solid"; +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import toArray from "dayjs/plugin/toArray"; +import timezone from "dayjs/plugin/timezone"; +import { createEvent } from "ics"; +import { getEventName } from "../lib/event"; dayjs.extend(utc); dayjs.extend(toArray); dayjs.extend(timezone); export default function Success(props) { - const router = useRouter(); - const {location, name} = router.query; + const router = useRouter(); + const { location, name } = router.query; - const [ is24h, setIs24h ] = useState(false); - const [ date, setDate ] = useState(dayjs.utc(router.query.date)); + const [is24h, setIs24h] = useState(false); + const [date, setDate] = useState(dayjs.utc(router.query.date)); - useEffect( () => { - setDate(date.tz(localStorage.getItem('timeOption.preferredTimeZone') || dayjs.tz.guess())); - setIs24h(!!localStorage.getItem('timeOption.is24hClock')); - }, []); + useEffect(() => { + setDate(date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess())); + setIs24h(!!localStorage.getItem("timeOption.is24hClock")); + }, []); - const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); + const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); - function eventLink(): string { - - let optional = {}; - if (location) { - optional['location'] = location; - } - - const event = createEvent({ - start: date.utc().toArray().slice(0, 6).map((v, i) => i === 1 ? v + 1 : v), - startInputType: 'utc', - title: eventName, - description: props.eventType.description, - duration: { minutes: props.eventType.length }, - ...optional - }); - - if (event.error) { - throw event.error; - } - - return encodeURIComponent(event.value); + function eventLink(): string { + let optional = {}; + if (location) { + optional["location"] = location; } - return( -
- - Booking Confirmed | {eventName} | Calendso - - -
-
-
- +
- ) +
+
+ ); } export async function getServerSideProps(context) { - const user = await prisma.user.findFirst({ - where: { - username: context.query.user, - }, - select: { - username: true, - name: true, - bio: true, - avatar: true, - eventTypes: true - } - }); + const user = await prisma.user.findFirst({ + where: { + username: context.query.user, + }, + select: { + username: true, + name: true, + bio: true, + avatar: true, + eventTypes: true, + hideBranding: true, + }, + }); - const eventType = await prisma.eventType.findUnique({ - where: { - id: parseInt(context.query.type), - }, - select: { - id: true, - title: true, - description: true, - length: true, - eventName: true - } - }); + const eventType = await prisma.eventType.findUnique({ + where: { + id: parseInt(context.query.type), + }, + select: { + id: true, + title: true, + description: true, + length: true, + eventName: true, + }, + }); - return { - props: { - user, - eventType - }, - } + return { + props: { + user, + eventType, + }, + }; } diff --git a/prisma/migrations/20210629160507_hide_branding/migration.sql b/prisma/migrations/20210629160507_hide_branding/migration.sql new file mode 100644 index 0000000000..0e6be4d5ec --- /dev/null +++ b/prisma/migrations/20210629160507_hide_branding/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "users" ADD COLUMN "hideBranding" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 491fd909e7..8bddada9c1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -47,6 +47,7 @@ model User { startTime Int @default(0) endTime Int @default(1440) bufferTime Int @default(0) + hideBranding Boolean @default(false) createdDate DateTime @default(now()) @map(name: "created") eventTypes EventType[] credentials Credential[]