Skip to content

Commit

Permalink
fix: Layout and theme of onboarding for 3000 (#18503)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Nov 10, 2023
1 parent 0d26804 commit bc18936
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"DATABASE_URL": "postgres://posthog:posthog@localhost:5432/posthog",
"SKIP_SERVICE_VERSION_REQUIREMENTS": "1",
"PRINT_SQL": "1",
"REPLAY_EVENTS_NEW_CONSUMER_RATIO": "1.0"
"REPLAY_EVENTS_NEW_CONSUMER_RATIO": "1.0",
"BILLING_SERVICE_URL": "https://billing.dev.posthog.dev"
},
"console": "integratedTerminal",
"python": "${workspaceFolder}/env/bin/python",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions frontend/src/layout/GlobalModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { CreateOrganizationModal } from 'scenes/organization/CreateOrganizationM
import { CreateProjectModal } from 'scenes/project/CreateProjectModal'

import type { globalModalsLogicType } from './GlobalModalsType'
import { FeaturePreviewsModal } from './FeaturePreviews'
import { UpgradeModal } from 'scenes/UpgradeModal'
import { LemonModal } from '@posthog/lemon-ui'
import { Setup2FA } from 'scenes/authentication/Setup2FA'
import { userLogic } from 'scenes/userLogic'
import { membersLogic } from 'scenes/organization/membersLogic'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
import { Prompt } from 'lib/logic/newPrompt/Prompt'
import { inviteLogic } from 'scenes/settings/organization/inviteLogic'
import { InviteModal } from 'scenes/settings/organization/InviteModal'

Expand Down Expand Up @@ -37,12 +45,37 @@ export function GlobalModals(): JSX.Element {
const { hideCreateOrganizationModal, hideCreateProjectModal } = useActions(globalModalsLogic)
const { isInviteModalShown } = useValues(inviteLogic)
const { hideInviteModal } = useActions(inviteLogic)
const { user } = useValues(userLogic)

return (
<>
<InviteModal isOpen={isInviteModalShown} onClose={hideInviteModal} />
<CreateOrganizationModal isVisible={isCreateOrganizationModalShown} onClose={hideCreateOrganizationModal} />
<CreateProjectModal isVisible={isCreateProjectModalShown} onClose={hideCreateProjectModal} />
<FeaturePreviewsModal />
<UpgradeModal />

{user && user.organization?.enforce_2fa && !user.is_2fa_enabled && (
<LemonModal title="Set up 2FA" closable={false}>
<p>
<b>Your organization requires you to set up 2FA.</b>
</p>
<p>
<b>
Use an authenticator app like Google Authenticator or 1Password to scan the QR code below.
</b>
</p>
<Setup2FA
onSuccess={() => {
userLogic.actions.loadUser()
membersLogic.actions.loadMembers()
}}
/>
</LemonModal>
)}
<FlaggedFeature flag="enable-prompts">
<Prompt />
</FlaggedFeature>
</>
)
}
5 changes: 3 additions & 2 deletions frontend/src/layout/navigation-3000/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Scene, SceneConfig } from 'scenes/sceneTypes'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
import { FEATURE_FLAGS } from 'lib/constants'
import { SidePanel } from './sidepanel/SidePanel'
import { GlobalModals } from '../GlobalModals'

export function Navigation({
children,
Expand All @@ -30,6 +29,9 @@ export function Navigation({
document.getElementById('bottom-notice')?.remove()
}, [])

if (sceneConfig?.layout === 'plain') {
return <>{children}</>
}
return (
<div className="Navigation3000">
<Navbar />
Expand All @@ -49,7 +51,6 @@ export function Navigation({
</main>
<SidePanel />
<CommandPalette />
<GlobalModals />
</div>
)
}
14 changes: 12 additions & 2 deletions frontend/src/layout/navigation-3000/themeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'

import type { themeLogicType } from './themeLogicType'
import { sceneLogic } from 'scenes/sceneLogic'

export const themeLogic = kea<themeLogicType>([
path(['layout', 'navigation-3000', 'themeLogic']),
Expand Down Expand Up @@ -32,8 +33,17 @@ export const themeLogic = kea<themeLogicType>([
}),
selectors({
isDarkModeOn: [
(s) => [s.darkModeSavedPreference, s.darkModeSystemPreference, featureFlagLogic.selectors.featureFlags],
(darkModeSavedPreference, darkModeSystemPreference, featureFlags) => {
(s) => [
s.darkModeSavedPreference,
s.darkModeSystemPreference,
featureFlagLogic.selectors.featureFlags,
sceneLogic.selectors.sceneConfig,
],
(darkModeSavedPreference, darkModeSystemPreference, featureFlags, sceneConfig) => {
// NOTE: Unauthenticated users always get the light mode until we have full support across onboarding flows
if (sceneConfig?.layout === 'plain' || sceneConfig?.allowUnauthenticated) {
return false
}
// Dark mode is a PostHog 3000 feature
// User-saved preference is used when set, oterwise we fall back to the system value
return featureFlags[FEATURE_FLAGS.POSTHOG_3000]
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/layout/navigation/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { NotebookButton } from '~/layout/navigation/TopBar/NotebookButton'
import { ActivationSidebarToggle } from 'lib/components/ActivationSidebar/ActivationSidebarToggle'
import { GlobalModals } from '~/layout/GlobalModals'

export function TopBar(): JSX.Element {
const { isSideBarShown, noSidebar, minimalTopBar, mobileLayout } = useValues(navigationLogic)
Expand Down Expand Up @@ -83,7 +82,6 @@ export function TopBar(): JSX.Element {
</div>
</header>
<CommandPalette />
<GlobalModals />
</>
)
}
10 changes: 4 additions & 6 deletions frontend/src/lib/logic/featureFlagLogic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { kea, path, actions, reducers, events } from 'kea'
import { kea, path, actions, reducers, afterMount } from 'kea'
import type { featureFlagLogicType } from './featureFlagLogicType'
import posthog from 'posthog-js'
import { getAppContext } from 'lib/utils/getAppContext'
Expand Down Expand Up @@ -84,9 +84,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
},
],
}),
events(({ actions }) => ({
afterMount: () => {
posthog.onFeatureFlags(actions.setFeatureFlags)
},
})),
afterMount(({ actions }) => {
posthog.onFeatureFlags(actions.setFeatureFlags)
}),
])
29 changes: 2 additions & 27 deletions frontend/src/scenes/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ToastContainer, Slide } from 'react-toastify'
import { preflightLogic } from './PreflightCheck/preflightLogic'
import { userLogic } from 'scenes/userLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { UpgradeModal } from './UpgradeModal'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import type { appLogicType } from './AppType'
import { models } from '~/models'
Expand All @@ -18,15 +17,11 @@ import { ToastCloseButton } from 'lib/lemon-ui/lemonToast'
import { frontendAppsLogic } from 'scenes/apps/frontendAppsLogic'
import { inAppPromptLogic } from 'lib/logic/inAppPrompt/inAppPromptLogic'
import { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'
import { LemonModal } from '@posthog/lemon-ui'
import { Setup2FA } from './authentication/Setup2FA'
import { membersLogic } from './organization/membersLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { Navigation as Navigation3000 } from '~/layout/navigation-3000/Navigation'
import { Prompt } from 'lib/logic/newPrompt/Prompt'
import { useEffect } from 'react'
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { FeaturePreviewsModal } from '~/layout/FeaturePreviews'
import { GlobalModals } from '~/layout/GlobalModals'

export const appLogic = kea<appLogicType>([
path(['scenes', 'App']),
Expand Down Expand Up @@ -182,27 +177,7 @@ function AppScene(): JSX.Element | null {
{wrappedSceneElement}
</Navigation>
{toastContainer}
<FeaturePreviewsModal />
<UpgradeModal />
{user.organization?.enforce_2fa && !user.is_2fa_enabled && (
<LemonModal title="Set up 2FA" closable={false}>
<p>
<b>Your organization requires you to set up 2FA.</b>
</p>
<p>
<b>
Use an authenticator app like Google Authenticator or 1Password to scan the QR code below.
</b>
</p>
<Setup2FA
onSuccess={() => {
userLogic.actions.loadUser()
membersLogic.actions.loadMembers()
}}
/>
</LemonModal>
)}
{featureFlags[FEATURE_FLAGS.ENABLE_PROMPTS] && <Prompt />}
<GlobalModals />
</>
)
}
1 change: 1 addition & 0 deletions frontend/src/scenes/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const sceneConfigurations: Partial<Record<Scene, SceneConfig>> = {
},
[Scene.Unsubscribe]: {
allowUnauthenticated: true,
layout: 'app-raw',
},
[Scene.DebugQuery]: {
projectBased: true,
Expand Down
1 change: 0 additions & 1 deletion posthog/api/test/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def preflight_dict(self, options={}):
def preflight_authenticated_dict(self, options={}):
preflight = {
"opt_out_capture": False,
"is_debug": False,
"licensed_users_available": None,
"site_url": "http://localhost:8000",
"can_create_org": False,
Expand Down
4 changes: 3 additions & 1 deletion posthog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ def preflight_check(request: HttpRequest) -> JsonResponse:
"object_storage": is_cloud() or is_object_storage_available(),
}

if settings.DEBUG or settings.E2E_TESTING:
response["is_debug"] = True

if request.user.is_authenticated:
response = {
**response,
"available_timezones": get_available_timezones_with_offsets(),
"opt_out_capture": os.environ.get("OPT_OUT_CAPTURE", False),
"is_debug": settings.DEBUG or settings.E2E_TESTING,
"licensed_users_available": get_licensed_users_available() if not is_cloud() else None,
"openai_available": bool(os.environ.get("OPENAI_API_KEY")),
"site_url": settings.SITE_URL,
Expand Down

0 comments on commit bc18936

Please sign in to comment.