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

refactor: issue details page #282

Merged
merged 1 commit into from
Feb 15, 2023
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
43 changes: 26 additions & 17 deletions apps/app/components/issues/activity.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { useRouter } from "next/router";
import Image from "next/image";
import { KeyedMutator } from "swr";
import useSWR from "swr";

// icons
import {
Expand All @@ -13,7 +13,7 @@ import {
UserIcon,
} from "@heroicons/react/24/outline";
// services
import issuesServices from "services/issues.service";
import issuesService from "services/issues.service";
// components
import { CommentCard } from "components/issues/comment";
// ui
Expand All @@ -24,7 +24,8 @@ import { BlockedIcon, BlockerIcon, CyclesIcon, TagIcon, UserGroupIcon } from "co
import { renderShortNumericDateFormat, timeAgo } from "helpers/date-time.helper";
import { addSpaceIfCamelCase } from "helpers/string.helper";
// types
import { IIssueActivity, IIssueComment } from "types";
import { IIssueComment } from "types";
import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys";

const activityDetails: {
[key: string]: {
Expand Down Expand Up @@ -85,19 +86,27 @@ const activityDetails: {
},
};

type Props = {
issueActivities: IIssueActivity[];
mutate: KeyedMutator<IIssueActivity[]>;
};
type Props = {};

export const IssueActivitySection: React.FC<Props> = ({ issueActivities, mutate }) => {
export const IssueActivitySection: React.FC<Props> = () => {
const router = useRouter();

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

const onCommentUpdate = async (comment: IIssueComment) => {
const { data: issueActivities, mutate: mutateIssueActivities } = useSWR(
workspaceSlug && projectId && issueId ? PROJECT_ISSUES_ACTIVITY(issueId as string) : null,
workspaceSlug && projectId && issueId
? () =>
issuesService.getIssueActivities(
workspaceSlug as string,
projectId as string,
issueId as string
)
: null
);

const handleCommentUpdate = async (comment: IIssueComment) => {
if (!workspaceSlug || !projectId || !issueId) return;
await issuesServices
await issuesService
.patchIssueComment(
workspaceSlug as string,
projectId as string,
Expand All @@ -106,21 +115,21 @@ export const IssueActivitySection: React.FC<Props> = ({ issueActivities, mutate
comment
)
.then((res) => {
mutate();
mutateIssueActivities();
});
};

const onCommentDelete = async (commentId: string) => {
const handleCommentDelete = async (commentId: string) => {
if (!workspaceSlug || !projectId || !issueId) return;
await issuesServices
await issuesService
.deleteIssueComment(
workspaceSlug as string,
projectId as string,
issueId as string,
commentId
)
.then((response) => {
mutate();
mutateIssueActivities();
console.log(response);
});
};
Expand Down Expand Up @@ -234,8 +243,8 @@ export const IssueActivitySection: React.FC<Props> = ({ issueActivities, mutate
<CommentCard
key={activity.id}
comment={activity as any}
onSubmit={onCommentUpdate}
handleCommentDeletion={onCommentDelete}
onSubmit={handleCommentUpdate}
handleCommentDeletion={handleCommentDelete}
/>
);
})}
Expand Down
13 changes: 7 additions & 6 deletions apps/app/components/issues/comment/add-comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { useMemo } from "react";
import { useRouter } from "next/router";
import dynamic from "next/dynamic";

import { mutate } from "swr";

// react-hook-form
import { useForm, Controller } from "react-hook-form";
// services
Expand All @@ -12,8 +14,9 @@ import { Loader } from "components/ui";
// helpers
import { debounce } from "helpers/common.helper";
// types
import type { IIssueActivity, IIssueComment } from "types";
import type { KeyedMutator } from "swr";
import type { IIssueComment } from "types";
// fetch-keys
import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys";

const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), {
ssr: false,
Expand All @@ -29,9 +32,7 @@ const defaultValues: Partial<IIssueComment> = {
comment_json: "",
};

export const AddComment: React.FC<{
mutate: KeyedMutator<IIssueActivity[]>;
}> = ({ mutate }) => {
export const AddComment: React.FC = () => {
const {
handleSubmit,
control,
Expand All @@ -57,7 +58,7 @@ export const AddComment: React.FC<{
await issuesServices
.createIssueComment(workspaceSlug as string, projectId as string, issueId as string, formData)
.then(() => {
mutate();
mutate(PROJECT_ISSUES_ACTIVITY(issueId as string));
reset(defaultValues);
})
.catch((error) => {
Expand Down
Loading