[WEB-2233] fix: intake issue comment (#5368)
* fix: intake issue comment * chore: issue comment improvement
This commit is contained in:
parent
4a71eef72e
commit
3e83eed398
9 changed files with 34 additions and 32 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { Extension } from "@tiptap/core";
|
import { Extension } from "@tiptap/core";
|
||||||
|
|
||||||
export const EnterKeyExtension = (onEnterKeyPress?: (descriptionHTML: string) => void) =>
|
export const EnterKeyExtension = (onEnterKeyPress?: () => void) =>
|
||||||
Extension.create({
|
Extension.create({
|
||||||
name: "enterKey",
|
name: "enterKey",
|
||||||
|
|
||||||
|
|
@ -8,7 +8,9 @@ export const EnterKeyExtension = (onEnterKeyPress?: (descriptionHTML: string) =>
|
||||||
return {
|
return {
|
||||||
Enter: () => {
|
Enter: () => {
|
||||||
if (!this.editor.storage.mentionsOpen) {
|
if (!this.editor.storage.mentionsOpen) {
|
||||||
onEnterKeyPress?.(this.editor.getHTML());
|
if (onEnterKeyPress) {
|
||||||
|
onEnterKeyPress();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export interface IEditorProps {
|
||||||
suggestions?: () => Promise<IMentionSuggestion[]>;
|
suggestions?: () => Promise<IMentionSuggestion[]>;
|
||||||
};
|
};
|
||||||
onChange?: (json: object, html: string) => void;
|
onChange?: (json: object, html: string) => void;
|
||||||
onEnterKeyPress?: (descriptionHTML: string) => void;
|
onEnterKeyPress?: (e?: any) => void;
|
||||||
placeholder?: string | ((isFocused: boolean, value: string) => string);
|
placeholder?: string | ((isFocused: boolean, value: string) => string);
|
||||||
tabIndex?: number;
|
tabIndex?: number;
|
||||||
value?: string | null;
|
value?: string | null;
|
||||||
|
|
|
||||||
|
|
@ -64,11 +64,7 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
|
||||||
}}
|
}}
|
||||||
isSubmitting={isSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
showSubmitButton={showSubmitButton}
|
showSubmitButton={showSubmitButton}
|
||||||
handleSubmit={() => {
|
handleSubmit={(e) => rest.onEnterKeyPress?.(e)}
|
||||||
if (isMutableRefObject<EditorRefApi>(ref)) {
|
|
||||||
rest.onEnterKeyPress?.(ref.current?.getHTML() ?? "");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
isCommentEmpty={isEmpty}
|
isCommentEmpty={isEmpty}
|
||||||
editorRef={isMutableRefObject<EditorRefApi>(ref) ? ref : null}
|
editorRef={isMutableRefObject<EditorRefApi>(ref) ? ref : null}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { cn } from "@/helpers/common.helper";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
executeCommand: (commandKey: TEditorCommands) => void;
|
executeCommand: (commandKey: TEditorCommands) => void;
|
||||||
handleSubmit: () => void;
|
handleSubmit: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||||
isCommentEmpty: boolean;
|
isCommentEmpty: boolean;
|
||||||
isSubmitting: boolean;
|
isSubmitting: boolean;
|
||||||
showSubmitButton: boolean;
|
showSubmitButton: boolean;
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ export const AddComment: React.FC<Props> = observer((props) => {
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { value, onChange } }) => (
|
render={({ field: { value, onChange } }) => (
|
||||||
<LiteTextEditor
|
<LiteTextEditor
|
||||||
onEnterKeyPress={() => {
|
onEnterKeyPress={(e) => {
|
||||||
if (currentUser) handleSubmit(onSubmit)();
|
if (currentUser) handleSubmit(onSubmit)(e);
|
||||||
}}
|
}}
|
||||||
workspaceId={workspaceID?.toString() ?? ""}
|
workspaceId={workspaceID?.toString() ?? ""}
|
||||||
workspaceSlug={workspaceSlug?.toString() ?? ""}
|
workspaceSlug={workspaceSlug?.toString() ?? ""}
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ export const CommentCard: React.FC<Props> = observer((props) => {
|
||||||
<LiteTextEditor
|
<LiteTextEditor
|
||||||
workspaceId={workspaceID?.toString() ?? ""}
|
workspaceId={workspaceID?.toString() ?? ""}
|
||||||
workspaceSlug={workspaceSlug?.toString() ?? ""}
|
workspaceSlug={workspaceSlug?.toString() ?? ""}
|
||||||
onEnterKeyPress={() => handleSubmit(handleCommentUpdate)()}
|
onEnterKeyPress={handleSubmit(handleCommentUpdate)}
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
id={comment.id}
|
id={comment.id}
|
||||||
initialValue={value}
|
initialValue={value}
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,7 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
handleAccessChange={handleAccessChange}
|
handleAccessChange={handleAccessChange}
|
||||||
handleSubmit={() => {
|
handleSubmit={(e) => rest.onEnterKeyPress?.(e)}
|
||||||
if (isMutableRefObject<EditorRefApi>(ref)) {
|
|
||||||
rest.onEnterKeyPress?.(ref.current?.getHTML() ?? "");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
isCommentEmpty={isEmpty}
|
isCommentEmpty={isEmpty}
|
||||||
isSubmitting={isSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
showAccessSpecifier={showAccessSpecifier}
|
showAccessSpecifier={showAccessSpecifier}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,11 @@ export const IssueCommentCard: FC<TIssueCommentCard> = observer((props) => {
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<form className={`flex-col gap-2 ${isEditing ? "flex" : "hidden"}`}>
|
<form className={`flex-col gap-2 ${isEditing ? "flex" : "hidden"}`}>
|
||||||
<div>
|
<div
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && !isEmpty) handleSubmit(onEnter)(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<LiteTextEditor
|
<LiteTextEditor
|
||||||
workspaceId={workspaceId}
|
workspaceId={workspaceId}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
|
|
@ -147,13 +151,9 @@ export const IssueCommentCard: FC<TIssueCommentCard> = observer((props) => {
|
||||||
initialValue={watch("comment_html") ?? ""}
|
initialValue={watch("comment_html") ?? ""}
|
||||||
value={null}
|
value={null}
|
||||||
onChange={(comment_json, comment_html) => setValue("comment_html", comment_html)}
|
onChange={(comment_json, comment_html) => setValue("comment_html", comment_html)}
|
||||||
onEnterKeyPress={(commentHTML) => {
|
onEnterKeyPress={(e) => {
|
||||||
const isCommentEmpty =
|
if (!isEmpty && !isSubmitting) {
|
||||||
commentHTML?.trim() === "" ||
|
handleSubmit(onEnter)(e);
|
||||||
commentHTML === "<p></p>" ||
|
|
||||||
(isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component"));
|
|
||||||
if (!isCommentEmpty && !isSubmitting) {
|
|
||||||
handleSubmit(onEnter)();
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
showSubmitButton={false}
|
showSubmitButton={false}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
|
watch,
|
||||||
formState: { isSubmitting },
|
formState: { isSubmitting },
|
||||||
reset,
|
reset,
|
||||||
} = useForm<Partial<TIssueComment>>({
|
} = useForm<Partial<TIssueComment>>({
|
||||||
|
|
@ -49,8 +50,19 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
|
||||||
editorRef.current?.clearEditor();
|
editorRef.current?.clearEditor();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const commentHTML = watch("comment_html");
|
||||||
|
const isEmpty =
|
||||||
|
commentHTML?.trim() === "" ||
|
||||||
|
commentHTML === "<p></p>" ||
|
||||||
|
(isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component"));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && !isEmpty && !isSubmitting)
|
||||||
|
handleSubmit(onSubmit)(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name="access"
|
name="access"
|
||||||
control={control}
|
control={control}
|
||||||
|
|
@ -65,13 +77,9 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {
|
||||||
value={"<p></p>"}
|
value={"<p></p>"}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
workspaceSlug={workspaceSlug}
|
workspaceSlug={workspaceSlug}
|
||||||
onEnterKeyPress={(commentHTML) => {
|
onEnterKeyPress={(e) => {
|
||||||
const isEmpty =
|
|
||||||
commentHTML?.trim() === "" ||
|
|
||||||
commentHTML === "<p></p>" ||
|
|
||||||
(isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component"));
|
|
||||||
if (!isEmpty && !isSubmitting) {
|
if (!isEmpty && !isSubmitting) {
|
||||||
handleSubmit(onSubmit)();
|
handleSubmit(onSubmit)(e);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue