Skip to content

Commit

Permalink
馃悰 Fix back button refreshing the page when typebot in folder
Browse files Browse the repository at this point in the history
Closes #1297
  • Loading branch information
baptisteArno committed Mar 7, 2024
1 parent 5dafb64 commit 59cf993
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
18 changes: 12 additions & 6 deletions apps/builder/src/features/editor/components/TypebotHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export const TypebotHeader = () => {
)
}

const LeftElements = (props: StackProps & { onHelpClick: () => void }) => {
const LeftElements = ({
onHelpClick,
...props
}: StackProps & { onHelpClick: () => void }) => {
const { t } = useTranslate()
const router = useRouter()
const {
Expand Down Expand Up @@ -144,10 +147,10 @@ const LeftElements = (props: StackProps & { onHelpClick: () => void }) => {
pathname: router.query.parentId
? '/typebots/[typebotId]/edit'
: typebot?.folderId
? '/typebots/folders/[folderId]'
? '/typebots/folders/[id]'
: '/typebots',
query: {
folderId: typebot?.folderId ?? [],
id: typebot?.folderId ?? [],
parentId: Array.isArray(router.query.parentId)
? router.query.parentId.slice(0, -1)
: [],
Expand Down Expand Up @@ -222,7 +225,7 @@ const LeftElements = (props: StackProps & { onHelpClick: () => void }) => {
)}
<Button
leftIcon={<BuoyIcon />}
onClick={props.onHelpClick}
onClick={onHelpClick}
size="sm"
iconSpacing={{ base: 0, xl: 2 }}
>
Expand All @@ -243,7 +246,10 @@ const LeftElements = (props: StackProps & { onHelpClick: () => void }) => {
)
}

const RightElements = (props: StackProps & { isResultsDisplayed: boolean }) => {
const RightElements = ({
isResultsDisplayed,
...props
}: StackProps & { isResultsDisplayed: boolean }) => {
const router = useRouter()
const { t } = useTranslate()
const { typebot, currentUserMode, save } = useTypebot()
Expand All @@ -266,7 +272,7 @@ const RightElements = (props: StackProps & { isResultsDisplayed: boolean }) => {
<TypebotNav
display={{ base: 'none', md: 'flex', xl: 'none' }}
typebotId={typebot?.id}
isResultsDisplayed={props.isResultsDisplayed}
isResultsDisplayed={isResultsDisplayed}
/>
<Flex pos="relative">
<ShareTypebotButton isLoading={isNotDefined(typebot)} />
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/src/features/folders/api/createFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const createFolder = authenticatedProcedure
.input(
z.object({
workspaceId: z.string(),
folderName: z.string().default('New folder'),
folderName: z.string().default(''),
parentFolderId: z.string().optional(),
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import { trpc } from '@/lib/trpc'

export const FolderButton = ({
folder,
index,
onFolderDeleted,
onFolderRenamed,
}: {
folder: DashboardFolder
index: number
onFolderDeleted: () => void
onFolderRenamed: () => void
}) => {
Expand Down Expand Up @@ -124,10 +126,11 @@ export const FolderButton = ({
color={useColorModeValue('blue.500', 'blue.400')}
/>
<Editable
defaultValue={folder.name}
defaultValue={folder.name === '' ? 'New folder' : folder.name}
fontSize="18"
onClick={(e) => e.stopPropagation()}
onSubmit={onRenameSubmit}
startWithEditView={index === 0 && folder.name === ''}
>
<EditablePreview
_hover={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ export const FolderContent = ({ folder }: Props) => {
)}
{isFolderLoading && <ButtonSkeleton />}
{folders &&
folders.map((folder) => (
folders.map((folder, index) => (
<FolderButton
key={folder.id.toString()}
index={index}
folder={folder}
onFolderDeleted={refetchFolders}
onFolderRenamed={() => refetchFolders()}
Expand Down
13 changes: 9 additions & 4 deletions apps/builder/src/features/typebot/api/importTypebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
} from '@typebot.io/schemas'
import { z } from 'zod'
import { getUserRoleInWorkspace } from '@/features/workspace/helpers/getUserRoleInWorkspace'
import { sanitizeGroups, sanitizeSettings } from '../helpers/sanitizers'
import {
sanitizeFolderId,
sanitizeGroups,
sanitizeSettings,
} from '../helpers/sanitizers'
import { preprocessTypebot } from '@typebot.io/schemas/features/typebot/helpers/preprocessTypebot'
import { migrateTypebot } from '@typebot.io/lib/migrations/migrateTypebot'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'
Expand All @@ -29,7 +33,6 @@ const omittedProps = {
resultsTablePreferencesSchema: true,
selectedThemeTemplateId: true,
publicId: true,
folderId: true,
} as const

const importingTypebotSchema = z.preprocess(
Expand Down Expand Up @@ -74,7 +77,6 @@ const migrateImportingTypebot = (
isArchived: false,
whatsAppCredentialsId: null,
publicId: null,
folderId: null,
riskLevel: null,
} satisfies Typebot
return migrateTypebot(fullTypebot)
Expand Down Expand Up @@ -141,7 +143,10 @@ export const importTypebot = authenticatedProcedure
},
}
: {},
folderId: migratedTypebot.folderId,
folderId: await sanitizeFolderId({
folderId: migratedTypebot.folderId,
workspaceId: workspace.id,
}),
variables: migratedTypebot.variables ?? [],
edges: migratedTypebot.edges ?? [],
resultsTablePreferences:
Expand Down
17 changes: 17 additions & 0 deletions apps/builder/src/features/typebot/helpers/sanitizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,20 @@ export const isCustomDomainNotAvailable = async ({

return typebotWithSameDomainCount > 0
}

export const sanitizeFolderId = async ({
folderId,
workspaceId,
}: {
folderId: string | null
workspaceId: string
}) => {
if (!folderId) return
const folderCount = await prisma.dashboardFolder.count({
where: {
id: folderId,
workspaceId,
},
})
return folderCount !== 0 ? folderId : undefined
}
2 changes: 1 addition & 1 deletion packages/forge/blocks/openRouter/logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'

export const OpenRouterLogo = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 512 512" fill="#71717A" stroke="#71717A" {...props}>
<g clip-path="url(#clip0_205_3)">
<g clipPath="url(#clip0_205_3)">
<path
d="M3 248.945C18 248.945 76 236 106 219C136 202 136 202 198 158C276.497 102.293 332 120.945 423 120.945"
strokeWidth="90"
Expand Down

0 comments on commit 59cf993

Please sign in to comment.