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.

Refactor bounty sheet integration and button logic

Kiran Kdf591850dd36
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
index 41f928e73e..8c9833e084 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-info.tsx
@@ -2,9 +2,9 @@
import useBounty from "@/lib/swr/use-bounty";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
-import { BountyActionButton } from "@/ui/partners/bounties/bounty-action-button";
import { formatDate, pluralize } from "@dub/utils";
import { CalendarDays, Users } from "lucide-react";
+import { BountyActionButton } from "../bounty-action-button";
export function BountyInfo() {
const { bounty, loading } = useBounty();
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
index bdff025df2..c5be2f6dc8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
@@ -588,7 +588,7 @@ export function BountySheet({
}
export function useBountySheet(
- props: { nested?: boolean } & Omit<BountySheetProps, "setIsOpen">,
+ props: { nested?: boolean } & Omit<BountySheetProps, "setIsOpen"> = {},
) {
const [isOpen, setIsOpen] = useState(false);
diff --git a/apps/web/ui/partners/bounties/bounty-action-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
similarity index 50%
rename from apps/web/ui/partners/bounties/bounty-action-button.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
index 1124565f5c..d03948ac00 100644
--- a/apps/web/ui/partners/bounties/bounty-action-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button.tsx
@@ -5,11 +5,12 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { BountyExtendedProps } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { ThreeDots } from "@/ui/shared/icons";
-import { Button, MenuItem, Popover, useRouterStuff } from "@dub/ui";
+import { Button, MenuItem, Popover } from "@dub/ui";
import { PenWriting, Trash } from "@dub/ui/icons";
import { Command } from "cmdk";
import { useState } from "react";
import { toast } from "sonner";
+import { useBountySheet } from "./add-edit-bounty-sheet";
interface BountyActionButtonProps {
bounty: BountyExtendedProps;
@@ -22,9 +23,9 @@ export function BountyActionButton({
className,
buttonClassName,
}: BountyActionButtonProps) {
- const { queryParams } = useRouterStuff();
const [isOpen, setIsOpen] = useState(false);
const { id: workspaceId } = useWorkspace();
+ const { setShowCreateBountySheet, BountySheet } = useBountySheet({ bounty });
const { confirmModal: deleteModal, setShowConfirmModal: setShowDeleteModal } =
useConfirmModal({
@@ -57,49 +58,52 @@ export function BountyActionButton({
});
return (
- <div className={className}>
+ <>
+ {BountySheet}
{deleteModal}
- <Popover
- openPopover={isOpen}
- setOpenPopover={setIsOpen}
- content={
- <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
- as={Command.Item}
- icon={PenWriting}
- variant="default"
- onSelect={() => {
- queryParams({ set: { bountyId: bounty.id } });
- setIsOpen(false);
- }}
- >
- Edit bounty
- </MenuItem>
+ <div className={className}>
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <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
+ as={Command.Item}
+ icon={PenWriting}
+ variant="default"
+ onSelect={() => {
+ setShowCreateBountySheet(true);
+ setIsOpen(false);
+ }}
+ >
+ Edit bounty
+ </MenuItem>
- <MenuItem
- as={Command.Item}
- icon={Trash}
- variant="danger"
- onSelect={() => {
- setIsOpen(false);
- setShowDeleteModal(true);
- }}
- >
- Delete bounty
- </MenuItem>
- </Command.List>
- </Command>
- }
- align="end"
- >
- <Button
- type="button"
- className={buttonClassName || "w-auto px-1.5"}
- variant="secondary"
- icon={<ThreeDots className="h-4 w-4 shrink-0" />}
- />
- </Popover>
- </div>
+ <MenuItem
+ as={Command.Item}
+ icon={Trash}
+ variant="danger"
+ onSelect={() => {
+ setIsOpen(false);
+ setShowDeleteModal(true);
+ }}
+ >
+ Delete bounty
+ </MenuItem>
+ </Command.List>
+ </Command>
+ }
+ align="end"
+ >
+ <Button
+ type="button"
+ className={buttonClassName || "w-auto px-1.5"}
+ variant="secondary"
+ icon={<ThreeDots className="h-4 w-4 shrink-0" />}
+ />
+ </Popover>
+ </div>
+ </>
);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
index a3bf4ed1f7..70c165e403 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
@@ -1,6 +1,6 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyExtendedProps } from "@/lib/types";
-import { BountyActionButton } from "@/ui/partners/bounties/bounty-action-button";
+import { BountyActionButton } from "app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-action-button";
import { BountyThumbnailImage } from "@/ui/partners/bounties/bounty-thumbnail-image";
import { Calendar6, Users } from "@dub/ui/icons";
import { formatDate, pluralize } from "@dub/utils";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
index be6edcd593..1d59fee483 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-list.tsx
@@ -3,29 +3,16 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { BountyExtendedProps } from "@/lib/types";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { Button, useRouterStuff } from "@dub/ui";
+import { Button } from "@dub/ui";
import { fetcher } from "@dub/utils";
import { Trophy } from "lucide-react";
-import { useEffect, useState } from "react";
import useSWR from "swr";
-import { BountySheet } from "./add-edit-bounty-sheet";
+import { useBountySheet } from "./add-edit-bounty-sheet";
import { BountyCard, BountyCardSkeleton } from "./bounty-card";
export function BountyList() {
- const { searchParams } = useRouterStuff();
const { id: workspaceId } = useWorkspace();
-
- const [bountySheetState, setBountySheetState] = useState<
- { open: false; bountyId: string | null } | { open: true; bountyId: string }
- >({ open: false, bountyId: null });
-
- // Open/close edit bounty sheet
- useEffect(() => {
- const bountyId = searchParams.get("bountyId");
- setBountySheetState(
- bountyId ? { open: true, bountyId } : { open: false, bountyId: null },
- );
- }, [searchParams.get("bountyId")]);
+ const { setShowCreateBountySheet, BountySheet } = useBountySheet();
const { data: bounties, isLoading } = useSWR<BountyExtendedProps[]>(
workspaceId ? `/api/bounties?workspaceId=${workspaceId}` : null,
@@ -35,22 +22,9 @@ export function BountyList() {
},
);
- const currentBounty = bountySheetState.bountyId
- ? bounties?.find((b) => b?.id === bountySheetState.bountyId)
- : undefined;
-
return (
<>
- {bountySheetState.open &&
- (!bountySheetState.bountyId || currentBounty) && (
- <BountySheet
- isOpen={bountySheetState.open}
- setIsOpen={(open) =>
- setBountySheetState((s) => ({ ...s, open }) as any)
- }
- bounty={currentBounty}
- />
- )}
+ {BountySheet}
{bounties?.length !== 0 || isLoading ? (
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 xl:grid-cols-3">
{isLoading
@@ -87,11 +61,7 @@ export function BountyList() {
<Button
text="Create bounty"
variant="primary"
- onClick={() =>
- setBountySheetState(
- (s) => ({ bountyId: null, open: true }) as any,
- )
- }
+ onClick={() => setShowCreateBountySheet(true)}
/>
}
/>