forked from github/plane
afb92ea850
* feat: cmdk integration * feat: create view, cycle, project, module and workspace from command k * feat: user can logout directly from command menu * feat: user can visit sub page like various settings * feat: change state of issue from command menu * chore: add current issue state and minor UX improvements * refactor: moved change issue state to new file * feat: change issue priority from command k * feat: delete issue from command k * feat: copy issue url to clipboard * fix: change placeholder when settings page is selected * chore: remove logout option from cmd k * feat: add help options to cmd k * feat: assign issue to member from cmd k * feat: now assign issue to yourself from cmd k * chore: implement new cmd k design with icons * feat: implemented global search feature in the cmd k * feat: add keyboard acessibility to cmd k list items * chore: remove console logs * fix: pages icon in cmd list --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import React, { Dispatch, SetStateAction, useCallback } from "react";
|
|
import { mutate } from "swr";
|
|
|
|
// cmdk
|
|
import { Command } from "cmdk";
|
|
// services
|
|
import issuesService from "services/issues.service";
|
|
// types
|
|
import { IIssue } from "types";
|
|
// constants
|
|
import { ISSUE_DETAILS, PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys";
|
|
import { PRIORITIES } from "constants/project";
|
|
// icons
|
|
import { CheckIcon, getPriorityIcon } from "components/icons";
|
|
|
|
type Props = {
|
|
setIsPaletteOpen: Dispatch<SetStateAction<boolean>>;
|
|
issue: IIssue;
|
|
};
|
|
|
|
export const ChangeIssuePriority: React.FC<Props> = ({ setIsPaletteOpen, issue }) => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
|
|
const submitChanges = useCallback(
|
|
async (formData: Partial<IIssue>) => {
|
|
if (!workspaceSlug || !projectId || !issueId) return;
|
|
|
|
mutate(
|
|
ISSUE_DETAILS(issueId as string),
|
|
(prevData: IIssue) => ({
|
|
...prevData,
|
|
...formData,
|
|
}),
|
|
false
|
|
);
|
|
|
|
const payload = { ...formData };
|
|
await issuesService
|
|
.patchIssue(workspaceSlug as string, projectId as string, issueId as string, payload)
|
|
.then(() => {
|
|
mutate(PROJECT_ISSUES_ACTIVITY(issueId as string));
|
|
})
|
|
.catch((e) => {
|
|
console.error(e);
|
|
});
|
|
},
|
|
[workspaceSlug, issueId, projectId]
|
|
);
|
|
|
|
const handleIssueState = (priority: string | null) => {
|
|
submitChanges({ priority });
|
|
setIsPaletteOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{PRIORITIES.map((priority) => (
|
|
<Command.Item
|
|
key={priority}
|
|
onSelect={() => handleIssueState(priority)}
|
|
className="focus:bg-slate-200 focus:outline-none"
|
|
tabIndex={0}
|
|
>
|
|
<div className="flex items-center space-x-3">
|
|
{getPriorityIcon(priority)}
|
|
<span className="capitalize">{priority ?? "None"}</span>
|
|
</div>
|
|
<div>{priority === issue.priority && <CheckIcon className="h-3 w-3" />}</div>
|
|
</Command.Item>
|
|
))}
|
|
</>
|
|
);
|
|
};
|