Skip to content

Commit 3effbc6

Browse files
committed
Make the AddEntity buttons be disabled instead of invisible when the user doesn't have permission or the appropriate pre-conditions chosen to be able to use them.
1 parent 0702b26 commit 3effbc6

File tree

5 files changed

+37
-108
lines changed

5 files changed

+37
-108
lines changed

src/components/ui/dashboard/add-coaching-session-button.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { cn } from "@/components/lib/utils";
44

55
interface AddCoachingSessionButtonProps
66
extends React.ComponentPropsWithoutRef<"button"> {
7+
disabled?: boolean;
78
onClick?: () => void;
89
}
910

1011
export const AddCoachingSessionButton = forwardRef<
1112
HTMLButtonElement,
1213
AddCoachingSessionButtonProps
13-
>(({ className, onClick, ...props }, ref) => {
14+
>(({ className, disabled, onClick, ...props }, ref) => {
1415
const [hoveredItem, setHoveredItem] = useState<string | null>(null);
1516

1617
const handleMouseEnter = (item: string) => {
@@ -24,10 +25,13 @@ export const AddCoachingSessionButton = forwardRef<
2425
return (
2526
<button
2627
ref={ref}
28+
disabled={disabled}
2729
className={cn(
28-
"flex items-center rounded-lg border border-border bg-card p-4 text-left transition-all hover:shadow-md",
29-
hoveredItem === "coaching" && "shadow-md",
30-
className // Merges passed className with existing classes
30+
"flex items-center rounded-lg border border-border bg-card p-4 text-left",
31+
disabled
32+
? "text-gray-300 cursor-not-allowed dark:bg-gray-700 dark:text-gray-400"
33+
: "bg-card text-black hover:shadow-md transition-all dark:bg-gray-800 dark:text-white",
34+
className
3135
)}
3236
onMouseEnter={() => handleMouseEnter("coaching")}
3337
onMouseLeave={handleMouseLeave}
@@ -38,7 +42,7 @@ export const AddCoachingSessionButton = forwardRef<
3842
<Calendar className="h-8 w-8 text-primary" />
3943
</div>
4044
<span className="ml-4 text-lg font-medium">Coaching Session</span>
41-
{hoveredItem === "coaching" && (
45+
{!disabled && hoveredItem === "coaching" && (
4246
<Plus className="ml-auto h-6 w-6 text-primary" />
4347
)}
4448
</button>

src/components/ui/dashboard/add-coaching-session-dialog.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export function AddCoachingSessionDialog({
9191
...(dialogTrigger.props as React.HTMLAttributes<HTMLButtonElement>),
9292
className: cn(
9393
(dialogTrigger.props as React.HTMLAttributes<HTMLButtonElement>)
94-
.className,
95-
isCoach ? "visible" : "invisible"
94+
.className
9695
),
9796
})}
9897
</DialogTrigger>

src/components/ui/dashboard/add-entities.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { AddCoachingSessionButton } from "./add-coaching-session-button";
66
import { AddMemberButton } from "./add-member-button";
77
import { useRouter } from "next/navigation";
88
import { useOrganizationStateStore } from "@/lib/providers/organization-state-store-provider";
9+
import { useAuthStore } from "@/lib/providers/auth-store-provider";
910

1011
export default function AddEntities() {
1112
const router = useRouter();
1213
const [open, setOpen] = useState(false);
1314
const { currentOrganizationId } = useOrganizationStateStore((state) => state);
15+
const { isCoach } = useAuthStore((state) => state);
1416

1517
const onCoachingSessionAdded = () => {
1618
setOpen(false);
@@ -30,14 +32,21 @@ export default function AddEntities() {
3032
open={open}
3133
onOpenChange={setOpen}
3234
onCoachingSessionAdded={onCoachingSessionAdded}
33-
dialogTrigger={<AddCoachingSessionButton />}
35+
dialogTrigger={
36+
<AddCoachingSessionButton
37+
disabled={!isCoach || !currentOrganizationId}
38+
/>
39+
}
3440
/>
3541

3642
{/* TODO: Refactor the AddMemberButton and AddMemberDialog to work just like
3743
AddCoachingSessionDialog does above, where the dialog is the parent container
3844
and it accepts a AddMemberButton as the dialogTrigger parameter.
3945
*/}
40-
<AddMemberButton onClick={onMemberButtonClicked} />
46+
<AddMemberButton
47+
disabled={!isCoach || !currentOrganizationId}
48+
onClick={onMemberButtonClicked}
49+
/>
4150
</div>
4251
</div>
4352
);

src/components/ui/dashboard/add-member-button.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
import { useState } from "react";
44
import { Plus, Users } from "lucide-react";
5-
import { cn } from "@/components/lib/utils";
65
import { useOrganizationStateStore } from "@/lib/providers/organization-state-store-provider";
76
import { useRouter } from "next/navigation";
87

8+
import { cn } from "@/components/lib/utils";
9+
910
interface AddMemberButtonProps {
11+
disabled?: boolean;
1012
onClick?: () => void;
1113
}
1214

13-
export function AddMemberButton({ onClick }: AddMemberButtonProps) {
15+
export function AddMemberButton({ disabled, onClick }: AddMemberButtonProps) {
1416
const router = useRouter();
1517
const { currentOrganizationId } = useOrganizationStateStore((state) => state);
1618
const [hoveredItem, setHoveredItem] = useState<string | null>(null);
@@ -27,24 +29,28 @@ export function AddMemberButton({ onClick }: AddMemberButtonProps) {
2729
<>
2830
<button
2931
className={cn(
30-
"flex items-center rounded-lg border border-border bg-card p-4 text-left transition-all hover:shadow-md",
31-
hoveredItem === "member" && "shadow-md"
32+
"flex items-center rounded-lg border border-border bg-card p-4 text-left",
33+
disabled
34+
? "text-gray-300 cursor-not-allowed dark:bg-gray-700 dark:text-gray-400"
35+
: "bg-card text-black hover:shadow-md transition-all dark:bg-gray-800 dark:text-white"
3236
)}
3337
onMouseEnter={() => handleMouseEnter("member")}
3438
onMouseLeave={handleMouseLeave}
3539
onClick={() => {
36-
// Navigate to the Members page and display the AddMemberDialog
37-
router.push(
38-
`/organizations/${currentOrganizationId}/members?addMember=true`
39-
);
40-
onClick;
40+
if (!disabled) {
41+
// Navigate to the Members page and display the AddMemberDialog
42+
router.push(
43+
`/organizations/${currentOrganizationId}/members?addMember=true`
44+
);
45+
onClick;
46+
}
4147
}}
4248
>
4349
<div className="flex h-16 w-16 items-center justify-center rounded-md bg-primary/10">
4450
<Users className="h-8 w-8 text-primary" />
4551
</div>
4652
<span className="ml-4 text-lg font-medium">Organization Member</span>
47-
{hoveredItem === "member" && (
53+
{!disabled && hoveredItem === "member" && (
4854
<Plus className="ml-auto h-6 w-6 text-primary" />
4955
)}
5056
</button>

src/styles/globals.css

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,6 @@
22
@tailwind components;
33
@tailwind utilities;
44

5-
/* @layer base {
6-
:root {
7-
--background: 0 0% 100%;
8-
--foreground: 222.2 84% 4.9%;
9-
10-
--card: 0 0% 100%;
11-
--card-foreground: 222.2 84% 4.9%;
12-
13-
--popover: 0 0% 100%;
14-
--popover-foreground: 222.2 84% 4.9%;
15-
16-
--primary: 222.2 47.4% 11.2%;
17-
--primary-foreground: 210 40% 98%;
18-
19-
--secondary: 210 40% 96.1%;
20-
--secondary-foreground: 222.2 47.4% 11.2%;
21-
22-
--muted: 210 40% 96.1%;
23-
--muted-foreground: 215.4 16.3% 46.9%;
24-
25-
--accent: 210 40% 96.1%;
26-
--accent-foreground: 222.2 47.4% 11.2%;
27-
28-
--destructive: 0 84.2% 60.2%;
29-
--destructive-foreground: 210 40% 98%;
30-
31-
--border: 214.3 31.8% 91.4%;
32-
--input: 214.3 31.8% 91.4%;
33-
--ring: 222.2 84% 4.9%;
34-
35-
--radius: 0.5rem;
36-
37-
--sidebar-background: 0 0% 98%;
38-
39-
--sidebar-foreground: 240 5.3% 26.1%;
40-
41-
--sidebar-primary: 240 5.9% 10%;
42-
43-
--sidebar-primary-foreground: 0 0% 98%;
44-
45-
--sidebar-accent: 240 4.8% 95.9%;
46-
47-
--sidebar-accent-foreground: 240 5.9% 10%;
48-
49-
--sidebar-border: 220 13% 91%;
50-
51-
--sidebar-ring: 217.2 91.2% 59.8%;
52-
}
53-
54-
.dark {
55-
--background: 222.2 84% 4.9%;
56-
--foreground: 210 40% 98%;
57-
58-
--card: 222.2 84% 4.9%;
59-
--card-foreground: 210 40% 98%;
60-
61-
--popover: 222.2 84% 4.9%;
62-
--popover-foreground: 210 40% 98%;
63-
64-
--primary: 210 40% 98%;
65-
--primary-foreground: 222.2 47.4% 11.2%;
66-
67-
--secondary: 217.2 32.6% 17.5%;
68-
--secondary-foreground: 210 40% 98%;
69-
70-
--muted: 217.2 32.6% 17.5%;
71-
--muted-foreground: 215 20.2% 65.1%;
72-
73-
--accent: 217.2 32.6% 17.5%;
74-
--accent-foreground: 210 40% 98%;
75-
76-
--destructive: 0 62.8% 30.6%;
77-
--destructive-foreground: 210 40% 98%;
78-
79-
--border: 217.2 32.6% 17.5%;
80-
--input: 217.2 32.6% 17.5%;
81-
--ring: 212.7 26.8% 83.9%;
82-
--sidebar-background: 240 5.9% 10%;
83-
--sidebar-foreground: 240 4.8% 95.9%;
84-
--sidebar-primary: 224.3 76.3% 48%;
85-
--sidebar-primary-foreground: 0 0% 100%;
86-
--sidebar-accent: 240 3.7% 15.9%;
87-
--sidebar-accent-foreground: 240 4.8% 95.9%;
88-
--sidebar-border: 240 3.7% 15.9%;
89-
--sidebar-ring: 217.2 91.2% 59.8%;
90-
}
91-
} */
92-
935
@layer base {
946
* {
957
@apply border-border;
@@ -190,4 +102,3 @@
190102
.group-data-\[collapsible\=icon\]\/sidebar-wrapper [data-sidebar="menu-button"] {
191103
justify-content: center;
192104
}
193-

0 commit comments

Comments
 (0)