Skip to content

Commit d7cfb82

Browse files
committed
feat: add project creation functionality with limit check in SelectProject component
1 parent cfc1899 commit d7cfb82

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/entities/project/ui/SelectProject.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
HStack,
77
Box,
88
Center,
9-
useDisclosure
9+
useDisclosure,
10+
Tooltip
1011
} from '@chakra-ui/react';
1112
import {
1213
ArrowIcon,
@@ -30,6 +31,18 @@ const SelectProject_: FunctionComponent<ComponentProps<typeof Box>> = props => {
3031
if (!projectsStore.selectedProject) {
3132
return null;
3233
}
34+
const isLimitReached = projectsStore.projects$.value.length >= 10;
35+
36+
const createProjectMenuItem = ({ isDisabled }: { isDisabled: boolean }) => (
37+
<MenuItem isDisabled={isDisabled} onClick={() => !isDisabled && onOpen()}>
38+
<Center w="7" minW="7" h="7" mr="2" borderRadius="sm" bgColor="background.contentTint">
39+
<PlusIcon16 />
40+
</Center>
41+
<Text textStyle="label2" color="text.primary" noOfLines={1}>
42+
Create Project
43+
</Text>
44+
</MenuItem>
45+
);
3346

3447
return (
3548
<Box {...props}>
@@ -66,21 +79,14 @@ const SelectProject_: FunctionComponent<ComponentProps<typeof Box>> = props => {
6679
{projectsStore.projects$.value.map(project => (
6780
<SelectProjectItem project={project} key={project.id} />
6881
))}
69-
<MenuItem onClick={onOpen}>
70-
<Center
71-
w="7"
72-
minW="7"
73-
h="7"
74-
mr="2"
75-
borderRadius="sm"
76-
bgColor="background.contentTint"
77-
>
78-
<PlusIcon16 />
79-
</Center>
80-
<Text textStyle="label2" color="text.primary" noOfLines={1}>
81-
Create Project
82-
</Text>
83-
</MenuItem>
82+
83+
{isLimitReached ? (
84+
<Tooltip hasArrow label="Project limit reached (10 max)">
85+
{createProjectMenuItem({ isDisabled: true })}
86+
</Tooltip>
87+
) : (
88+
createProjectMenuItem({ isDisabled: false })
89+
)}
8490
</MenuList>
8591
</Menu>
8692
<CreateProjectModal isOpen={isOpen} onClose={onClose} />

0 commit comments

Comments
 (0)