|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { acceptInvite } from "@/actions/acceptInvite"; |
| 4 | +import type { Team } from "@/api/team"; |
| 5 | +import { ToggleThemeButton } from "@/components/color-mode-toggle"; |
| 6 | +import { Spinner } from "@/components/ui/Spinner/Spinner"; |
| 7 | +import { DotsBackgroundPattern } from "@/components/ui/background-patterns"; |
| 8 | +import { Button } from "@/components/ui/button"; |
| 9 | +import { useDashboardRouter } from "@/lib/DashboardRouter"; |
| 10 | +import { useMutation } from "@tanstack/react-query"; |
| 11 | +import { CheckIcon, UsersIcon } from "lucide-react"; |
| 12 | +import Link from "next/link"; |
| 13 | +import { toast } from "sonner"; |
| 14 | +import { ThirdwebMiniLogo } from "../../../../components/ThirdwebMiniLogo"; |
| 15 | + |
| 16 | +export function JoinTeamPage(props: { |
| 17 | + team: Team; |
| 18 | + inviteId: string; |
| 19 | +}) { |
| 20 | + const router = useDashboardRouter(); |
| 21 | + return ( |
| 22 | + <JoinTeamPageUI |
| 23 | + teamName={props.team.name} |
| 24 | + invite={async () => { |
| 25 | + const res = await acceptInvite({ |
| 26 | + inviteId: props.inviteId, |
| 27 | + teamId: props.team.id, |
| 28 | + }); |
| 29 | + |
| 30 | + if (!res.ok) { |
| 31 | + throw new Error(res.errorMessage); |
| 32 | + } |
| 33 | + |
| 34 | + router.replace(`/teams/${props.team.slug}`); |
| 35 | + }} |
| 36 | + /> |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +export function JoinTeamPageUI(props: { |
| 41 | + teamName: string; |
| 42 | + invite: () => Promise<void>; |
| 43 | +}) { |
| 44 | + return ( |
| 45 | + <div className="relative flex min-h-dvh flex-col overflow-hidden"> |
| 46 | + <Header /> |
| 47 | + |
| 48 | + <div className="container flex grow flex-col items-center justify-center "> |
| 49 | + <div className="z-10"> |
| 50 | + <AcceptInviteCardUI teamName={props.teamName} invite={props.invite} /> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + |
| 54 | + <DotsBackgroundPattern /> |
| 55 | + </div> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +function Header() { |
| 60 | + return ( |
| 61 | + <div className="border-b bg-background"> |
| 62 | + <header className="container flex w-full flex-row items-center justify-between px-6 py-4"> |
| 63 | + <div className="flex shrink-0 items-center gap-3"> |
| 64 | + <ThirdwebMiniLogo className="size-7 md:size-8" /> |
| 65 | + <span className="font-medium text-foreground text-xl tracking-tight"> |
| 66 | + thirdweb |
| 67 | + </span> |
| 68 | + </div> |
| 69 | + |
| 70 | + <div className="flex items-center gap-4"> |
| 71 | + <div className="flex items-center gap-2"> |
| 72 | + <Link |
| 73 | + href="/support" |
| 74 | + target="_blank" |
| 75 | + className="px-2 text-muted-foreground text-sm hover:text-foreground" |
| 76 | + > |
| 77 | + Support |
| 78 | + </Link> |
| 79 | + </div> |
| 80 | + <ToggleThemeButton /> |
| 81 | + </div> |
| 82 | + </header> |
| 83 | + </div> |
| 84 | + ); |
| 85 | +} |
| 86 | + |
| 87 | +function AcceptInviteCardUI(props: { |
| 88 | + teamName: string; |
| 89 | + invite: () => Promise<void>; |
| 90 | +}) { |
| 91 | + const invite = useMutation({ |
| 92 | + mutationFn: props.invite, |
| 93 | + }); |
| 94 | + return ( |
| 95 | + <div className="w-full rounded-xl border bg-card shadow-2xl lg:w-[600px]"> |
| 96 | + <div className="p-4 lg:p-6"> |
| 97 | + <div className="mb-5 flex size-12 items-center justify-center rounded-full border bg-background"> |
| 98 | + <UsersIcon className="size-5 text-muted-foreground" /> |
| 99 | + </div> |
| 100 | + |
| 101 | + <h1 className="mb-3 font-semibold text-2xl tracking-tight"> |
| 102 | + Join your team on thirdweb |
| 103 | + </h1> |
| 104 | + <p className="mb-1.5 font-medium text-muted-foreground"> |
| 105 | + You have been invited to join team{" "} |
| 106 | + <em className="text-foreground not-italic">{props.teamName}</em>{" "} |
| 107 | + </p> |
| 108 | + |
| 109 | + <p className="text-muted-foreground"> |
| 110 | + Accepting this invite will add you to the team and give you access to |
| 111 | + the team's resources |
| 112 | + </p> |
| 113 | + </div> |
| 114 | + <div className="flex justify-end border-t p-4 lg:p-6"> |
| 115 | + <Button |
| 116 | + disabled={invite.isPending} |
| 117 | + className="gap-2" |
| 118 | + onClick={() => { |
| 119 | + const promise = invite.mutateAsync(); |
| 120 | + toast.promise(promise, { |
| 121 | + success: "Invite accepted", |
| 122 | + error: (e) => { |
| 123 | + if (e instanceof Error && e.message) { |
| 124 | + return e.message; |
| 125 | + } |
| 126 | + return "Failed to accept invite"; |
| 127 | + }, |
| 128 | + }); |
| 129 | + }} |
| 130 | + > |
| 131 | + Accept Invite |
| 132 | + {invite.isPending ? ( |
| 133 | + <Spinner className="size-4" /> |
| 134 | + ) : ( |
| 135 | + <CheckIcon className="size-4" /> |
| 136 | + )} |
| 137 | + </Button> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + ); |
| 141 | +} |
0 commit comments