Skip to content

Commit cba27c3

Browse files
authored
fix: home quick start widget validation (#6626)
* fix: Handled workspace switcher closing on click * fix: home quickstart widget
1 parent ffe87cc commit cba27c3

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

web/core/components/home/widgets/empty-states/no-projects.tsx

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ import { useTranslation } from "@plane/i18n";
1212
import { cn } from "@plane/utils";
1313
import { getFileURL } from "@/helpers/file.helper";
1414
// hooks
15-
import { useCommandPalette, useEventTracker, useProject, useUser, useUserPermissions } from "@/hooks/store";
15+
import {
16+
useCommandPalette,
17+
useEventTracker,
18+
useProject,
19+
useUser,
20+
useUserPermissions,
21+
useWorkspace,
22+
} from "@/hooks/store";
1623
// plane web constants
1724

1825
export const NoProjectsEmptyState = observer(() => {
@@ -24,6 +31,7 @@ export const NoProjectsEmptyState = observer(() => {
2431
const { setTrackElement } = useEventTracker();
2532
const { data: currentUser } = useUser();
2633
const { joinedProjectIds } = useProject();
34+
const { currentWorkspace: activeWorkspace } = useWorkspace();
2735
// local storage
2836
const { storedValue, setValue } = useLocalStorage(`quickstart-guide-${workspaceSlug}`, {
2937
hide: false,
@@ -37,6 +45,7 @@ export const NoProjectsEmptyState = observer(() => {
3745
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
3846
EUserPermissionsLevel.WORKSPACE
3947
);
48+
const isWorkspaceAdmin = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.WORKSPACE);
4049

4150
const EMPTY_STATE_DATA = [
4251
{
@@ -54,6 +63,7 @@ export const NoProjectsEmptyState = observer(() => {
5463
setTrackElement("Sidebar");
5564
toggleCreateProjectModal(true);
5665
},
66+
disabled: !canCreateProject,
5767
},
5868
},
5969
{
@@ -65,6 +75,7 @@ export const NoProjectsEmptyState = observer(() => {
6575
cta: {
6676
text: "home.empty.invite_team.cta",
6777
link: `/${workspaceSlug}/settings/members`,
78+
disabled: !isWorkspaceAdmin,
6879
},
6980
},
7081
{
@@ -76,6 +87,7 @@ export const NoProjectsEmptyState = observer(() => {
7687
cta: {
7788
text: "home.empty.configure_workspace.cta",
7889
link: "settings",
90+
disabled: !isWorkspaceAdmin,
7991
},
8092
},
8193
{
@@ -104,6 +116,7 @@ export const NoProjectsEmptyState = observer(() => {
104116
cta: {
105117
text: "home.empty.personalize_account.cta",
106118
link: "/profile",
119+
disabled: false,
107120
},
108121
},
109122
];
@@ -112,15 +125,15 @@ export const NoProjectsEmptyState = observer(() => {
112125
case "projects":
113126
return joinedProjectIds?.length > 0;
114127
case "visited_members":
115-
return storedValue?.visited_members;
128+
return (activeWorkspace?.total_members || 0) >= 2;
116129
case "visited_workspace":
117130
return storedValue?.visited_workspace;
118131
case "visited_profile":
119132
return storedValue?.visited_profile;
120133
}
121134
};
122135

123-
if (storedValue?.hide) return null;
136+
if (storedValue?.hide || (joinedProjectIds?.length > 0 && (activeWorkspace?.total_members || 0) >= 2)) return null;
124137

125138
return (
126139
<div>
@@ -161,28 +174,35 @@ export const NoProjectsEmptyState = observer(() => {
161174
<div className="flex items-center gap-2 bg-[#17a34a] rounded-full p-1">
162175
<Check className="size-3 text-custom-primary-100 text-white" />
163176
</div>
164-
) : item.cta.link ? (
165-
<Link
166-
href={item.cta.link}
167-
onClick={() => {
168-
if (!storedValue) return;
169-
setValue({
170-
...storedValue,
171-
[item.flag]: true,
172-
});
173-
}}
174-
className="text-custom-primary-100 hover:text-custom-primary-200 text-sm font-medium"
175-
>
176-
{t(item.cta.text)}
177-
</Link>
178177
) : (
179-
<button
180-
type="button"
181-
className="text-custom-primary-100 hover:text-custom-primary-200 text-sm font-medium"
182-
onClick={item.cta.onClick}
183-
>
184-
{t(item.cta.text)}
185-
</button>
178+
!item.cta.disabled &&
179+
(item.cta.link ? (
180+
<Link
181+
href={item.cta.link}
182+
onClick={(e) => {
183+
if (!storedValue) {
184+
e.stopPropagation();
185+
e.preventDefault();
186+
return;
187+
}
188+
setValue({
189+
...storedValue,
190+
[item.flag]: true,
191+
});
192+
}}
193+
className={cn("text-custom-primary-100 hover:text-custom-primary-200 text-sm font-medium", {})}
194+
>
195+
{t(item.cta.text)}
196+
</Link>
197+
) : (
198+
<button
199+
type="button"
200+
className="text-custom-primary-100 hover:text-custom-primary-200 text-sm font-medium"
201+
onClick={item.cta.onClick}
202+
>
203+
{t(item.cta.text)}
204+
</button>
205+
))
186206
)}
187207
</div>
188208
);

0 commit comments

Comments
 (0)