2023-10-18 09:25:26 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-03-07 19:37:00 +00:00
|
|
|
// ui
|
2023-10-19 09:54:51 +00:00
|
|
|
import { CustomSelect } from "@plane/ui";
|
2023-10-18 09:25:26 +00:00
|
|
|
// helpers
|
|
|
|
import { renderEmoji } from "helpers/emoji.helper";
|
2023-01-26 18:12:20 +00:00
|
|
|
// icons
|
2023-10-16 14:57:22 +00:00
|
|
|
import { Clipboard } from "lucide-react";
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
export interface IssueProjectSelectProps {
|
|
|
|
value: string;
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
}
|
|
|
|
|
2023-10-18 09:25:26 +00:00
|
|
|
export const IssueProjectSelect: React.FC<IssueProjectSelectProps> = observer((props) => {
|
|
|
|
const { value, onChange } = props;
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
|
|
|
const { project: projectStore } = useMobxStore();
|
|
|
|
|
|
|
|
const projects = workspaceSlug ? projectStore.projects[workspaceSlug.toString()] : undefined;
|
|
|
|
|
|
|
|
const selectedProject = projects?.find((i) => i.id === value);
|
2023-01-26 18:12:20 +00:00
|
|
|
|
|
|
|
return (
|
2023-03-07 19:37:00 +00:00
|
|
|
<CustomSelect
|
|
|
|
value={value}
|
|
|
|
label={
|
2023-10-18 09:25:26 +00:00
|
|
|
selectedProject ? (
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
<span className="grid place-items-center">
|
|
|
|
{selectedProject.emoji
|
|
|
|
? renderEmoji(selectedProject.emoji)
|
|
|
|
: selectedProject.icon_prop
|
|
|
|
? renderEmoji(selectedProject.icon_prop)
|
|
|
|
: null}
|
|
|
|
</span>
|
|
|
|
<div className="truncate">{selectedProject.identifier}</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Clipboard className="h-3 w-3" />
|
|
|
|
<div>Select Project</div>
|
|
|
|
</>
|
|
|
|
)
|
2023-03-07 19:37:00 +00:00
|
|
|
}
|
2023-07-23 16:42:13 +00:00
|
|
|
onChange={(val: string) => onChange(val)}
|
2023-03-07 19:37:00 +00:00
|
|
|
noChevron
|
|
|
|
>
|
|
|
|
{projects ? (
|
|
|
|
projects.length > 0 ? (
|
|
|
|
projects.map((project) => (
|
|
|
|
<CustomSelect.Option key={project.id} value={project.id}>
|
2023-10-18 09:25:26 +00:00
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
<span className="grid place-items-center">
|
|
|
|
{project.emoji
|
|
|
|
? renderEmoji(project.emoji)
|
|
|
|
: project.icon_prop
|
|
|
|
? renderEmoji(project.icon_prop)
|
|
|
|
: null}
|
|
|
|
</span>
|
|
|
|
<>{project.name}</>
|
|
|
|
</div>
|
2023-03-07 19:37:00 +00:00
|
|
|
</CustomSelect.Option>
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
<p className="text-gray-400">No projects found!</p>
|
|
|
|
)
|
|
|
|
) : (
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="px-2 text-sm text-custom-text-200">Loading...</div>
|
2023-03-07 19:37:00 +00:00
|
|
|
)}
|
|
|
|
</CustomSelect>
|
2023-01-26 18:12:20 +00:00
|
|
|
);
|
2023-10-18 09:25:26 +00:00
|
|
|
});
|