Skip to content

Commit 3bd1b58

Browse files
ButteryCrumpetRokt33r
authored andcommitted
readonly editor for not trials
1 parent 3e44277 commit 3bd1b58

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/cloud/components/DocPage/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import { useRouter } from '../../lib/router'
2121
import ColoredBlock from '../../../design/components/atoms/ColoredBlock'
2222
import Editor from '../Editor'
2323
import ApplicationPage from '../ApplicationPage'
24-
import { freePlanDocLimit, freePlanMembersLimit } from '../../lib/subscription'
24+
import {
25+
freePlanDocLimit,
26+
freePlanMembersLimit,
27+
teamIsReadonly,
28+
} from '../../lib/subscription'
2529
import { useCloudDocPreview } from '../../lib/hooks/useCloudDocPreview'
2630

2731
interface DocPageProps {
@@ -197,6 +201,7 @@ const DocPage = ({
197201
backLinks={backLinks}
198202
revisionHistory={revisionHistory}
199203
docIsEditable={docIsEditable}
204+
readonly={teamIsReadonly(team, subscription)}
200205
/>
201206
)
202207
}

src/cloud/components/Editor/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface EditorProps {
116116
contributors: SerializedUser[]
117117
backLinks: SerializedDoc[]
118118
docIsEditable?: boolean
119+
readonly?: boolean
119120
}
120121

121122
interface EditorPosition {
@@ -143,6 +144,7 @@ const Editor = ({
143144
contributors,
144145
backLinks,
145146
docIsEditable,
147+
readonly = false,
146148
}: EditorProps) => {
147149
const { translate } = useI18n()
148150
const {
@@ -258,6 +260,7 @@ const Editor = ({
258260

259261
return {
260262
mode: 'markdown',
263+
readOnly: readonly,
261264
lineNumbers: showEditorLineNumbers,
262265
lineWrapping: true,
263266
theme,
@@ -281,7 +284,7 @@ const Editor = ({
281284
closeCharacters: /[\s()\[\]{};:>,\n]/,
282285
},
283286
}
284-
}, [settings])
287+
}, [settings, readonly])
285288

286289
const shortcodeConvertMenuStyle: React.CSSProperties = useMemo(() => {
287290
if (shortcodeConvertMenu == null || editorRef.current == null) {

src/cloud/lib/subscription.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ export function isTimeEligibleForDiscount(team: { createdAt: string }) {
3737
return false
3838
}
3939

40+
export function teamIsReadonly(
41+
team: SerializedTeam,
42+
subscription?: SerializedSubscription
43+
) {
44+
return (
45+
((subscription == null || subscription.status === 'inactive') &&
46+
remainingTrialInfo(team).remaining < 1) ||
47+
subscription != null
48+
)
49+
}
50+
4051
export function remainingTrialInfo(team: SerializedTeam) {
4152
const createDate = new Date(team.createdAt)
4253
const startDate = isBefore(createDate, legacyCutoff)

0 commit comments

Comments
 (0)