mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
e9a0eb87cc
* dev: initialize inbox * dev: inbox and inbox issues models, views and serializers * dev: issue object filter for inbox * dev: filter for search issues * dev: inbox snooze and duplicates * dev: set duplicate to null by default * feat: inbox ui and services * feat: project detail in inbox * style: layout, popover, icons, sidebar * dev: default inbox for project and pending issues count * dev: fix exception when creating default inbox * fix: empty state for inbox * dev: auto issue state updation when rejected or marked duplicate * fix: inbox update status * fix: hydrating chose with old values filters workflow * feat: inbox issue filtering * fix: issue inbox filtering * feat: filter inbox issues * refactor: analytics, border colors * dev: filters and views for inbox * dev: source for inboxissue and update list inbox issue * dev: update list endpoint to house filters and additional data * dev: bridge id for list * dev: remove print logs * dev: update inbox issue workflow * dev: add description_html in issue details * fix: inbox track event auth, chore: inbox issue action authorization * fix: removed unnecessary api calls * style: viewed issues * fix: priority validation * dev: remove print logs * dev: update issue inbox update workflow * chore: added inbox view context * fix: type errors * fix: build errors and warnings * dev: update issue inbox workflow and log all the changes * fix: filters logic, sidebar fields to show * dev: update issue filtering status * chore: update create inbox issue modal, fix: mutation issues * dev: update issue accept workflow * chore: add comment to inbox issues * chore: remove inboxIssueId from url after deleting * dev: update the issue triage workflow * fix: mutation after issue status change * chore: issue details sidebar divider * fix: issue activity for inbox issues * dev: update inbox perrmissions * dev: create new permission layer * chore: auth layer for inbox * chore: show accepting status * chore: show issue status at the top of issue details --------- Co-authored-by: Dakshesh Jain <dakshesh.jain14@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
260 lines
8.0 KiB
TypeScript
260 lines
8.0 KiB
TypeScript
import { useCallback, useEffect } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
|
// react hook form
|
|
import { useForm } from "react-hook-form";
|
|
// contexts
|
|
import { useProjectMyMembership } from "contexts/project-member.context";
|
|
// services
|
|
import inboxServices from "services/inbox.service";
|
|
// hooks
|
|
import useInboxView from "hooks/use-inbox-view";
|
|
import useUserAuth from "hooks/use-user-auth";
|
|
// components
|
|
import {
|
|
AddComment,
|
|
IssueActivitySection,
|
|
IssueDescriptionForm,
|
|
IssueDetailsSidebar,
|
|
} from "components/issues";
|
|
// ui
|
|
import { Loader } from "components/ui";
|
|
// icons
|
|
import {
|
|
ArrowTopRightOnSquareIcon,
|
|
CheckCircleIcon,
|
|
ClockIcon,
|
|
DocumentDuplicateIcon,
|
|
ExclamationTriangleIcon,
|
|
XCircleIcon,
|
|
} from "@heroicons/react/24/outline";
|
|
// helpers
|
|
import { renderShortNumericDateFormat } from "helpers/date-time.helper";
|
|
// types
|
|
import type { IInboxIssue, IIssue } from "types";
|
|
// fetch-keys
|
|
import { INBOX_ISSUES, INBOX_ISSUE_DETAILS } from "constants/fetch-keys";
|
|
|
|
const defaultValues = {
|
|
name: "",
|
|
description: "",
|
|
description_html: "",
|
|
estimate_point: null,
|
|
assignees_list: [],
|
|
priority: "low",
|
|
target_date: new Date().toString(),
|
|
labels_list: [],
|
|
};
|
|
|
|
export const InboxMainContent: React.FC = () => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, inboxId, inboxIssueId } = router.query;
|
|
|
|
const { user } = useUserAuth();
|
|
const { memberRole } = useProjectMyMembership();
|
|
const { params } = useInboxView();
|
|
|
|
const { reset, control, watch } = useForm<IIssue>({
|
|
defaultValues,
|
|
});
|
|
|
|
const { data: issueDetails, mutate: mutateIssueDetails } = useSWR(
|
|
workspaceSlug && projectId && inboxId && inboxIssueId
|
|
? INBOX_ISSUE_DETAILS(inboxId.toString(), inboxIssueId.toString())
|
|
: null,
|
|
workspaceSlug && projectId && inboxId && inboxIssueId
|
|
? () =>
|
|
inboxServices.getInboxIssueById(
|
|
workspaceSlug.toString(),
|
|
projectId.toString(),
|
|
inboxId.toString(),
|
|
inboxIssueId.toString()
|
|
)
|
|
: null
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (!issueDetails || !inboxIssueId) return;
|
|
|
|
reset({
|
|
...issueDetails,
|
|
assignees_list:
|
|
issueDetails.assignees_list ?? (issueDetails.assignee_details ?? []).map((user) => user.id),
|
|
labels_list: issueDetails.labels_list ?? issueDetails.labels,
|
|
});
|
|
}, [issueDetails, reset, inboxIssueId]);
|
|
|
|
const submitChanges = useCallback(
|
|
async (formData: Partial<IInboxIssue>) => {
|
|
if (!workspaceSlug || !projectId || !inboxIssueId || !inboxId || !issueDetails) return;
|
|
|
|
mutateIssueDetails((prevData: any) => {
|
|
if (!prevData) return prevData;
|
|
|
|
return {
|
|
...prevData,
|
|
...formData,
|
|
};
|
|
}, false);
|
|
mutate<IInboxIssue[]>(
|
|
INBOX_ISSUES(inboxId.toString(), params),
|
|
(prevData) =>
|
|
(prevData ?? []).map((i) => {
|
|
if (i.bridge_id === inboxIssueId) {
|
|
return {
|
|
...i,
|
|
...formData,
|
|
};
|
|
}
|
|
|
|
return i;
|
|
}),
|
|
false
|
|
);
|
|
|
|
const payload = { issue: { ...formData } };
|
|
|
|
await inboxServices
|
|
.patchInboxIssue(
|
|
workspaceSlug.toString(),
|
|
projectId.toString(),
|
|
inboxId.toString(),
|
|
issueDetails.issue_inbox[0].id,
|
|
payload,
|
|
user
|
|
)
|
|
.then(() => {
|
|
mutateIssueDetails();
|
|
mutate(INBOX_ISSUES(inboxId.toString(), params));
|
|
});
|
|
},
|
|
[
|
|
workspaceSlug,
|
|
inboxIssueId,
|
|
projectId,
|
|
mutateIssueDetails,
|
|
inboxId,
|
|
user,
|
|
issueDetails,
|
|
params,
|
|
]
|
|
);
|
|
|
|
const issueStatus = issueDetails?.issue_inbox[0].status;
|
|
|
|
return (
|
|
<>
|
|
{issueDetails ? (
|
|
<div className="flex h-full overflow-auto divide-x">
|
|
<div className="basis-2/3 h-full overflow-auto p-5 space-y-3">
|
|
<div
|
|
className={`flex items-center gap-2 p-3 text-sm border rounded-md ${
|
|
issueStatus === -2
|
|
? "text-orange-500 border-orange-500 bg-orange-500/10"
|
|
: issueStatus === -1
|
|
? "text-red-500 border-red-500 bg-red-500/10"
|
|
: issueStatus === 0
|
|
? "text-blue-500 border-blue-500 bg-blue-500/10"
|
|
: issueStatus === 1
|
|
? "text-green-500 border-green-500 bg-green-500/10"
|
|
: issueStatus === 2
|
|
? "text-yellow-500 border-yellow-500 bg-yellow-500/10"
|
|
: ""
|
|
}`}
|
|
>
|
|
{issueStatus === -2 ? (
|
|
<>
|
|
<ExclamationTriangleIcon className="h-5 w-5" />
|
|
<p>This issue is still pending.</p>
|
|
</>
|
|
) : issueStatus === -1 ? (
|
|
<>
|
|
<XCircleIcon className="h-5 w-5" />
|
|
<p>This issue has been declined.</p>
|
|
</>
|
|
) : issueStatus === 0 ? (
|
|
<>
|
|
<ClockIcon className="h-5 w-5" />
|
|
<p>
|
|
This issue has been snoozed till{" "}
|
|
{renderShortNumericDateFormat(issueDetails.issue_inbox[0].snoozed_till ?? "")}.
|
|
</p>
|
|
</>
|
|
) : issueStatus === 1 ? (
|
|
<>
|
|
<CheckCircleIcon className="h-5 w-5" />
|
|
<p>This issue has been accepted.</p>
|
|
</>
|
|
) : issueStatus === 2 ? (
|
|
<>
|
|
<DocumentDuplicateIcon className="h-5 w-5" />
|
|
<p className="flex items-center gap-1">
|
|
This issue has been marked as a duplicate of
|
|
<a
|
|
href={`/${workspaceSlug}/projects/${projectId}/issues/${issueDetails.issue_inbox[0].duplicate_to}`}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="underline flex items-center gap-2"
|
|
>
|
|
this issue <ArrowTopRightOnSquareIcon className="h-3 w-3" />
|
|
</a>
|
|
.
|
|
</p>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
<div>
|
|
<IssueDescriptionForm
|
|
issue={{
|
|
name: issueDetails.name,
|
|
description: issueDetails.description,
|
|
description_html: issueDetails.description_html,
|
|
}}
|
|
handleFormSubmit={submitChanges}
|
|
isAllowed={
|
|
memberRole.isMember || memberRole.isOwner || user?.id === issueDetails.created_by
|
|
}
|
|
/>
|
|
</div>
|
|
<div className="space-y-5">
|
|
<h3 className="text-lg text-brand-base">Comments/Activity</h3>
|
|
<IssueActivitySection issueId={issueDetails.id} user={user} />
|
|
<AddComment issueId={issueDetails.id} user={user} />
|
|
</div>
|
|
</div>
|
|
|
|
<div className="basis-1/3 space-y-5 border-brand-base p-5">
|
|
<IssueDetailsSidebar
|
|
control={control}
|
|
issueDetail={issueDetails}
|
|
submitChanges={submitChanges}
|
|
watch={watch}
|
|
fieldsToShow={["assignee", "priority", "estimate", "dueDate", "label", "state"]}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<Loader className="flex h-full gap-5 p-5">
|
|
<div className="basis-2/3 space-y-2">
|
|
<Loader.Item height="30px" width="40%" />
|
|
<Loader.Item height="15px" width="60%" />
|
|
<Loader.Item height="15px" width="60%" />
|
|
<Loader.Item height="15px" width="40%" />
|
|
</div>
|
|
<div className="basis-1/3 space-y-3">
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
</div>
|
|
</Loader>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return null;
|
|
};
|