🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
refactor(members): enhance loading state handling and improve member display
Bill Yang7d663a487479
diff --git a/client/src/app/organization/members/components/Invitations.tsx b/client/src/app/organization/members/components/Invitations.tsxindex 2556fbb7d..155f1ddfe 100644--- a/client/src/app/organization/members/components/Invitations.tsx+++ b/client/src/app/organization/members/components/Invitations.tsx@@ -32,8 +32,11 @@ export function Invitations({ organizationId, isOwner }: InvitationsProps) {null);- const { data: invitations, refetch: refetchInvitations } =- useOrganizationInvitations(organizationId);+ const {+ data: invitations,+ refetch: refetchInvitations,+ isLoading: invitationsLoading,+ } = useOrganizationInvitations(organizationId);const handleCancelInvitation = async (invitationId: string) => {try {@@ -101,62 +104,91 @@ export function Invitations({ organizationId, isOwner }: InvitationsProps) {</TableRow></TableHeader><TableBody>- {invitations?.length && invitations.length > 0 ? (- invitations.map((invitation) => (- <TableRow key={invitation.id}>- <TableCell>{invitation.email}</TableCell>- <TableCell className="capitalize">- {invitation.role}+ {invitationsLoading ? (+ // Loading skeleton rows+ Array.from({ length: 2 }).map((_, index) => (+ <TableRow key={`loading-${index}`}>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-32"></div>+ </TableCell>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-16"></div></TableCell><TableCell>- <Badge variant={getBadgeVariant(invitation.status)}>- {invitation.status}- </Badge>+ <div className="h-6 bg-muted animate-pulse rounded w-20"></div></TableCell><TableCell>- {DateTime.fromJSDate(- new Date(invitation.expiresAt)- ).toLocaleString(DateTime.DATE_SHORT)}+ <div className="h-4 bg-muted animate-pulse rounded w-20"></div></TableCell>{isOwner && (- <TableCell className="text-right">- {invitation.status === "pending" && (- <Button- variant="default"- size="sm"- disabled={loadingInvitationId === invitation.id}- onClick={() => handleCancelInvitation(invitation.id)}- >- {loadingInvitationId === invitation.id- ? "Processing..."- : "Cancel"}- </Button>- )}- {invitation.status === "canceled" && (- <Button- variant="default"- size="sm"- disabled={loadingInvitationId === invitation.id}- onClick={() => handleResendInvitation(invitation)}- >- {loadingInvitationId === invitation.id- ? "Processing..."- : "Resend"}- </Button>- )}+ <TableCell>+ <div className="h-8 bg-muted animate-pulse rounded w-16 ml-auto"></div></TableCell>)}</TableRow>))) : (- <TableRow>- <TableCell- colSpan={isOwner ? 5 : 4}- className="text-center py-6 text-muted-foreground"- >- No pending invitations- </TableCell>- </TableRow>+ <>+ {invitations?.length && invitations.length > 0 ? (+ invitations.map((invitation) => (+ <TableRow key={invitation.id}>+ <TableCell>{invitation.email}</TableCell>+ <TableCell className="capitalize">+ {invitation.role}+ </TableCell>+ <TableCell>+ <Badge variant={getBadgeVariant(invitation.status)}>+ {invitation.status}+ </Badge>+ </TableCell>+ <TableCell>+ {DateTime.fromJSDate(+ new Date(invitation.expiresAt)+ ).toLocaleString(DateTime.DATE_SHORT)}+ </TableCell>+ {isOwner && (+ <TableCell className="text-right">+ {invitation.status === "pending" && (+ <Button+ variant="default"+ size="sm"+ disabled={loadingInvitationId === invitation.id}+ onClick={() =>+ handleCancelInvitation(invitation.id)+ }+ >+ {loadingInvitationId === invitation.id+ ? "Processing..."+ : "Cancel"}+ </Button>+ )}+ {invitation.status === "canceled" && (+ <Button+ variant="default"+ size="sm"+ disabled={loadingInvitationId === invitation.id}+ onClick={() => handleResendInvitation(invitation)}+ >+ {loadingInvitationId === invitation.id+ ? "Processing..."+ : "Resend"}+ </Button>+ )}+ </TableCell>+ )}+ </TableRow>+ ))+ ) : (+ <TableRow>+ <TableCell+ colSpan={isOwner ? 5 : 4}+ className="text-center py-6 text-muted-foreground"+ >+ No pending invitations+ </TableCell>+ </TableRow>+ )}+ </>)}</TableBody></Table>diff --git a/client/src/app/organization/members/components/RemoveMemberDialog.tsx b/client/src/app/organization/members/components/RemoveMemberDialog.tsxindex 75e4cc191..2ced5cff4 100644--- a/client/src/app/organization/members/components/RemoveMemberDialog.tsx+++ b/client/src/app/organization/members/components/RemoveMemberDialog.tsx@@ -50,7 +50,7 @@ export function RemoveMemberDialog({return (<Dialog open={open} onOpenChange={setOpen}><DialogTrigger asChild>- <Button size="sm" variant="ghost" className="text-destructive">+ <Button size="smIcon" variant="ghost" className="text-destructive"><UserMinus className="h-4 w-4" /></Button></DialogTrigger>diff --git a/client/src/app/organization/members/page.tsx b/client/src/app/organization/members/page.tsxindex 2f6aff4de..339b8eee7 100644--- a/client/src/app/organization/members/page.tsx+++ b/client/src/app/organization/members/page.tsx@@ -59,7 +59,11 @@ function Organization({createdAt: Date;};}) {- const { data: members, refetch } = useOrganizationMembers(org.id);+ const {+ data: members,+ refetch,+ isLoading: membersLoading,+ } = useOrganizationMembers(org.id);const { refetch: refetchInvitations } = useOrganizationInvitations(org.id);const { data } = authClient.useSession();@@ -77,12 +81,7 @@ function Organization({<Card className="w-full"><CardHeader className="pb-2"><div className="flex items-center justify-between flex-wrap gap-2">- <CardTitle className="text-xl">- {org.name}- <span className="text-sm font-normal text-muted-foreground ml-2">- ({org.slug})- </span>- </CardTitle>+ <CardTitle className="text-xl">Members</CardTitle><div className="flex items-center gap-2">{isOwner && (@@ -116,38 +115,67 @@ function Organization({</TableRow></TableHeader><TableBody>- {members?.data?.map((member: any) => (- <TableRow key={member.id}>- <TableCell>{member.user?.name || "—"}</TableCell>- <TableCell>{member.user?.email}</TableCell>- <TableCell className="capitalize">{member.role}</TableCell>- <TableCell>- {DateTime.fromSQL(member.createdAt).toLocaleString(- DateTime.DATE_SHORT+ {membersLoading ? (+ // Loading skeleton rows+ Array.from({ length: 3 }).map((_, index) => (+ <TableRow key={`loading-${index}`}>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-24"></div>+ </TableCell>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-32"></div>+ </TableCell>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-16"></div>+ </TableCell>+ <TableCell>+ <div className="h-4 bg-muted animate-pulse rounded w-20"></div>+ </TableCell>+ {isOwner && (+ <TableCell>+ <div className="h-8 bg-muted animate-pulse rounded w-16 ml-auto"></div>+ </TableCell>)}- </TableCell>- {isOwner && (- <TableCell className="text-right">- {member.role !== "owner" && (- <RemoveMemberDialog- member={member}- organizationId={org.id}- onSuccess={handleRefresh}- />+ </TableRow>+ ))+ ) : (+ <>+ {members?.data?.map((member: any) => (+ <TableRow key={member.id}>+ <TableCell>{member.user?.name || "—"}</TableCell>+ <TableCell>{member.user?.email}</TableCell>+ <TableCell className="capitalize">+ {member.role}+ </TableCell>+ <TableCell>+ {DateTime.fromSQL(member.createdAt).toLocaleString(+ DateTime.DATE_SHORT+ )}+ </TableCell>+ {isOwner && (+ <TableCell className="text-right">+ {member.role !== "owner" && (+ <RemoveMemberDialog+ member={member}+ organizationId={org.id}+ onSuccess={handleRefresh}+ />+ )}+ </TableCell>)}- </TableCell>+ </TableRow>+ ))}+ {(!members?.data || members.data.length === 0) && (+ <TableRow>+ <TableCell+ colSpan={isOwner ? 5 : 4}+ className="text-center py-6 text-muted-foreground"+ >+ No members found+ </TableCell>+ </TableRow>)}- </TableRow>- ))}- {(!members?.data || members.data.length === 0) && (- <TableRow>- <TableCell- colSpan={isOwner ? 5 : 4}- className="text-center py-6 text-muted-foreground"- >- No members found- </TableCell>- </TableRow>+ </>)}</TableBody></Table>diff --git a/client/src/app/organization/subscription/page.tsx b/client/src/app/organization/subscription/page.tsxindex 53b627ffd..63dd68ac6 100644--- a/client/src/app/organization/subscription/page.tsx+++ b/client/src/app/organization/subscription/page.tsx@@ -22,7 +22,7 @@ export default function OrganizationSubscriptionPage() {const { data: activeSubscription, isLoading: isLoadingSubscription } =useStripeSubscription();- const { data: activeOrg } = authClient.useActiveOrganization();+ const { data: activeOrg, isPending } = authClient.useActiveOrganization();const { data: session } = authClient.useSession();// Check if the current user is an owner by looking at the members in the active organization@@ -31,11 +31,11 @@ export default function OrganizationSubscriptionPage() {);const isOwner = currentUserMember?.role === "owner";- const isLoading = isLoadingSubscription;+ const isLoading = isLoadingSubscription || isPending;// Determine which plan to displayconst renderPlanComponent = () => {- if (!activeOrg) {+ if (!activeOrg && !isPending) {return (<NoOrganization message="You need to select an organization to manage your subscription." />);