Skip to content

Commit 19a642d

Browse files
committed
fix doc preview and context menu with viewer role
1 parent 942d739 commit 19a642d

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

src/cloud/components/DocPage/DocContextMenuActions.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,21 @@ export function DocContextMenuActions({
315315
},
316316
}}
317317
/>
318-
<MetadataContainerRow
319-
row={{
320-
type: 'button',
321-
props: {
322-
id: 'metadata-duplicate-link',
323-
label: translate(lngKeys.GeneralDuplicate),
324-
iconPath: mdiContentDuplicate,
325-
spinning: duplicated,
326-
disabled: duplicated,
327-
onClick: duplicateButtonHandler,
328-
},
329-
}}
330-
/>
318+
{currentUserIsCoreMember && (
319+
<MetadataContainerRow
320+
row={{
321+
type: 'button',
322+
props: {
323+
id: 'metadata-duplicate-link',
324+
label: translate(lngKeys.GeneralDuplicate),
325+
iconPath: mdiContentDuplicate,
326+
spinning: duplicated,
327+
disabled: duplicated,
328+
onClick: duplicateButtonHandler,
329+
},
330+
}}
331+
/>
332+
)}
331333
<MetadataContainerRow
332334
row={{
333335
type: 'button',

src/cloud/components/DocPreview/DocPreviewRealtime.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { SerializedSubscription } from '../../interfaces/db/subscription'
3434

3535
interface DocPreviewRealtimeProps {
3636
team: SerializedTeam
37+
currentUserIsCoreMember: boolean
3738
subscription?: SerializedSubscription
3839
doc: SerializedDocWithSupplemental
3940
token: string
@@ -49,6 +50,7 @@ const DocPreviewRealtime = ({
4950
token,
5051
user,
5152
subscription,
53+
currentUserIsCoreMember,
5254
setRenderHeader,
5355
}: DocPreviewRealtimeProps) => {
5456
const [loaded, setLoaded] = useState(false)
@@ -207,6 +209,24 @@ const DocPreviewRealtime = ({
207209
)
208210
}
209211

212+
if (!currentUserIsCoreMember) {
213+
return (
214+
<Container>
215+
<StyledEditor className={cc(['preview', 'doc-preview__editor'])}>
216+
<StyledPreview className={`layout-preview`}>
217+
<CustomizedMarkdownPreviewer
218+
content={editorContent}
219+
updateContent={setEditorRefContent}
220+
headerLinks={true}
221+
className='doc-preview__content__scroller'
222+
getEmbed={getEmbed}
223+
/>
224+
</StyledPreview>
225+
</StyledEditor>
226+
</Container>
227+
)
228+
}
229+
210230
return (
211231
<>
212232
<Container>

src/cloud/components/DocPreview/index.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ const DocPreviewModal = ({ doc, team, fallbackUrl }: DocPreviewModalProps) => {
113113
)
114114

115115
const toggleViewMode = useCallback(() => {
116+
if (!currentUserIsCoreMember) {
117+
return
118+
}
116119
setMode((prev) => (prev === 'preview' ? 'editor' : 'preview'))
117-
}, [])
120+
}, [currentUserIsCoreMember])
118121

119122
useEffect(() => {
120123
togglePreviewModeEventEmitter.listen(toggleViewMode)
@@ -163,15 +166,17 @@ const DocPreviewModal = ({ doc, team, fallbackUrl }: DocPreviewModalProps) => {
163166
</Button>
164167
<Flexbox className='doc-preview__actions'>
165168
{renderHeader}
166-
<Button
167-
variant='icon'
168-
iconPath={mode === 'preview' ? mdiPencil : mdiEyeOutline}
169-
onClick={() =>
170-
setMode((prev) => (prev === 'preview' ? 'editor' : 'preview'))
171-
}
172-
id='doc-preview__edit'
173-
size='sm'
174-
/>
169+
{currentUserIsCoreMember && (
170+
<Button
171+
variant='icon'
172+
iconPath={mode === 'preview' ? mdiPencil : mdiEyeOutline}
173+
onClick={() =>
174+
setMode((prev) => (prev === 'preview' ? 'editor' : 'preview'))
175+
}
176+
id='doc-preview__edit'
177+
size='sm'
178+
/>
179+
)}
175180
<Button
176181
variant='icon'
177182
iconPath={mdiDotsHorizontal}
@@ -227,6 +232,7 @@ const DocPreviewModal = ({ doc, team, fallbackUrl }: DocPreviewModalProps) => {
227232
user={currentUser}
228233
mode={mode}
229234
subscription={subscription}
235+
currentUserIsCoreMember={currentUserIsCoreMember}
230236
/>
231237
)}
232238
</div>

0 commit comments

Comments
 (0)