Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions apps/dashboard/src/@/actions/acceptInvite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use server";

import { getAuthToken } from "../../app/api/lib/getAuthToken";
import { API_SERVER_URL } from "../constants/env";

export async function acceptInvite(options: {
teamId: string;
inviteId: string;
}) {
const token = await getAuthToken();

if (!token) {
return {
ok: false,
errorMessage: "You are not authorized to perform this action",
};
}

const res = await fetch(
`${API_SERVER_URL}/v1/teams/${options.teamId}/invites/${options.inviteId}/accept`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({}),
},
);

if (!res.ok) {
let errorMessage = "Failed to accept invite";
try {
const result = (await res.json()) as {
error: {
code: string;
message: string;
statusCode: number;
};
};
errorMessage = result.error.message;
} catch {}

return {
ok: false,
errorMessage,
};
}

return {
ok: true,
};
}
68 changes: 68 additions & 0 deletions apps/dashboard/src/@/actions/sendTeamInvite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use server";

import { getAuthToken } from "../../app/api/lib/getAuthToken";
import { API_SERVER_URL } from "../constants/env";

export async function sendTeamInvites(options: {
teamId: string;
invites: Array<{ email: string; role: "OWNER" | "MEMBER" }>;
}): Promise<
| {
ok: true;
results: Array<"fulfilled" | "rejected">;
}
| {
ok: false;
errorMessage: string;
}
> {
const token = await getAuthToken();

if (!token) {
return {
ok: false,
errorMessage: "You are not authorized to perform this action",
};
}

const results = await Promise.allSettled(
options.invites.map((invite) => sendInvite(options.teamId, invite, token)),
);

return {
ok: true,
results: results.map((x) => x.status),
};
}

async function sendInvite(
teamId: string,
invite: { email: string; role: "OWNER" | "MEMBER" },
token: string,
) {
const res = await fetch(`${API_SERVER_URL}/v1/teams/${teamId}/invites`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
inviteEmail: invite.email,
inviteRole: invite.role,
}),
});

if (!res.ok) {
const errorMessage = await res.text();
return {
email: invite.email,
ok: false,
errorMessage,
};
}

return {
email: invite.email,
ok: true,
};
}
46 changes: 46 additions & 0 deletions apps/dashboard/src/@/api/team-invites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getAuthToken } from "../../app/api/lib/getAuthToken";
import { API_SERVER_URL } from "../constants/env";

export type TeamInvite = {
id: string;
teamId: string;
email: string;
role: "OWNER" | "MEMBER";
createdAt: string;
status: "pending" | "accepted" | "expired";
expiresAt: string;
};

export async function getTeamInvites(
teamId: string,
options: {
count: number;
start: number;
},
) {
const authToken = await getAuthToken();

if (!authToken) {
throw new Error("Unauthorized");
}

const res = await fetch(
`${API_SERVER_URL}/v1/teams/${teamId}/invites?skip=${options.start}&take=${options.count}`,
{
headers: {
Authorization: `Bearer ${authToken}`,
},
},
);

if (!res.ok) {
const errorMessage = await res.text();
throw new Error(errorMessage);
}

const json = (await res.json()) as {
result: TeamInvite[];
};

return json.result;
}
9 changes: 5 additions & 4 deletions apps/dashboard/src/@/api/team-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ export type TeamAccountRole =

export type TeamMember = {
account: {
creatorWalletAddress: string;
name: string;
email: string | null;
image: string | null;
};
} & {
deletedAt: Date | null;
deletedAt: string | null;
accountId: string;
teamId: string;
createdAt: Date;
updatedAt: Date;
createdAt: string;
updatedAt: string;
role: TeamAccountRole;
};

Expand Down
16 changes: 15 additions & 1 deletion apps/dashboard/src/@/api/team.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "server-only";
import { API_SERVER_URL } from "@/constants/env";
import { API_SERVER_URL, THIRDWEB_API_SECRET } from "@/constants/env";
import type { TeamResponse } from "@thirdweb-dev/service-utils";
import { getAuthToken } from "../../app/api/lib/getAuthToken";

Expand All @@ -22,6 +22,20 @@ export async function getTeamBySlug(slug: string) {
return null;
}

export async function service_getTeamBySlug(slug: string) {
const teamRes = await fetch(`${API_SERVER_URL}/v1/teams/${slug}`, {
headers: {
"x-service-api-key": THIRDWEB_API_SECRET,
},
});

if (teamRes.ok) {
return (await teamRes.json())?.result as Team;
}

return null;
}

export function getTeamById(id: string) {
return getTeamBySlug(id);
}
Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/src/@/components/ui/background-patterns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { cn } from "@/lib/utils";

export function DotsBackgroundPattern(props: {
className?: string;
}) {
return (
<div
className={cn(
"pointer-events-none absolute inset-0 text-foreground/30 dark:text-foreground/10",
props.className,
)}
style={{
backgroundImage: "radial-gradient(currentColor 1px, transparent 1px)",
backgroundSize: "24px 24px",
maskImage:
"radial-gradient(ellipse 100% 100% at 50% 50%, black 30%, transparent 50%)",
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Toaster } from "@/components/ui/sonner";
import type { Meta, StoryObj } from "@storybook/react";
import { mobileViewport } from "../../../../../stories/utils";
import { JoinTeamPageUI } from "./JoinTeamPage";

const meta = {
title: "Team/Join Team",
component: Story,
parameters: {
nextjs: {
appDirectory: true,
},
},
} satisfies Meta<typeof Story>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Desktop: Story = {
args: {},
};

export const Mobile: Story = {
args: {},
parameters: {
viewport: mobileViewport("iphone14"),
},
};

function Story() {
return (
<div>
<JoinTeamPageUI
teamName="XYZ Inc"
invite={async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
}}
/>
<Toaster richColors />
</div>
);
}
Loading
Loading