Skip to content

Commit

Permalink
feat: ♿️ Add sleekplan paths
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 7, 2022
1 parent ed9d791 commit 7b66494
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
4 changes: 2 additions & 2 deletions apps/builder/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { SupportBubble } from 'components/shared/SupportBubble'

if (process.env.NEXT_PUBLIC_E2E_TEST === 'enabled') enableMocks()

const App = ({ Component, pageProps }: AppProps) => {
const App = ({ Component, pageProps: { session, ...pageProps } }: AppProps) => {
useRouterProgressBar()
const { query } = useRouter()

const typebotId = query.typebotId?.toString()
return (
<ChakraProvider theme={customTheme}>
<KBarProvider actions={actions}>
<SessionProvider>
<SessionProvider session={session}>
<UserContext>
{typebotId ? (
<TypebotContext typebotId={typebotId}>
Expand Down
31 changes: 0 additions & 31 deletions apps/builder/pages/api/auth/sleekplan.ts

This file was deleted.

41 changes: 41 additions & 0 deletions apps/builder/pages/feedback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getSession } from 'next-auth/react'
import { NextPageContext } from 'next'
import { User } from 'db'
import { isNotDefined } from 'utils'
import { sign } from 'jsonwebtoken'

const FeedbackPage = () => {
return
}

export async function getServerSideProps(context: NextPageContext) {
const session = await getSession(context)
if (isNotDefined(session?.user))
return {
redirect: {
permanent: false,
destination: `/signin?redirectPath=%2Ffeedback`,
},
}
const sleekplanToken = createSSOToken(session?.user as User)
return {
redirect: {
permanent: false,
destination: `https://feedback.typebot.io?sso=${sleekplanToken}`,
},
}
}

const createSSOToken = (user: User) => {
if (!process.env.SLEEKPLAN_SSO_KEY) return
const userData = {
mail: user.email,
id: user.id,
name: user.name,
img: user.image,
}

return sign(userData, process.env.SLEEKPLAN_SSO_KEY, { algorithm: 'HS256' })
}

export default FeedbackPage
23 changes: 14 additions & 9 deletions apps/builder/pages/typebots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { Spinner, useToast } from '@chakra-ui/react'
import { pay } from 'services/stripe'
import { useUser } from 'contexts/UserContext'
import { Banner } from 'components/dashboard/annoucements/AnnoucementBanner'
import { NextPageContext } from 'next/types'

const DashboardPage = () => {
const [isLoading, setIsLoading] = useState(false)
const { query, isReady, push } = useRouter()
const { query, isReady } = useRouter()
const { user } = useUser()
const toast = useToast({
position: 'top-right',
Expand All @@ -35,14 +36,7 @@ const DashboardPage = () => {
if (!isReady) return
const couponCode = query.coupon?.toString()
const stripeStatus = query.stripe?.toString()
const sleekplan = query.sleekplan?.toString()
const redirectPath = query.redirectPath as string | undefined

if (sleekplan) {
setIsLoading(true)
push('/api/auth/sleekplan')
return
}
if (stripeStatus === 'success')
toast({
title: 'Typebot Pro',
Expand All @@ -54,7 +48,6 @@ const DashboardPage = () => {
location.href = '/typebots'
})
}
if (redirectPath) push(redirectPath)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isReady])

Expand Down Expand Up @@ -84,4 +77,16 @@ const DashboardPage = () => {
)
}

export async function getServerSideProps(context: NextPageContext) {
const redirectPath = context.query.redirectPath?.toString()
return redirectPath
? {
redirect: {
permanent: false,
destination: redirectPath,
},
}
: { props: {} }
}

export default DashboardPage

2 comments on commit 7b66494

@vercel
Copy link

@vercel vercel bot commented on 7b66494 Mar 7, 2022

@vercel
Copy link

@vercel vercel bot commented on 7b66494 Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.