2023-02-08 04:43:07 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import stateService from "services/state.service";
|
|
|
|
// ui
|
2023-02-22 06:12:17 +00:00
|
|
|
import { CustomSelect, Tooltip } from "components/ui";
|
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-02-08 13:21:03 +00:00
|
|
|
import { IIssue } from "types";
|
2023-02-08 04:43:07 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { STATE_LIST } from "constants/fetch-keys";
|
2023-03-05 14:52:01 +00:00
|
|
|
import { getStateGroupIcon } from "components/icons";
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>) => void;
|
2023-03-05 14:52:01 +00:00
|
|
|
position?: "left" | "right";
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned?: boolean;
|
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-02-23 17:04:36 +00:00
|
|
|
selfPositioned = false,
|
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-02-13 14:08:58 +00:00
|
|
|
workspaceSlug && issue ? STATE_LIST(issue.project) : null,
|
|
|
|
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 14:52:01 +00:00
|
|
|
const currentState = states?.find((s) => s.id === issue.state);
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
return (
|
|
|
|
<CustomSelect
|
|
|
|
label={
|
|
|
|
<>
|
2023-03-05 14:52:01 +00:00
|
|
|
{getStateGroupIcon(
|
|
|
|
currentState?.group ?? "backlog",
|
|
|
|
"16",
|
|
|
|
"16",
|
|
|
|
currentState?.color ?? ""
|
|
|
|
)}
|
2023-02-22 06:12:17 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipHeading="State"
|
2023-03-05 14:52:01 +00:00
|
|
|
tooltipContent={addSpaceIfCamelCase(currentState?.name ?? "")}
|
2023-02-22 06:12:17 +00:00
|
|
|
>
|
2023-03-05 14:52:01 +00:00
|
|
|
<span>{addSpaceIfCamelCase(currentState?.name ?? "")}</span>
|
2023-02-22 06:12:17 +00:00
|
|
|
</Tooltip>
|
2023-02-08 04:43:07 +00:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
value={issue.state}
|
2023-03-05 14:52:01 +00:00
|
|
|
onChange={(data: string) => partialUpdateIssue({ state: data })}
|
2023-02-08 04:43:07 +00:00
|
|
|
maxHeight="md"
|
|
|
|
noChevron
|
|
|
|
disabled={isNotAllowed}
|
2023-03-05 14:52:01 +00:00
|
|
|
position={position}
|
2023-02-23 17:04:36 +00:00
|
|
|
selfPositioned={selfPositioned}
|
2023-02-08 04:43:07 +00:00
|
|
|
>
|
|
|
|
{states?.map((state) => (
|
|
|
|
<CustomSelect.Option key={state.id} value={state.id}>
|
|
|
|
<>
|
2023-03-05 14:52:01 +00:00
|
|
|
{getStateGroupIcon(state.group, "16", "16", state.color)}
|
2023-02-08 04:43:07 +00:00
|
|
|
{addSpaceIfCamelCase(state.name)}
|
|
|
|
</>
|
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
|
|
|
);
|
|
|
|
};
|