forked from github/plane
892a30c3a8
* fix: web-view * feat: select module * dev: select cycle & module * fix: permissions, logs and archive issue * fix: logs for issue select fix: hard-coded web-view validation * fix: attachment confirm delete workflow * fix: typo * fix: logging link instead of redirecting to the link * fix: made editor height 100% * style: due-date select * fix: update comment not working * fix: changed button text style: spacing * fix: due date select not working for today's date * fix: typography * fix: spacing in select parent
117 lines
2.8 KiB
TypeScript
117 lines
2.8 KiB
TypeScript
// react
|
|
import React, { useState } from "react";
|
|
|
|
// next
|
|
import { useRouter } from "next/router";
|
|
|
|
// swr
|
|
import { mutate } from "swr";
|
|
|
|
// services
|
|
import issuesService from "services/issues.service";
|
|
|
|
// hooks
|
|
import useUser from "hooks/use-user";
|
|
|
|
// fetch keys
|
|
import { ISSUE_DETAILS, PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys";
|
|
|
|
// icons
|
|
import { ChevronDown } from "lucide-react";
|
|
|
|
// components
|
|
import { IssuesSelectBottomSheet } from "components/web-view";
|
|
|
|
// types
|
|
import { BlockeIssueDetail, ISearchIssueResponse } from "types";
|
|
|
|
type Props = {
|
|
disabled?: boolean;
|
|
};
|
|
|
|
export const DuplicateSelect: React.FC<Props> = (props) => {
|
|
const { disabled = false } = props;
|
|
|
|
const [isBottomSheetOpen, setIsBottomSheetOpen] = useState(false);
|
|
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
|
|
const { user } = useUser();
|
|
|
|
const onSubmit = async (data: ISearchIssueResponse[]) => {
|
|
if (!workspaceSlug || !projectId || !issueId || !user || disabled) return;
|
|
|
|
if (data.length === 0)
|
|
return console.log(
|
|
"toast",
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Please select at least one issue.",
|
|
})
|
|
);
|
|
|
|
const selectedIssues: { blocker_issue_detail: BlockeIssueDetail }[] = data.map((i) => ({
|
|
blocker_issue_detail: {
|
|
id: i.id,
|
|
name: i.name,
|
|
sequence_id: i.sequence_id,
|
|
project_detail: {
|
|
id: i.project_id,
|
|
identifier: i.project__identifier,
|
|
name: i.project__name,
|
|
},
|
|
},
|
|
}));
|
|
|
|
if (!user) return;
|
|
|
|
issuesService
|
|
.createIssueRelation(
|
|
workspaceSlug.toString(),
|
|
projectId.toString(),
|
|
issueId.toString(),
|
|
user,
|
|
{
|
|
related_list: [
|
|
...selectedIssues.map((issue) => ({
|
|
issue: issueId as string,
|
|
issue_detail: issue.blocker_issue_detail,
|
|
related_issue: issue.blocker_issue_detail.id,
|
|
relation_type: "duplicate" as const,
|
|
})),
|
|
],
|
|
}
|
|
)
|
|
.then(() => {
|
|
mutate(ISSUE_DETAILS(issueId as string));
|
|
mutate(PROJECT_ISSUES_ACTIVITY(issueId as string));
|
|
});
|
|
|
|
setIsBottomSheetOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<IssuesSelectBottomSheet
|
|
isOpen={isBottomSheetOpen}
|
|
onClose={() => setIsBottomSheetOpen(false)}
|
|
onSubmit={onSubmit}
|
|
searchParams={{ issue_relation: true }}
|
|
/>
|
|
|
|
<button
|
|
type="button"
|
|
disabled={disabled}
|
|
onClick={() => setIsBottomSheetOpen(true)}
|
|
className={
|
|
"relative w-full px-2.5 py-0.5 text-base flex justify-between items-center gap-0.5"
|
|
}
|
|
>
|
|
<span className="text-custom-text-200">Select issue</span>
|
|
<ChevronDown className="w-4 h-4 text-custom-text-200" />
|
|
</button>
|
|
</>
|
|
);
|
|
};
|