2
0

chore(editor): ♻️ Revert tables to arrays

Yet another refacto. I improved many many mechanisms on this one including dnd. It is now end 2 end tested 🎉
This commit is contained in:
Baptiste Arnaud
2022-02-04 19:00:08 +01:00
parent 8a350eee6c
commit 524ef0812c
123 changed files with 2998 additions and 3112 deletions

View File

@@ -5,7 +5,6 @@ import { upsertAnswer } from 'services/answer'
import { SEO } from '../components/Seo'
import { createResult, updateResult } from '../services/result'
import { ErrorPage } from './ErrorPage'
import { NotFoundPage } from './NotFoundPage'
export type TypebotPageProps = {
typebot?: PublicTypebot
@@ -15,7 +14,11 @@ export type TypebotPageProps = {
const sessionStorageKey = 'resultId'
export const TypebotPage = ({ typebot, isIE, url }: TypebotPageProps) => {
export const TypebotPage = ({
typebot,
isIE,
url,
}: TypebotPageProps & { typebot: PublicTypebot }) => {
const [error, setError] = useState<Error | undefined>(
isIE ? new Error('Internet explorer is not supported') : undefined
)
@@ -27,7 +30,6 @@ export const TypebotPage = ({ typebot, isIE, url }: TypebotPageProps) => {
}, [])
const initializeResult = async () => {
if (!typebot) return
const resultIdFromSession = sessionStorage.getItem(sessionStorageKey)
if (resultIdFromSession) setResultId(resultIdFromSession)
else {
@@ -52,9 +54,6 @@ export const TypebotPage = ({ typebot, isIE, url }: TypebotPageProps) => {
if (error) setError(error)
}
if (!typebot) {
return <NotFoundPage />
}
if (error) {
return <ErrorPage error={error} />
}

View File

@@ -1,3 +1,4 @@
import { NotFoundPage } from 'layouts/NotFoundPage'
import { PublicTypebot } from 'models'
import { GetServerSideProps, GetServerSidePropsContext } from 'next'
import { TypebotPage, TypebotPageProps } from '../layouts/TypebotPage'
@@ -12,7 +13,6 @@ export const getServerSideProps: GetServerSideProps = async (
try {
if (!context.req.headers.host) return { props: {} }
typebot = await getTypebotFromPublicId(context.query.publicId?.toString())
if (!typebot) return { props: {} }
return {
props: {
typebot,
@@ -41,5 +41,7 @@ const getTypebotFromPublicId = async (
return (typebot as unknown as PublicTypebot | undefined) ?? undefined
}
const App = (props: TypebotPageProps) => <TypebotPage {...props} />
const App = ({ typebot, ...props }: TypebotPageProps) =>
typebot ? <TypebotPage typebot={typebot} {...props} /> : <NotFoundPage />
export default App

View File

@@ -1,3 +1,4 @@
import { NotFoundPage } from 'layouts/NotFoundPage'
import { PublicTypebot } from 'models'
import { GetServerSideProps, GetServerSidePropsContext } from 'next'
import { TypebotPage, TypebotPageProps } from '../layouts/TypebotPage'
@@ -12,7 +13,6 @@ export const getServerSideProps: GetServerSideProps = async (
try {
if (!context.req.headers.host) return { props: {} }
typebot = await getTypebotFromUrl(context.req.headers.host)
if (!typebot) return { props: {} }
return {
props: {
typebot,
@@ -42,5 +42,6 @@ const getTypebotFromUrl = async (
return (typebot as unknown as PublicTypebot | undefined) ?? undefined
}
const App = (props: TypebotPageProps) => <TypebotPage {...props} />
const App = ({ typebot, ...props }: TypebotPageProps) =>
typebot ? <TypebotPage {...props} typebot={typebot} /> : <NotFoundPage />
export default App