🚸(app-impress) warning when resource not editable

When a resource is public, the users can see it
but not edit it. This commit adds a warning message
to the user to tell them that the resource
is not editable.
This commit is contained in:
Anthony LC
2024-04-18 13:23:00 +02:00
committed by Anthony LC
parent 82463be8ec
commit 7107caf50b
4 changed files with 21 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import { BlockNoteView, useCreateBlockNote } from '@blocknote/react';
import '@blocknote/react/style.css';
import { Alert, VariantType } from '@openfun/cunningham-react';
import React, { useEffect, useState } from 'react';
import { WebrtcProvider } from 'y-webrtc';
@@ -57,6 +58,8 @@ export const BlockNoteContent = ({ pad, provider }: BlockNoteContentProps) => {
},
});
editor.isEditable = pad.abilities.partial_update;
useEffect(() => {
setEditor(pad.id, editor);
}, [setEditor, pad.id, editor]);
@@ -69,6 +72,13 @@ export const BlockNoteContent = ({ pad, provider }: BlockNoteContentProps) => {
};
`}
>
{!pad.abilities.partial_update && (
<Box className="m-b" $css="margin-top:0;">
<Alert
type={VariantType.WARNING}
>{`Read only, you don't have the right to update this pad.`}</Alert>
</Box>
)}
<BlockNoteView editor={editor} formattingToolbar={false}>
<BlockNoteToolbar />
</BlockNoteView>

View File

@@ -28,5 +28,6 @@ export interface Pad {
retrieve: boolean;
manage_accesses: boolean;
update: boolean;
partial_update: boolean;
};
}

View File

@@ -52,7 +52,7 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => {
? template.code_editor
: editor.getProjectData();
editor.loadProjectData(projectData);
editor?.loadProjectData(projectData);
editor.Storage.add('remote', {
load() {
@@ -118,6 +118,14 @@ export const TemplateEditor = ({ template }: TemplateEditorProps) => {
</Box>
)}
{!template.abilities.partial_update && (
<Box className="m-b" $css="margin-top:0;">
<Alert
type={VariantType.WARNING}
>{`Read only, you don't have the right to update this template.`}</Alert>
</Box>
)}
<Box className="m-b" $css="margin-top:0;flex:1;" $overflow="auto">
<GjsEditor
grapesjs={grapesjs}

View File

@@ -27,6 +27,7 @@ export interface Template {
manage_accesses: boolean;
retrieve: boolean;
update: boolean;
partial_update: boolean;
};
accesses: Access[];
code_editor: ProjectData;