mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
6595a387d0
* fix: event tracker changes * fix: App provider implementation using wrappers * fix: updating packages * fix: handling warning * fix: wrapper fixes and minor optimization changes * fix: chore app-provider clearnup * fix: cleanup * fix: removing jitsu tracking * fix: minor updates * fix: adding event to posthog event tracker (#2802) * dev: posthog event tracker update intitiate * fix: adding events for posthog integration * fix: event payload --------- Co-authored-by: Ramesh Kumar Chandra <31303617+rameshkumarchandra@users.noreply.github.com>
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
import React, { Dispatch, SetStateAction, useCallback } from "react";
|
|
import { useRouter } from "next/router";
|
|
import useSWR, { mutate } from "swr";
|
|
// cmdk
|
|
import { Command } from "cmdk";
|
|
// services
|
|
import { IssueService } from "services/issue";
|
|
import { ProjectStateService } from "services/project";
|
|
// ui
|
|
import { Spinner, StateGroupIcon } from "@plane/ui";
|
|
// icons
|
|
import { Check } from "lucide-react";
|
|
// types
|
|
import { IUser, IIssue } from "types";
|
|
// fetch keys
|
|
import { ISSUE_DETAILS, PROJECT_ISSUES_ACTIVITY, STATES_LIST } from "constants/fetch-keys";
|
|
|
|
type Props = {
|
|
setIsPaletteOpen: Dispatch<SetStateAction<boolean>>;
|
|
issue: IIssue;
|
|
user: IUser | undefined;
|
|
};
|
|
|
|
// services
|
|
const issueService = new IssueService();
|
|
const stateService = new ProjectStateService();
|
|
|
|
export const ChangeIssueState: React.FC<Props> = ({ setIsPaletteOpen, issue }) => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
|
|
const { data: states, mutate: mutateStates } = useSWR(
|
|
workspaceSlug && projectId ? STATES_LIST(projectId as string) : null,
|
|
workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null
|
|
);
|
|
|
|
const submitChanges = 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 issueService
|
|
.patchIssue(workspaceSlug as string, projectId as string, issueId as string, payload)
|
|
.then(() => {
|
|
mutateStates();
|
|
mutate(PROJECT_ISSUES_ACTIVITY(issueId as string));
|
|
})
|
|
.catch((e) => {
|
|
console.error(e);
|
|
});
|
|
},
|
|
[workspaceSlug, issueId, projectId, mutateStates]
|
|
);
|
|
|
|
const handleIssueState = (stateId: string) => {
|
|
submitChanges({ state: stateId });
|
|
setIsPaletteOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{states ? (
|
|
states.length > 0 ? (
|
|
states.map((state) => (
|
|
<Command.Item key={state.id} onSelect={() => handleIssueState(state.id)} className="focus:outline-none">
|
|
<div className="flex items-center space-x-3">
|
|
<StateGroupIcon stateGroup={state.group} color={state.color} height="16px" width="16px" />
|
|
<p>{state.name}</p>
|
|
</div>
|
|
<div>{state.id === issue.state && <Check className="h-3 w-3" />}</div>
|
|
</Command.Item>
|
|
))
|
|
) : (
|
|
<div className="text-center">No states found</div>
|
|
)
|
|
) : (
|
|
<Spinner />
|
|
)}
|
|
</>
|
|
);
|
|
};
|