Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/JS-5520: Read only chat form #972

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/json/text.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
"blockChatMessageEdited": "(edited)",
"blockChatEditing": "Editing message",
"blockChatReplying": "Replying to %s",
"blockChatFormReadonly": "Only editors can send messages. Contact the owner to request access.",

"popupSettingsTitle": "Settings",
"popupSettingsAccountPersonalInformationTitle": "Personal information",
Expand Down
6 changes: 6 additions & 0 deletions src/scss/block/chat/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@

.icon.send { position: absolute; bottom: 10px; right: 16px; width: 20px; height: 20px; background: url('~img/icon/chat/buttons/send.svg'); }
}

.formWrapperReadonly {
display: flex; justify-content: center; align-items: center; gap: 0px 8px; height: 40px; border-radius: 8px; @include text-small;
border: 1px solid var(--color-shape-primary); background: var(--color-shape-tertiary);
}
.formWrapperReadonly::before { content: ''; display: block; width: 8px; height: 12px; background: url('~img/icon/lock.svg'); }
51 changes: 32 additions & 19 deletions src/ts/component/block/chat/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
const { space } = S.Common;
const value = this.getTextValue();

if (readonly) {
return (
<div id="formWrapper" className="formWrapper">
<div className="formWrapperReadonly">{translate('blockChatFormReadonly')}</div>
</div>
);
};

let title = '';
let text = '';
let icon: any = null;
Expand Down Expand Up @@ -140,7 +148,6 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
<Editable
ref={ref => this.refEditable = ref}
id="messageBox"
readonly={readonly}
maxLength={J.Constant.limit.chat.text}
placeholder={translate('blockChatPlaceholder')}
onSelect={this.onSelect}
Expand Down Expand Up @@ -171,24 +178,22 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
</div>
) : ''}

{!readonly ? (
<Buttons
ref={ref => this.refButtons = ref}
{...this.props}
value={value}
hasSelection={this.hasSelection}
getMarksAndRange={this.getMarksAndRange}
attachments={attachments}
caretMenuParam={this.caretMenuParam}
onMention={this.onMention}
onChatButtonSelect={this.onChatButtonSelect}
onTextButtonToggle={this.onTextButtonToggle}
getObjectFromPath={this.getObjectFromPath}
addAttachments={this.addAttachments}
onMenuClose={this.onMenuClose}
removeBookmark={this.removeBookmark}
/>
) : ''}
<Buttons
ref={ref => this.refButtons = ref}
{...this.props}
value={value}
hasSelection={this.hasSelection}
getMarksAndRange={this.getMarksAndRange}
attachments={attachments}
caretMenuParam={this.caretMenuParam}
onMention={this.onMention}
onChatButtonSelect={this.onChatButtonSelect}
onTextButtonToggle={this.onTextButtonToggle}
getObjectFromPath={this.getObjectFromPath}
addAttachments={this.addAttachments}
onMenuClose={this.onMenuClose}
removeBookmark={this.removeBookmark}
/>

<Icon id="send" className="send" onClick={this.onSend} />
</div>
Expand All @@ -197,6 +202,10 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
};

componentDidMount () {
if (this.props.readonly) {
return;
};

this._isMounted = true;
this.checkSendButton();

Expand All @@ -219,6 +228,10 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> {
};

componentDidUpdate () {
if (this.props.readonly) {
return;
};

this.renderMarkup();
this.checkSendButton();
};
Expand Down
Loading