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
|
|
|
|
import { CustomSelect } from "components/ui";
|
|
|
|
// 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";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>) => void;
|
|
|
|
position?: "left" | "right";
|
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ViewStateSelect: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
|
|
|
position,
|
|
|
|
isNotAllowed,
|
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-02-08 13:21:03 +00:00
|
|
|
const { data: stateGroups } = useSWR(
|
|
|
|
workspaceSlug && projectId ? STATE_LIST(issue.project) : null,
|
|
|
|
workspaceSlug ? () => 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
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomSelect
|
|
|
|
label={
|
|
|
|
<>
|
|
|
|
<span
|
|
|
|
className="h-1.5 w-1.5 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: states?.find((s) => s.id === issue.state)?.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{addSpaceIfCamelCase(states?.find((s) => s.id === issue.state)?.name ?? "")}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
value={issue.state}
|
|
|
|
onChange={(data: string) => {
|
|
|
|
partialUpdateIssue({ state: data });
|
|
|
|
}}
|
|
|
|
maxHeight="md"
|
|
|
|
noChevron
|
|
|
|
disabled={isNotAllowed}
|
|
|
|
>
|
|
|
|
{states?.map((state) => (
|
|
|
|
<CustomSelect.Option key={state.id} value={state.id}>
|
|
|
|
<>
|
|
|
|
<span
|
|
|
|
className="h-1.5 w-1.5 flex-shrink-0 rounded-full"
|
|
|
|
style={{
|
|
|
|
backgroundColor: state.color,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{addSpaceIfCamelCase(state.name)}
|
|
|
|
</>
|
|
|
|
</CustomSelect.Option>
|
|
|
|
))}
|
|
|
|
</CustomSelect>
|
|
|
|
);
|
|
|
|
};
|