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

fix: comment box placeholder #909

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 17 additions & 30 deletions apps/app/components/issues/comment/add-comment.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from "react";
import React from "react";

import { useRouter } from "next/router";
import dynamic from "next/dynamic";
Expand All @@ -9,10 +9,10 @@ import { mutate } from "swr";
import { useForm, Controller } from "react-hook-form";
// services
import issuesServices from "services/issues.service";
// hooks
import useToast from "hooks/use-toast";
// ui
import { Loader, SecondaryButton } from "components/ui";
// helpers
import { debounce } from "helpers/common.helper";
// types
import type { IIssueComment } from "types";
// fetch-keys
Expand All @@ -28,8 +28,8 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor
});

const defaultValues: Partial<IIssueComment> = {
comment_html: "",
comment_json: "",
comment_html: "",
};

export const AddComment: React.FC = () => {
Expand All @@ -42,9 +42,10 @@ export const AddComment: React.FC = () => {
} = useForm<IIssueComment>({ defaultValues });

const router = useRouter();

const { workspaceSlug, projectId, issueId } = router.query;

const { setToastAlert } = useToast();

const onSubmit = async (formData: IIssueComment) => {
if (
!workspaceSlug ||
Expand All @@ -61,41 +62,27 @@ export const AddComment: React.FC = () => {
mutate(PROJECT_ISSUES_ACTIVITY(issueId as string));
reset(defaultValues);
})
.catch((error) => {
console.error(error);
});
.catch(() =>
setToastAlert({
type: "error",
title: "Error!",
message: "Comment could not be posted. Please try again.",
})
);
};

const updateDescription = useMemo(
() =>
debounce((key: any, val: any) => {
setValue(key, val);
}, 1000),
[setValue]
);

const updateDescriptionHTML = useMemo(
() =>
debounce((key: any, val: any) => {
setValue(key, val);
}, 1000),
[setValue]
);

return (
<div>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="issue-comments-section" >
<div className="issue-comments-section">
<Controller
name="comment_html"
name="comment_json"
control={control}
render={({ field: { value } }) => (
<RemirrorRichTextEditor
value={value}
onBlur={(jsonValue, htmlValue) => {
setValue("comment_json", jsonValue);
setValue("comment_html", htmlValue);
}}
onJSONChange={(jsonValue) => setValue("comment_json", jsonValue)}
onHTMLChange={(htmlValue) => setValue("comment_html", htmlValue)}
placeholder="Enter your comment..."
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/rich-text-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const RemirrorRichTextEditor: FC<IRemirrorRichTextEditor> = (props) => {
{(!value || value === "" || value?.content?.[0]?.content === undefined) &&
!(typeof value === "string" && value.includes("<")) &&
placeholder && (
<p className="absolute pointer-events-none top-4 left-4 text-brand-secondary">
<p className="pointer-events-none absolute top-4 left-4 text-brand-secondary">
{placeholder}
</p>
)}
Expand Down