Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

UI changes to Members tab

Kiran K2e3bb4c3ccae
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
index 8e2bdc00f5..aa49f88d94 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/users/route.ts
@@ -33,6 +33,7 @@ export const GET = withWorkspace(
name: true,
email: true,
image: true,
+ isMachine: true,
},
},
createdAt: true,
@@ -60,6 +61,9 @@ export const PUT = withWorkspace(
projectId: workspace.id,
userId,
},
+ user: {
+ isMachine: false,
+ },
},
data: {
role,
@@ -86,6 +90,11 @@ export const DELETE = withWorkspace(
},
select: {
role: true,
+ user: {
+ select: {
+ isMachine: true,
+ },
+ },
},
}),
prisma.projectUsers.count({
@@ -121,6 +130,15 @@ export const DELETE = withWorkspace(
},
},
});
+
+ if (projectUser.user.isMachine) {
+ await prisma.user.delete({
+ where: {
+ id: userId,
+ },
+ });
+ }
+
return NextResponse.json(response);
},
{
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/people/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/people/page-client.tsx
index be9484b55d..969d052329 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/people/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/people/page-client.tsx
@@ -85,11 +85,7 @@ export default function WorkspacePeopleClient() {
{users ? (
users.length > 0 ? (
users.map((user) => (
- <UserCard
- key={user.email}
- user={user}
- currentTab={currentTab}
- />
+ <UserCard key={user.id} user={user} currentTab={currentTab} />
))
) : (
<div className="flex flex-col items-center justify-center py-10">
@@ -123,7 +119,7 @@ const UserCard = ({
const { isOwner } = useWorkspace();
- const { name, email, createdAt, role: currentRole } = user;
+ const { id, name, email, createdAt, role: currentRole, isMachine } = user;
const [role, setRole] = useState<"owner" | "member">(currentRole);
@@ -148,7 +144,7 @@ const UserCard = ({
<EditRoleModal />
<RemoveTeammateModal />
<div
- key={email}
+ key={id}
className="flex items-center justify-between space-x-3 px-4 py-3 sm:pl-8"
>
<div className="flex items-start space-x-3">
@@ -167,24 +163,26 @@ const UserCard = ({
session?.user?.email === email ? (
<p className="text-xs capitalize text-gray-500">{role}</p>
) : (
- <select
- className={cn(
- "rounded-md border border-gray-200 text-xs text-gray-500 focus:border-gray-600 focus:ring-gray-600",
- {
- "cursor-not-allowed bg-gray-100": !isOwner,
- },
- )}
- value={role}
- disabled={!isOwner}
- onChange={(e) => {
- setRole(e.target.value as "owner" | "member");
- setOpenPopover(false);
- setShowEditRoleModal(true);
- }}
- >
- <option value="owner">Owner</option>
- <option value="member">Member</option>
- </select>
+ !isMachine && (
+ <select
+ className={cn(
+ "rounded-md border border-gray-200 text-xs text-gray-500 focus:border-gray-600 focus:ring-gray-600",
+ {
+ "cursor-not-allowed bg-gray-100": !isOwner,
+ },
+ )}
+ value={role}
+ disabled={!isOwner}
+ onChange={(e) => {
+ setRole(e.target.value as "owner" | "member");
+ setOpenPopover(false);
+ setShowEditRoleModal(true);
+ }}
+ >
+ <option value="owner">Owner</option>
+ <option value="member">Member</option>
+ </select>
+ )
)
) : (
<p className="text-xs text-gray-500" suppressHydrationWarning>
diff --git a/apps/web/app/app.dub.co/(dashboard)/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/settings/tokens/page-client.tsx
index e9132d832e..8517915819 100644
--- a/apps/web/app/app.dub.co/(dashboard)/settings/tokens/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/settings/tokens/page-client.tsx
@@ -1,61 +1,41 @@
"use client";
import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
-import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
-import { Form, IconMenu, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ IconMenu,
+ LoadingSpinner,
+ Popover,
+ TokenAvatar,
+} from "@dub/ui";
import { fetcher, timeAgo } from "@dub/utils";
import { Token } from "@prisma/client";
import { FolderOpen, MoreVertical, Trash } from "lucide-react";
import { useState } from "react";
-import { toast } from "sonner";
import useSWR from "swr";
export default function TokensPageClient() {
- const {
- data: tokens,
- mutate,
- isLoading,
- } = useSWR<Token[]>("/api/user/tokens", fetcher);
+ const { data: tokens, isLoading } = useSWR<Token[]>(
+ "/api/user/tokens",
+ fetcher,
+ );
- const [createdToken, setCreatedToken] = useState<string | null>(null);
- const { TokenCreatedModal, setShowTokenCreatedModal } = useTokenCreatedModal({
- token: createdToken || "",
- });
return (
<>
- <TokenCreatedModal />
- <Form
- title="Create New API Key"
- description="Enter a unique name for your API key to differentiate it from other keys."
- inputAttrs={{
- name: "name",
- defaultValue: "",
- placeholder: "Jetpack API Key",
- maxLength: 140,
- }}
- helpText="<a href='https://d.to/api' target='_blank'>Learn more about Dub's API</a>"
- buttonText="Submit"
- handleSubmit={(data) =>
- fetch("/api/user/tokens", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify(data),
- }).then(async (res) => {
- if (res.status === 200) {
- const { token } = await res.json();
- setCreatedToken(token);
- setShowTokenCreatedModal(true);
- mutate();
- toast.success("Successfully created a new token!");
- } else {
- const errorMessage = await res.text();
- toast.error(errorMessage || "Something went wrong");
- }
- })
- }
- />
+ <Alert>
+ {/* <Info className="h-6 w-6 mt-1" /> */}
+ <AlertTitle>
+ User API Keys have been replaced by Workspace API Keys.
+ </AlertTitle>
+ <AlertDescription>
+ We recommend creating a new Workspace API Key for more granular
+ control over your resources such as Links, Tags, Domains, Analytics,
+ etc.
+ </AlertDescription>
+ </Alert>
+
<div className="rounded-lg border border-gray-200 bg-white">
<div className="flex flex-col space-y-3 p-5 sm:p-10">
<h2 className="text-xl font-medium">Your API Keys</h2>
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index eab4549754..ebfeddb1de 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -105,6 +105,7 @@ export interface UserProps {
source: string | null;
migratedWorkspace: string | null;
defaultWorkspace?: string;
+ isMachine: boolean;
}
export interface WorkspaceUserProps extends UserProps {
diff --git a/packages/ui/src/alert.tsx b/packages/ui/src/alert.tsx
new file mode 100644
index 0000000000..3ff4d00654
--- /dev/null
+++ b/packages/ui/src/alert.tsx
@@ -0,0 +1,64 @@
+import { cn } from "@dub/utils";
+import { cva, type VariantProps } from "class-variance-authority";
+import * as React from "react";
+
+const alertVariants = cva(
+ "relative w-full rounded-lg border px-4 py-6 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
+ {
+ variants: {
+ variant: {
+ default: "bg-background text-foreground",
+ destructive:
+ "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive border-red-500 dark:border-red-500",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ },
+);
+
+const Alert = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
+>(({ className, variant, ...props }, ref) => (
+ <div
+ ref={ref}
+ role="alert"
+ className={cn(alertVariants({ variant }), className)}
+ {...props}
+ />
+));
+
+Alert.displayName = "Alert";
+
+const AlertTitle = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLHeadingElement>
+>(({ className, ...props }, ref) => (
+ <h5
+ ref={ref}
+ className={cn(
+ "text-lg mb-2 font-medium leading-none tracking-tight",
+ className,
+ )}
+ {...props}
+ />
+));
+
+AlertTitle.displayName = "AlertTitle";
+
+const AlertDescription = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLParagraphElement>
+>(({ className, ...props }, ref) => (
+ <div
+ ref={ref}
+ className={cn("text-sm [&_p]:leading-relaxed", className)}
+ {...props}
+ />
+));
+
+AlertDescription.displayName = "AlertDescription";
+
+export { Alert, AlertDescription, AlertTitle };
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index 01618b6eec..df54c238c1 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -2,6 +2,7 @@
import "./styles.css";
// components
+export * from "./alert";
export * from "./accordion";
export * from "./avatar";
export * from "./badge";