Skip to content

Commit

Permalink
feat(OUT-1212): show NoPreviewSupport while accessing from CRM preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rrojan committed Dec 31, 2024
1 parent 1926a67 commit 5894d17
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/app/client-preview/NoPreviewSupport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Box } from '@mui/material'
import AnnouncementIcon from '@mui/icons-material/Announcement'

export const NoPreviewSupport = () => {
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100vh',
fontSize: '24px',
}}
>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: '4px',
opacity: '0.8',
}}
>
<Box sx={{ display: 'flex' }}>
<AnnouncementIcon />
</Box>
<div>CRM preview is currently not supported for Client Home</div>{' '}
</Box>
</Box>
)
}
12 changes: 10 additions & 2 deletions src/app/client-preview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { CopilotAPI } from '@/utils/copilotApiUtils'
import InvalidToken from '../components/InvalidToken'
import { defaultState } from '../../../defaultState'
import { defaultBannerImagePath, defaultBgColor } from '@/utils/constants'
import { getPreviewMode } from '@/utils/previewMode'
import { NoPreviewSupport } from './NoPreviewSupport'

export const revalidate = 0

Expand Down Expand Up @@ -56,6 +58,14 @@ export default async function ClientPreviewPage({
}

const token = tokenParsed.data
const copilotClient = new CopilotAPI(token)
const tokenPayload = await copilotClient.getTokenPayload()
if (!tokenPayload) {
throw new Error('Failed to parse token payload')
}
if (getPreviewMode(tokenPayload)) {
return <NoPreviewSupport />
}

const clientId = z.string().uuid().parse(searchParams.clientId)

Expand All @@ -75,8 +85,6 @@ export default async function ClientPreviewPage({
displayTasks: false,
}

const copilotClient = new CopilotAPI(token)

const [defaultSetting, allCustomFields, _client, workspace] =
await Promise.all([
getSettings(token),
Expand Down
18 changes: 18 additions & 0 deletions src/utils/previewMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Token } from '@/types/common'

export type PreviewMode = 'client' | 'company' | null

export const getPreviewMode = (tokenPayload: Token): PreviewMode => {
const isClientPreview = tokenPayload.internalUserId && tokenPayload.clientId
// For a company to be alongside IU token, it shouldn't be "default" or undefined
// Older workspaces in Copilot have "default" as companyId, while newer ones have undefined for IUs
const isDefaultCompany = tokenPayload.companyId === 'default'
const isCompanyPreview =
tokenPayload.internalUserId && !isDefaultCompany && !!tokenPayload.companyId
const previewMode: PreviewMode = isClientPreview
? 'client'
: isCompanyPreview
? 'company'
: null
return previewMode
}

0 comments on commit 5894d17

Please sign in to comment.