2023-02-08 04:43:07 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import stateService from "services/state.service";
|
2023-04-06 06:38:52 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-02-08 04:43:07 +00:00
|
|
|
// ui
|
2023-03-05 17:54:50 +00:00
|
|
|
import { CustomSearchSelect, Tooltip } from "components/ui";
|
|
|
|
// icons
|
|
|
|
import { getStateGroupIcon } from "components/icons";
|
2023-02-08 04:43:07 +00:00
|
|
|
// helpers
|
|
|
|
import { addSpaceIfCamelCase } from "helpers/string.helper";
|
2023-02-08 13:21:03 +00:00
|
|
|
import { getStatesList } from "helpers/state.helper";
|
2023-02-08 04:43:07 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-02-08 04:43:07 +00:00
|
|
|
// fetch-keys
|
2023-04-22 12:49:35 +00:00
|
|
|
import { STATES_LIST } from "constants/fetch-keys";
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-06-24 12:39:06 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issue: IIssue) => void;
|
2023-03-05 14:52:01 +00:00
|
|
|
position?: "left" | "right";
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition?: "top" | "bottom";
|
2023-07-07 08:41:33 +00:00
|
|
|
className?: string;
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned?: boolean;
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton?: boolean;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-02-08 04:43:07 +00:00
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ViewStateSelect: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
2023-03-05 14:52:01 +00:00
|
|
|
position = "left",
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition = "top",
|
2023-07-07 08:41:33 +00:00
|
|
|
className = "",
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned = false,
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton = false,
|
2023-06-06 16:06:00 +00:00
|
|
|
user,
|
2023-02-08 04:43:07 +00:00
|
|
|
isNotAllowed,
|
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
2023-02-13 14:08:58 +00:00
|
|
|
const { workspaceSlug } = router.query;
|
2023-02-08 04:43:07 +00:00
|
|
|
|
2023-02-08 13:21:03 +00:00
|
|
|
const { data: stateGroups } = useSWR(
|
2023-04-22 12:49:35 +00:00
|
|
|
workspaceSlug && issue ? STATES_LIST(issue.project) : null,
|
2023-02-13 14:08:58 +00:00
|
|
|
workspaceSlug && issue
|
|
|
|
? () => stateService.getStates(workspaceSlug as string, issue.project)
|
|
|
|
: null
|
2023-02-08 04:43:07 +00:00
|
|
|
);
|
2023-02-08 13:21:03 +00:00
|
|
|
const states = getStatesList(stateGroups ?? {});
|
2023-02-08 04:43:07 +00:00
|
|
|
|
2023-03-05 17:54:50 +00:00
|
|
|
const options = states?.map((state) => ({
|
|
|
|
value: state.id,
|
|
|
|
query: state.name,
|
|
|
|
content: (
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
{getStateGroupIcon(state.group, "16", "16", state.color)}
|
|
|
|
{state.name}
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const selectedOption = states?.find((s) => s.id === issue.state);
|
2023-03-05 14:52:01 +00:00
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
const stateLabel = (
|
|
|
|
<Tooltip
|
|
|
|
tooltipHeading="State"
|
|
|
|
tooltipContent={addSpaceIfCamelCase(selectedOption?.name ?? "")}
|
2023-06-28 11:57:43 +00:00
|
|
|
position={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
>
|
2023-07-07 08:41:33 +00:00
|
|
|
<div className="flex items-center cursor-pointer w-full gap-2 text-brand-secondary">
|
|
|
|
<span className="h-4 w-4">
|
|
|
|
{selectedOption &&
|
|
|
|
getStateGroupIcon(selectedOption.group, "16", "16", selectedOption.color)}
|
|
|
|
</span>
|
|
|
|
<span className="truncate">{selectedOption?.name ?? "State"}</span>
|
2023-06-23 11:50:05 +00:00
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
return (
|
2023-03-05 17:54:50 +00:00
|
|
|
<CustomSearchSelect
|
2023-07-07 08:41:33 +00:00
|
|
|
className={className}
|
2023-02-08 04:43:07 +00:00
|
|
|
value={issue.state}
|
2023-04-06 06:38:52 +00:00
|
|
|
onChange={(data: string) => {
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue(
|
|
|
|
{
|
|
|
|
state: data,
|
|
|
|
priority: issue.priority,
|
|
|
|
target_date: issue.target_date,
|
|
|
|
},
|
2023-06-24 12:39:06 +00:00
|
|
|
issue
|
2023-05-10 20:57:14 +00:00
|
|
|
);
|
2023-04-06 06:38:52 +00:00
|
|
|
trackEventServices.trackIssuePartialPropertyUpdateEvent(
|
|
|
|
{
|
2023-04-14 14:10:00 +00:00
|
|
|
workspaceSlug,
|
|
|
|
workspaceId: issue.workspace,
|
2023-04-06 06:38:52 +00:00
|
|
|
projectId: issue.project_detail.id,
|
|
|
|
projectIdentifier: issue.project_detail.identifier,
|
|
|
|
projectName: issue.project_detail.name,
|
|
|
|
issueId: issue.id,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
"ISSUE_PROPERTY_UPDATE_STATE",
|
|
|
|
user
|
2023-04-06 06:38:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const oldState = states.find((s) => s.id === issue.state);
|
|
|
|
const newState = states.find((s) => s.id === data);
|
|
|
|
|
|
|
|
if (oldState?.group !== "completed" && newState?.group !== "completed") {
|
2023-06-06 16:06:00 +00:00
|
|
|
trackEventServices.trackIssueMarkedAsDoneEvent(
|
|
|
|
{
|
|
|
|
workspaceSlug: issue.workspace_detail.slug,
|
|
|
|
workspaceId: issue.workspace_detail.id,
|
|
|
|
projectId: issue.project_detail.id,
|
|
|
|
projectIdentifier: issue.project_detail.identifier,
|
|
|
|
projectName: issue.project_detail.name,
|
|
|
|
issueId: issue.id,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-04-06 06:38:52 +00:00
|
|
|
}
|
|
|
|
}}
|
2023-03-05 17:54:50 +00:00
|
|
|
options={options}
|
2023-06-23 11:50:05 +00:00
|
|
|
{...(customButton ? { customButton: stateLabel } : { label: stateLabel })}
|
2023-03-05 14:52:01 +00:00
|
|
|
position={position}
|
2023-03-05 17:54:50 +00:00
|
|
|
disabled={isNotAllowed}
|
|
|
|
noChevron
|
|
|
|
/>
|
2023-02-08 04:43:07 +00:00
|
|
|
);
|
|
|
|
};
|