diff --git a/services/web/frontend/js/features/pdf-preview/components/compile-timeout-changing-soon.tsx b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-changing-soon.tsx new file mode 100644 index 0000000000..ca8b7c0918 --- /dev/null +++ b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-changing-soon.tsx @@ -0,0 +1,109 @@ +import Notification from '@/shared/components/notification' +import StartFreeTrialButton from '@/shared/components/start-free-trial-button' +import { Trans, useTranslation } from 'react-i18next' +import * as eventTracking from '@/infrastructure/event-tracking' +import { FC } from 'react' + +const sendInfoClickEvent = () => { + eventTracking.sendMB('paywall-info-click', { + 'paywall-type': 'compile-time-warning', + content: 'blog', + }) +} + +export const CompileTimeoutChangingSoon: FC<{ + isProjectOwner?: boolean + handleDismissChangingSoon: () => void +}> = ({ isProjectOwner = false, handleDismissChangingSoon }) => { + const { t } = useTranslation() + + const compileTimeoutBlogLinks = [ + /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */ + , + /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */ + , + ] + + if (isProjectOwner) { + return ( + + {t('start_free_trial_without_exclamation')} + + } + ariaLive="polite" + content={ +
+

+ {' '} + }} + /> +

+
+ } + title={t('your_project_compiled_but_soon_might_not')} + type="warning" + isActionBelowContent + isDismissible + onDismiss={handleDismissChangingSoon} + /> + ) + } + + return ( + +

+ +

+

+ }} + /> +

+ + } + title={t('this_project_compiled_but_soon_might_not')} + type="warning" + isDismissible + onDismiss={handleDismissChangingSoon} + /> + ) +} diff --git a/services/web/frontend/js/features/pdf-preview/components/compile-timeout-messages.tsx b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-messages.tsx index 571799b661..fcb939a549 100644 --- a/services/web/frontend/js/features/pdf-preview/components/compile-timeout-messages.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-messages.tsx @@ -1,10 +1,9 @@ -import { memo, useCallback, useEffect, useState, useMemo } from 'react' -import * as eventTracking from '../../../infrastructure/event-tracking' -import { useDetachCompileContext } from '../../../shared/context/detach-compile-context' -import usePersistedState from '../../../shared/hooks/use-persisted-state' -import Notification from '../../../shared/components/notification' -import { Trans, useTranslation } from 'react-i18next' -import StartFreeTrialButton from '@/shared/components/start-free-trial-button' +import { memo, useCallback, useEffect, useMemo, useState } from 'react' +import * as eventTracking from '@/infrastructure/event-tracking' +import { useDetachCompileContext } from '@/shared/context/detach-compile-context' +import usePersistedState from '@/shared/hooks/use-persisted-state' +import { CompileTimeoutWarning } from '@/features/pdf-preview/components/compile-timeout-warning' +import { CompileTimeoutChangingSoon } from '@/features/pdf-preview/components/compile-timeout-changing-soon' function CompileTimeoutMessages() { const { @@ -16,8 +15,6 @@ function CompileTimeoutMessages() { error, } = useDetachCompileContext() - const { t } = useTranslation() - const [showWarning, setShowWarning] = useState(false) const [showChangingSoon, setShowChangingSoon] = useState(false) const [dismissedUntilWarning, setDismissedUntilWarning] = usePersistedState< @@ -105,140 +102,23 @@ function CompileTimeoutMessages() { return null } - function sendInfoClickEvent() { - eventTracking.sendMB('paywall-info-click', { - 'paywall-type': 'compile-time-warning', - content: 'blog', - }) - } - - const compileTimeoutBlogLinks = [ - /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */ -
, - /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */ - , - ] - // if showWarning is true then the 10s warning is shown // and if showChangingSoon is true then the 20s-60s should show return (
{showWarning && isProjectOwner && ( - - {t('start_free_trial_without_exclamation')} - - } - ariaLive="polite" - content={ -
-
- {t('your_project_near_compile_timeout_limit')} -
- {showNewCompileTimeoutUI === 'active' ? ( - <> - {t('upgrade_for_12x_more_compile_time')} - {'. '} - - ) : ( - {t('upgrade_for_plenty_more_compile_time')} - )} -
- } - type="warning" - title={t('took_a_while')} - isActionBelowContent - isDismissible - onDismiss={handleDismissWarning} + + )} + {showChangingSoon && ( + )} - {showChangingSoon && - (isProjectOwner ? ( - - {t('start_free_trial_without_exclamation')} - - } - ariaLive="polite" - content={ -
-

- {' '} - }} - /> -

-
- } - title={t('your_project_compiled_but_soon_might_not')} - type="warning" - isActionBelowContent - isDismissible - onDismiss={handleDismissChangingSoon} - /> - ) : ( - -

- -

-

- }} - /> -

-
- } - title={t('this_project_compiled_but_soon_might_not')} - type="warning" - isDismissible - onDismiss={handleDismissChangingSoon} - /> - ))} ) } diff --git a/services/web/frontend/js/features/pdf-preview/components/compile-timeout-warning.tsx b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-warning.tsx new file mode 100644 index 0000000000..485890381e --- /dev/null +++ b/services/web/frontend/js/features/pdf-preview/components/compile-timeout-warning.tsx @@ -0,0 +1,48 @@ +import Notification from '@/shared/components/notification' +import StartFreeTrialButton from '@/shared/components/start-free-trial-button' +import { useTranslation } from 'react-i18next' +import { FC } from 'react' + +export const CompileTimeoutWarning: FC<{ + handleDismissWarning: () => void + showNewCompileTimeoutUI: string +}> = ({ handleDismissWarning, showNewCompileTimeoutUI }) => { + const { t } = useTranslation() + + return ( + + {t('start_free_trial_without_exclamation')} + + } + ariaLive="polite" + content={ +
+
+ {t('your_project_near_compile_timeout_limit')} +
+ {showNewCompileTimeoutUI === 'active' ? ( + <> + {t('upgrade_for_12x_more_compile_time')} + {'. '} + + ) : ( + {t('upgrade_for_plenty_more_compile_time')} + )} +
+ } + type="warning" + title={t('took_a_while')} + isActionBelowContent + isDismissible + onDismiss={handleDismissWarning} + /> + ) +} diff --git a/services/web/frontend/stories/pdf-preview-messages.stories.tsx b/services/web/frontend/stories/pdf-preview-messages.stories.tsx new file mode 100644 index 0000000000..87c0a49a2e --- /dev/null +++ b/services/web/frontend/stories/pdf-preview-messages.stories.tsx @@ -0,0 +1,60 @@ +import { useEffect } from 'react' +import { ScopeDecorator } from './decorators/scope' +import { useLocalCompileContext } from '@/shared/context/local-compile-context' +import { PdfPreviewMessages } from '@/features/pdf-preview/components/pdf-preview-messages' +import CompileTimeWarning from '@/features/pdf-preview/components/compile-time-warning' +import { CompileTimeoutChangingSoon } from '@/features/pdf-preview/components/compile-timeout-changing-soon' +import { CompileTimeoutWarning } from '@/features/pdf-preview/components/compile-timeout-warning' + +export default { + title: 'Editor / PDF Preview / Messages', + component: PdfPreviewMessages, + decorators: [ + ScopeDecorator, + (Story: any) => ( +
+ + + +
+ ), + ], +} + +export const CompileTime = () => { + const { setShowCompileTimeWarning } = useLocalCompileContext() + + useEffect(() => { + setShowCompileTimeWarning(true) + }, [setShowCompileTimeWarning]) + + return +} + +export const CompileTimeoutChangingSoonNotProjectOwner = (args: any) => { + return +} +CompileTimeoutChangingSoonNotProjectOwner.argTypes = { + handleDismissChangingSoon: { action: 'dismiss changing soon' }, +} + +export const CompileTimeoutChangingSoonProjectOwner = (args: any) => { + return +} +CompileTimeoutChangingSoonProjectOwner.argTypes = { + handleDismissChangingSoon: { action: 'dismiss changing soon' }, +} + +export const CompileTimeoutWarningActive = (args: any) => { + return +} +CompileTimeoutWarningActive.argTypes = { + handleDismissWarning: { action: 'dismiss warning' }, +} + +export const CompileTimeoutWarningChanging = (args: any) => { + return +} +CompileTimeoutWarningChanging.argTypes = { + handleDismissWarning: { action: 'dismiss warning' }, +}