From 015b7c18af9b856d98e42073bbd9d014dd7aae6c Mon Sep 17 00:00:00 2001 From: Femi Odugbesan Date: Fri, 8 Oct 2021 08:10:57 -0500 Subject: [PATCH] fix #582: send user back to onboarding after adding integration (#635) * fix #582: send user back to onboarding after adding integration if incomplete * use more accurate, descriptive typings Co-authored-by: Alex van Andel --- lib/getting-started.tsx | 12 +++++ pages/event-types/index.tsx | 24 ++++------ pages/integrations/index.tsx | 92 ++++++++++++++++++++---------------- 3 files changed, 73 insertions(+), 55 deletions(-) diff --git a/lib/getting-started.tsx b/lib/getting-started.tsx index e652b0d2..601e8b95 100644 --- a/lib/getting-started.tsx +++ b/lib/getting-started.tsx @@ -1,3 +1,15 @@ +import { User } from "@prisma/client"; import dayjs from "dayjs"; export const ONBOARDING_INTRODUCED_AT = dayjs("September 1 2021").toISOString(); + +export const ONBOARDING_NEXT_REDIRECT = { + redirect: { + permanent: false, + destination: "/getting-started", + }, +} as const; + +export const shouldShowOnboarding = (user: Pick) => { + return !user.completedOnboarding && dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT); +}; diff --git a/pages/event-types/index.tsx b/pages/event-types/index.tsx index 96b638c5..fd31b75a 100644 --- a/pages/event-types/index.tsx +++ b/pages/event-types/index.tsx @@ -8,9 +8,8 @@ import { PlusIcon, UsersIcon, } from "@heroicons/react/solid"; -import { SchedulingType } from "@prisma/client"; -import { Prisma } from "@prisma/client"; -import dayjs from "dayjs"; +import { SchedulingType, Prisma } from "@prisma/client"; +import { GetServerSidePropsContext } from "next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Head from "next/head"; import Link from "next/link"; @@ -23,7 +22,7 @@ import { getSession } from "@lib/auth"; import classNames from "@lib/classNames"; import { HttpError } from "@lib/core/http/error"; import { getOrSetUserLocaleFromHeaders } from "@lib/core/i18n/i18n.utils"; -import { ONBOARDING_INTRODUCED_AT } from "@lib/getting-started"; +import { shouldShowOnboarding, ONBOARDING_NEXT_REDIRECT } from "@lib/getting-started"; import { useLocale } from "@lib/hooks/useLocale"; import { useToggleQuery } from "@lib/hooks/useToggleQuery"; import createEventType from "@lib/mutations/event-types/create-event-type"; @@ -145,7 +144,7 @@ const EventTypesPage = (props: PageProps) => { "hover:bg-neutral-50 flex justify-between items-center ", type.$disabled && "pointer-events-none" )}> -
+
@@ -224,7 +223,7 @@ const EventTypesPage = (props: PageProps) => { leaveTo="transform opacity-0 scale-95"> + className="absolute right-0 z-10 w-56 mt-2 origin-top-right bg-white divide-y rounded-sm shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none divide-neutral-100">
{({ active }) => ( @@ -558,7 +557,7 @@ const CreateNewEventDialog = ({ ); }; -export async function getServerSideProps(context) { +export async function getServerSideProps(context: GetServerSidePropsContext) { const session = await getSession(context); const locale = await getOrSetUserLocaleFromHeaders(context.req); @@ -647,13 +646,10 @@ export async function getServerSideProps(context) { }; } - if (!user.completedOnboarding && dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT)) { - return { - redirect: { - permanent: false, - destination: "/getting-started", - }, - }; + if ( + shouldShowOnboarding({ completedOnboarding: user.completedOnboarding, createdDate: user.createdDate }) + ) { + return ONBOARDING_NEXT_REDIRECT; } // backwards compatibility, TMP: diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsx index d147ad3c..81d36a12 100644 --- a/pages/integrations/index.tsx +++ b/pages/integrations/index.tsx @@ -6,6 +6,7 @@ import Link from "next/link"; import { useCallback, useEffect, useRef, useState } from "react"; import { getSession } from "@lib/auth"; +import { ONBOARDING_NEXT_REDIRECT, shouldShowOnboarding } from "@lib/getting-started"; import AddAppleIntegration, { ADD_APPLE_INTEGRATION_FORM_TITLE, } from "@lib/integrations/Apple/components/AddAppleIntegration"; @@ -138,8 +139,8 @@ export default function Home({ integrations }: inferSSRProps ( - - + + Connect a new App @@ -152,14 +153,14 @@ export default function Home({ integrations }: inferSSRProps { return (
  • -
    - {integration.title} +
    + {integration.title}
    -

    {integration.title}

    -

    {integration.description}

    +

    {integration.title}

    +

    {integration.description}

    -
    +
    -
    +
    @@ -182,7 +183,7 @@ export default function Home({ integrations }: inferSSRProps ( !open && onCloseSelectCalendar()}> - + Select calendars @@ -192,20 +193,20 @@ export default function Home({ integrations }: inferSSRProps
    -