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.

Rejection

Tim Wilsonfcc3b5277975
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
index e33de3e577..7711beac75 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
@@ -1,5 +1,7 @@
"use client";
+import { rejectPartnerAction } from "@/lib/actions/partners/reject-partner";
+import { rejectPartnersBulkAction } from "@/lib/actions/partners/reject-partners-bulk";
import usePartner from "@/lib/swr/use-partner";
import usePartnersCount from "@/lib/swr/use-partners-count";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -11,7 +13,7 @@ import { SearchBoxPersisted } from "@/ui/shared/search-box";
import {
Button,
EditColumnsButton,
- Icon,
+ MenuItem,
Popover,
Table,
Tooltip,
@@ -19,10 +21,23 @@ import {
useRouterStuff,
useTable,
} from "@dub/ui";
-import { BadgeCheck2Fill, Dots, User, Users } from "@dub/ui/icons";
-import { cn, COUNTRIES, fetcher, formatDate, getPrettyUrl } from "@dub/utils";
+import {
+ BadgeCheck2Fill,
+ Dots,
+ LoadingSpinner,
+ Users,
+ UserXmark,
+} from "@dub/ui/icons";
+import {
+ COUNTRIES,
+ fetcher,
+ formatDate,
+ getPrettyUrl,
+ pluralize,
+} from "@dub/utils";
import { Row } from "@tanstack/react-table";
import { Command } from "cmdk";
+import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
import { useEffect, useMemo, useState } from "react";
import { toast } from "sonner";
@@ -44,7 +59,8 @@ export function ProgramPartnersApplicationsPageClient() {
const {
data: partners,
error,
- isLoading,
+ isValidating,
+ mutate,
} = useSWR<EnrolledPartnerProps[]>(
`/api/partners${getQueryString(
{
@@ -56,6 +72,7 @@ export function ProgramPartnersApplicationsPageClient() {
fetcher,
{
keepPreviousData: true,
+ revalidateOnFocus: false,
},
);
@@ -75,6 +92,19 @@ export function ProgramPartnersApplicationsPageClient() {
partnerId: detailsSheetState.partnerId,
});
+ const { executeAsync: rejectPartners, isPending: isRejectingPartners } =
+ useAction(rejectPartnersBulkAction, {
+ onError: ({ error }) => {
+ toast.error(error.serverError);
+ },
+ onSuccess: ({ input }) => {
+ toast.success(
+ `${pluralize("Partner", input.partnerIds.length)} rejected`,
+ );
+ mutate();
+ },
+ });
+
const { columnVisibility, setColumnVisibility } = useColumnVisibility();
const { pagination, setPagination } = usePagination();
@@ -221,7 +251,7 @@ export function ProgramPartnersApplicationsPageClient() {
maxSize: 43,
header: ({ table }) => <EditColumnsButton table={table} />,
cell: ({ row }) => (
- <RowMenuButton row={row} workspaceId={workspaceId!} />
+ <RowMenuButton row={row} workspaceId={workspaceId!} mutate={mutate} />
),
},
],
@@ -266,22 +296,36 @@ export function ProgramPartnersApplicationsPageClient() {
}),
getRowId: (row) => row.id,
- onRowSelectionChange: (rows) => {
- console.log(rows);
- },
selectionControls: (table) => (
<>
<Button
variant="primary"
text="Approve"
className="h-7 w-fit rounded-lg px-2.5"
- onClick={() => toast.info("WIP")}
+ onClick={() => console.log(table.getSelectedRowModel().rows)}
/>
<Button
variant="secondary"
text="Reject"
className="h-7 w-fit rounded-lg px-2.5"
- onClick={() => toast.info("WIP")}
+ loading={isRejectingPartners}
+ onClick={() => {
+ if (
+ !window.confirm(
+ "Are you sure you want to reject these applications?",
+ )
+ )
+ return;
+
+ const partnerIds = table
+ .getSelectedRowModel()
+ .rows.map((row) => row.original.id);
+
+ rejectPartners({
+ workspaceId: workspaceId!,
+ partnerIds,
+ });
+ }}
/>
</>
),
@@ -290,7 +334,7 @@ export function ProgramPartnersApplicationsPageClient() {
tdClassName: "border-l-0",
resourceName: (p) => `application${p ? "s" : ""}`,
rowCount: partnersCount || 0,
- loading: isLoading || isCurrentPartnerLoading,
+ loading: isValidating || isCurrentPartnerLoading,
error: error || countError ? "Failed to load applications" : undefined,
});
@@ -336,12 +380,25 @@ export function ProgramPartnersApplicationsPageClient() {
function RowMenuButton({
row,
workspaceId,
+ mutate,
}: {
row: Row<EnrolledPartnerProps>;
workspaceId: string;
+ mutate: () => void;
}) {
const [isOpen, setIsOpen] = useState(false);
+ const { executeAsync: rejectPartner, isPending: isRejectingPartner } =
+ useAction(rejectPartnerAction, {
+ onError: ({ error }) => {
+ toast.error(error.serverError);
+ },
+ onSuccess: () => {
+ toast.success(`Partner application rejected`);
+ mutate();
+ },
+ });
+
return (
<>
<Popover
@@ -351,12 +408,26 @@ function RowMenuButton({
<Command tabIndex={0} loop className="focus:outline-none">
<Command.List className="flex w-screen flex-col gap-1 p-1.5 text-sm focus-visible:outline-none sm:w-auto sm:min-w-[200px]">
<MenuItem
- icon={User}
- label="WIP"
+ as={Command.Item}
+ icon={UserXmark}
+ variant="danger"
onSelect={() => {
- alert("WIP");
+ setIsOpen(false);
+ if (
+ !window.confirm(
+ "Are you sure you want to reject this application?",
+ )
+ )
+ return;
+
+ rejectPartner({
+ workspaceId: workspaceId!,
+ partnerId: row.original.id,
+ });
}}
- />
+ >
+ Reject partner
+ </MenuItem>
</Command.List>
</Command>
}
@@ -366,52 +437,19 @@ function RowMenuButton({
type="button"
className="h-8 whitespace-nowrap px-2"
variant="outline"
- icon={<Dots className="h-4 w-4 shrink-0" />}
+ icon={
+ isRejectingPartner ? (
+ <LoadingSpinner className="size-4 shrink-0" />
+ ) : (
+ <Dots className="size-4 shrink-0" />
+ )
+ }
/>
</Popover>
</>
);
}
-function MenuItem({
- icon: IconComp,
- label,
- onSelect,
- variant = "default",
-}: {
- icon: Icon;
- label: string;
- onSelect: () => void;
- variant?: "default" | "danger";
-}) {
- const variantStyles = {
- default: {
- text: "text-neutral-600",
- icon: "text-neutral-500",
- },
- danger: {
- text: "text-red-600",
- icon: "text-red-600",
- },
- };
-
- const { text, icon } = variantStyles[variant];
-
- return (
- <Command.Item
- className={cn(
- "flex cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-md p-2 text-sm",
- "data-[selected=true]:bg-neutral-100",
- text,
- )}
- onSelect={onSelect}
- >
- <IconComp className={cn("size-4 shrink-0", icon)} />
- {label}
- </Command.Item>
- );
-}
-
/** Gets the current partner from the loaded partners array if available, or a separate fetch if not */
function useCurrentPartner({
partners,
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index d0fa201d76..ae26db9b5b 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -207,6 +207,7 @@ export * from "./user-crown";
export * from "./user-delete";
export * from "./user-focus";
export * from "./user-plus";
+export * from "./user-xmark";
export * from "./users";
export * from "./users-fill";
export * from "./users-settings";
diff --git a/packages/ui/src/icons/nucleo/user-xmark.tsx b/packages/ui/src/icons/nucleo/user-xmark.tsx
new file mode 100644
index 0000000000..4da571a54c
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/user-xmark.tsx
@@ -0,0 +1,56 @@
+import { SVGProps } from "react";
+
+export function UserXmark(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <circle
+ cx="9"
+ cy="4.5"
+ fill="none"
+ r="2.75"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="12"
+ x2="16"
+ y1="12"
+ y2="16"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="16"
+ x2="12"
+ y1="12"
+ y2="16"
+ />
+ <path
+ d="M10.563,9.962c-.501-.13-1.021-.212-1.563-.212-2.551,0-4.739,1.53-5.709,3.72-.365,.825,.087,1.774,.947,2.045,1.225,.386,2.846,.734,4.762,.734,.181,0,.346-.017,.522-.023"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/table/selection-toolbar.tsx b/packages/ui/src/table/selection-toolbar.tsx
index 060361540c..d44111aa04 100644
--- a/packages/ui/src/table/selection-toolbar.tsx
+++ b/packages/ui/src/table/selection-toolbar.tsx
@@ -26,17 +26,17 @@ export function SelectionToolbar<T>({
<td colSpan={table.getHeaderGroups().length} className="contents size-0">
<div
className={cn(
- "pointer-events-none absolute bottom-px left-11 right-0 top-0 bg-white opacity-0 duration-150",
+ "pointer-events-none absolute bottom-px left-11 right-0 top-0 bg-white opacity-0 duration-100",
selectedCount && "pointer-events-auto opacity-100",
)}
>
<div
className={cn(
- "flex size-full -translate-x-1 items-center gap-2 transition-transform duration-150",
+ "flex size-full -translate-x-1 items-center gap-2 transition-transform duration-100",
selectedCount && "translate-x-0",
)}
>
- <span className="text-content-emphasis mr-2 text-sm font-medium">
+ <span className="text-content-emphasis mr-2 text-sm font-medium tabular-nums">
{lastSelectedCount} selected
</span>
{controls?.(table)}
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index d0481b9387..df1bb80a90 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -60,6 +60,9 @@ export function useTable<T extends any>(
columnResizeMode = "onChange",
} = props;
+ const selectionEnabled =
+ !!props.onRowSelectionChange || !!props.selectionControls;
+
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(
props.columnVisibility ?? {},
);
@@ -94,7 +97,7 @@ export function useTable<T extends any>(
const tableColumns = useMemo(
() => [
- ...(props.onRowSelectionChange
+ ...(selectionEnabled
? [
{
id: "select",
@@ -133,7 +136,7 @@ export function useTable<T extends any>(
: []),
...columns,
],
- [props.onRowSelectionChange, columns],
+ [selectionEnabled, columns],
);
const table = useReactTable({
@@ -282,6 +285,8 @@ export function Table<T>({
children,
enableColumnResizing = false,
}: TableProps<T>) {
+ const selectionEnabled = !!onRowSelectionChange || !!selectionControls;
+
// Memoize table width calculation
const tableWidth = useMemo(() => {
if (!enableColumnResizing) return "100%";
@@ -404,7 +409,7 @@ export function Table<T>({
})}
</tr>
))}
- {onRowSelectionChange && (
+ {selectionEnabled && (
<SelectionToolbar table={table} controls={selectionControls} />
)}
</thead>