plane/apps/app/components/issues/view-select/state.tsx

87 lines
2.2 KiB
TypeScript
Raw Normal View History

import { useRouter } from "next/router";
import useSWR from "swr";
// services
import stateService from "services/state.service";
// ui
2023-03-05 17:54:50 +00:00
import { CustomSearchSelect, Tooltip } from "components/ui";
// icons
import { getStateGroupIcon } from "components/icons";
// helpers
import { addSpaceIfCamelCase } from "helpers/string.helper";
import { getStatesList } from "helpers/state.helper";
// types
import { IIssue } from "types";
// fetch-keys
import { STATE_LIST } from "constants/fetch-keys";
type Props = {
issue: IIssue;
partialUpdateIssue: (formData: Partial<IIssue>) => void;
2023-03-05 14:52:01 +00:00
position?: "left" | "right";
selfPositioned?: boolean;
isNotAllowed: boolean;
};
export const ViewStateSelect: React.FC<Props> = ({
issue,
partialUpdateIssue,
2023-03-05 14:52:01 +00:00
position = "left",
selfPositioned = false,
isNotAllowed,
}) => {
const router = useRouter();
2023-02-13 14:08:58 +00:00
const { workspaceSlug } = router.query;
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
);
const states = getStatesList(stateGroups ?? {});
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
return (
2023-03-05 17:54:50 +00:00
<CustomSearchSelect
value={issue.state}
onChange={(data: string) =>
partialUpdateIssue({
state: data,
priority: issue.priority,
target_date: issue.target_date,
})
}
2023-03-05 17:54:50 +00:00
options={options}
label={
<Tooltip
tooltipHeading="State"
tooltipContent={addSpaceIfCamelCase(selectedOption?.name ?? "")}
>
<div className="flex items-center gap-2 text-gray-500">
{selectedOption &&
getStateGroupIcon(selectedOption.group, "16", "16", selectedOption.color)}
{selectedOption?.name ?? "State"}
</div>
</Tooltip>
}
2023-03-05 14:52:01 +00:00
position={position}
2023-03-05 17:54:50 +00:00
disabled={isNotAllowed}
noChevron
/>
);
};