Skip to content

Commit

Permalink
readonly editor for not trials
Browse files Browse the repository at this point in the history
  • Loading branch information
ButteryCrumpet authored and Rokt33r committed Jul 20, 2022
1 parent 3e44277 commit 3bd1b58
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/cloud/components/DocPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { useRouter } from '../../lib/router'
import ColoredBlock from '../../../design/components/atoms/ColoredBlock'
import Editor from '../Editor'
import ApplicationPage from '../ApplicationPage'
import { freePlanDocLimit, freePlanMembersLimit } from '../../lib/subscription'
import {
freePlanDocLimit,
freePlanMembersLimit,
teamIsReadonly,
} from '../../lib/subscription'
import { useCloudDocPreview } from '../../lib/hooks/useCloudDocPreview'

interface DocPageProps {
Expand Down Expand Up @@ -197,6 +201,7 @@ const DocPage = ({
backLinks={backLinks}
revisionHistory={revisionHistory}
docIsEditable={docIsEditable}
readonly={teamIsReadonly(team, subscription)}
/>
)
}
Expand Down
5 changes: 4 additions & 1 deletion src/cloud/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ interface EditorProps {
contributors: SerializedUser[]
backLinks: SerializedDoc[]
docIsEditable?: boolean
readonly?: boolean
}

interface EditorPosition {
Expand Down Expand Up @@ -143,6 +144,7 @@ const Editor = ({
contributors,
backLinks,
docIsEditable,
readonly = false,
}: EditorProps) => {
const { translate } = useI18n()
const {
Expand Down Expand Up @@ -258,6 +260,7 @@ const Editor = ({

return {
mode: 'markdown',
readOnly: readonly,
lineNumbers: showEditorLineNumbers,
lineWrapping: true,
theme,
Expand All @@ -281,7 +284,7 @@ const Editor = ({
closeCharacters: /[\s()\[\]{};:>,\n]/,
},
}
}, [settings])
}, [settings, readonly])

const shortcodeConvertMenuStyle: React.CSSProperties = useMemo(() => {
if (shortcodeConvertMenu == null || editorRef.current == null) {
Expand Down
11 changes: 11 additions & 0 deletions src/cloud/lib/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ export function isTimeEligibleForDiscount(team: { createdAt: string }) {
return false
}

export function teamIsReadonly(
team: SerializedTeam,
subscription?: SerializedSubscription
) {
return (
((subscription == null || subscription.status === 'inactive') &&
remainingTrialInfo(team).remaining < 1) ||
subscription != null
)
}

export function remainingTrialInfo(team: SerializedTeam) {
const createDate = new Date(team.createdAt)
const startDate = isBefore(createDate, legacyCutoff)
Expand Down

0 comments on commit 3bd1b58

Please sign in to comment.