Skip to content

Commit abb74e7

Browse files
committed
basic members table
1 parent 69a7969 commit abb74e7

File tree

17 files changed

+615
-17
lines changed

17 files changed

+615
-17
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SITE_URL="https://getdocbase.com"
1+
SITE_URL="https://getrebase.com"

.env.example

Lines changed: 0 additions & 3 deletions
This file was deleted.

.env.local.example

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ yarn-error.log*
2626

2727
# local env files
2828
.env*.local
29+
.env
2930

3031
# vercel
3132
.vercel

app/favicon.ico

-10.3 KB
Binary file not shown.

app/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { siteConfig } from "@/config/site";
88

99
export const metadata: Metadata = {
1010
title: {
11-
default: "Project Name",
12-
template: "%s | Project Name",
11+
default: siteConfig.name,
12+
template: `%s | ${siteConfig.name}`,
1313
},
14-
description: "Project description",
14+
description: siteConfig.description,
1515
themeColor: [
1616
{ media: "(prefers-color-scheme: light)", color: "white" },
1717
{ media: "(prefers-color-scheme: dark)", color: "black" },

app/mailbox/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Mailbox() {
2+
return <div>Mailbox</div>;
3+
}

app/members/page.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import MemberForm from "@/components/member-form";
2+
import { MembersTable } from "@/components/members-table";
3+
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
4+
import { cookies } from "next/headers";
5+
import { redirect } from "next/navigation";
6+
7+
export default async function Members() {
8+
const supabase = createServerComponentClient({ cookies });
9+
const {
10+
data: { user },
11+
} = await supabase.auth.getUser();
12+
13+
if (!user) {
14+
redirect("/");
15+
}
16+
17+
const {
18+
data: members,
19+
error,
20+
status,
21+
} = await supabase.from("members").select("*").eq("created_by", user.id);
22+
23+
console.log(members);
24+
25+
return (
26+
<div>
27+
<MemberForm user={user} />
28+
<MembersTable members={members} />
29+
</div>
30+
);
31+
}

app/opengraph-image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default async function handler() {
1616
alignItems: "center",
1717
}}
1818
>
19-
Project Name 🤗
19+
Re:base 📧
2020
</div>
2121
),
2222
{

components/member-form.tsx

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"use client";
2+
3+
import { zodResolver } from "@hookform/resolvers/zod";
4+
import { useForm } from "react-hook-form";
5+
import * as z from "zod";
6+
import {
7+
Dialog,
8+
DialogContent,
9+
DialogDescription,
10+
DialogFooter,
11+
DialogHeader,
12+
DialogTitle,
13+
DialogTrigger,
14+
} from "@/components/ui/dialog";
15+
import { Label } from "@/components/ui/label";
16+
import { Button } from "@/components/ui/button";
17+
import {
18+
Form,
19+
FormControl,
20+
FormField,
21+
FormItem,
22+
FormLabel,
23+
} from "@/components/ui/form";
24+
import { Input } from "@/components/ui/input";
25+
import { toast } from "@/components/ui/use-toast";
26+
import { createClientComponentClient } from "@supabase/auth-helpers-nextjs";
27+
28+
const memberFormSchema = z.object({
29+
email: z.string().optional(),
30+
first_name: z.string().optional(),
31+
last_name: z.string().optional(),
32+
});
33+
34+
type MemberFormValues = z.infer<typeof memberFormSchema>;
35+
36+
export default function MemberForm({ user }: { user: any }) {
37+
const supabase = createClientComponentClient();
38+
const form = useForm<MemberFormValues>({
39+
resolver: zodResolver(memberFormSchema),
40+
defaultValues: {
41+
email: "",
42+
first_name: "",
43+
last_name: "",
44+
},
45+
});
46+
47+
async function onSubmit(data: MemberFormValues) {
48+
try {
49+
const updates = {
50+
email: data.email,
51+
first_name: data.first_name,
52+
last_name: data.last_name,
53+
created_by: user?.id,
54+
};
55+
56+
let { error } = await supabase.from("members").insert(updates);
57+
if (error) throw error;
58+
toast({
59+
description: "Your member has been added",
60+
});
61+
} catch (error) {
62+
console.log(error);
63+
}
64+
}
65+
66+
return (
67+
<div>
68+
<div className="grid gap-4 py-4">
69+
<Form {...form}>
70+
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
71+
<Dialog>
72+
<DialogTrigger asChild>
73+
<Button variant="outline">Add Member</Button>
74+
</DialogTrigger>
75+
<DialogContent className="sm:max-w-[425px]">
76+
<DialogHeader>
77+
<DialogTitle>New Member</DialogTitle>
78+
<DialogDescription>
79+
Please enter the first name, last name, and email
80+
</DialogDescription>
81+
</DialogHeader>{" "}
82+
<FormField
83+
control={form.control}
84+
name="email"
85+
render={({ field }) => (
86+
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
87+
<div className="space-y-0.5">
88+
<FormLabel className="text-base mx-2">Email</FormLabel>
89+
</div>
90+
<FormControl>
91+
<Input {...field} />
92+
</FormControl>
93+
</FormItem>
94+
)}
95+
/>
96+
<FormField
97+
control={form.control}
98+
name="first_name"
99+
render={({ field }) => (
100+
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
101+
<div className="space-y-0.5">
102+
<FormLabel className="text-base mx-2">
103+
First Name
104+
</FormLabel>
105+
</div>
106+
<FormControl>
107+
<Input {...field} />
108+
</FormControl>
109+
</FormItem>
110+
)}
111+
/>
112+
<FormField
113+
control={form.control}
114+
name="last_name"
115+
render={({ field }) => (
116+
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
117+
<div className="space-y-0.5">
118+
<FormLabel className="text-base mx-2">
119+
Last Name
120+
</FormLabel>
121+
</div>
122+
<FormControl>
123+
<Input {...field} />
124+
</FormControl>
125+
</FormItem>
126+
)}
127+
/>
128+
<div className="py-1 flex justify-center">
129+
<Button
130+
type="submit"
131+
className="bg-[#9FACE6] text-white font-bold py-2 px-4 rounded w-full"
132+
>
133+
Add
134+
</Button>
135+
</div>
136+
</DialogContent>
137+
</Dialog>
138+
</form>
139+
</Form>
140+
</div>
141+
</div>
142+
);
143+
}

0 commit comments

Comments
 (0)