forked from github/plane
44f8ba407d
* auth integration fixes * auth integration fixes * auth integration fixes * auth integration fixes * dev: update user api to return fallback workspace and improve the structure of the response * dev: fix the issue keyerror and move onboarding logic to serializer method field * dev: use-user-auth hook imlemented for route access validation and build issues resolved effected by user payload * fix: global theme color fix * style: new onboarding ui , fix: use-user-auth hook implemented * fix: command palette, project invite modal and issue detail page mutation type fix * fix: onboarding redirection fix * dev: build isuue resolved * fix: use user auth hook fix * fix: sign in toast alert fix, sign out redirection fix and user theme error fix * fix: user response fix * fix: unAuthorizedStatus logic updated --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: gurusainath <gurusainath007@gmail.com> Co-authored-by: anmolsinghbhatia <anmolsinghbhatia@caravel.tech>
112 lines
3.1 KiB
TypeScript
112 lines
3.1 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import React, { Dispatch, SetStateAction, useCallback } from "react";
|
|
import useSWR, { 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, PROJECT_MEMBERS } from "constants/fetch-keys";
|
|
// icons
|
|
import { CheckIcon } from "components/icons";
|
|
import projectService from "services/project.service";
|
|
import { Avatar } from "components/ui";
|
|
|
|
type Props = {
|
|
setIsPaletteOpen: Dispatch<SetStateAction<boolean>>;
|
|
issue: IIssue;
|
|
};
|
|
|
|
export const ChangeIssueAssignee: React.FC<Props> = ({ setIsPaletteOpen, issue }) => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
|
|
const { data: members } = useSWR(
|
|
projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
workspaceSlug && projectId
|
|
? () => projectService.projectMembers(workspaceSlug as string, projectId as string)
|
|
: null
|
|
);
|
|
|
|
const options =
|
|
members?.map(({ member }) => ({
|
|
value: member.id,
|
|
query:
|
|
(member.first_name && member.first_name !== "" ? member.first_name : member.email) +
|
|
" " +
|
|
member.last_name ?? "",
|
|
content: (
|
|
<>
|
|
<div className="flex items-center gap-2">
|
|
<Avatar user={member} />
|
|
{member.first_name && member.first_name !== "" ? member.first_name : member.email}
|
|
</div>
|
|
{issue.assignees.includes(member.id) && (
|
|
<div>
|
|
<CheckIcon className="h-3 w-3" />
|
|
</div>
|
|
)}
|
|
</>
|
|
),
|
|
})) ?? [];
|
|
|
|
const updateIssue = useCallback(
|
|
async (formData: Partial<IIssue>) => {
|
|
if (!workspaceSlug || !projectId || !issueId) return;
|
|
|
|
mutate<IIssue>(
|
|
ISSUE_DETAILS(issueId as string),
|
|
async (prevData) => {
|
|
if (!prevData) return prevData;
|
|
return {
|
|
...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 handleIssueAssignees = (assignee: string) => {
|
|
const updatedAssignees = issue.assignees_list ?? [];
|
|
|
|
if (updatedAssignees.includes(assignee)) {
|
|
updatedAssignees.splice(updatedAssignees.indexOf(assignee), 1);
|
|
} else {
|
|
updatedAssignees.push(assignee);
|
|
}
|
|
|
|
updateIssue({ assignees_list: updatedAssignees });
|
|
setIsPaletteOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{options.map((option) => (
|
|
<Command.Item
|
|
key={option.value}
|
|
onSelect={() => handleIssueAssignees(option.value)}
|
|
className="focus:outline-none"
|
|
>
|
|
{option.content}
|
|
</Command.Item>
|
|
))}
|
|
</>
|
|
);
|
|
};
|