Skip to content

Commit 6cb86ac

Browse files
authored
Merge pull request #18 from oslabs-beta/group/Newsletter
Group/newsletter
2 parents 3527ae8 + ea1a529 commit 6cb86ac

File tree

8 files changed

+83
-24
lines changed

8 files changed

+83
-24
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"name" TEXT NOT NULL,
5+
"email" TEXT NOT NULL,
6+
"admin" BOOLEAN NOT NULL DEFAULT false,
7+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
"updatedAt" DATETIME NOT NULL
9+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "sqlite"

www/prisma/schema.prisma

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13-
model Example {
14-
id String @id @default(cuid())
13+
model User {
14+
id String @id @default(cuid())
15+
name String
16+
email String
17+
admin Boolean @default(false)
1518
createdAt DateTime @default(now())
1619
updatedAt DateTime @updatedAt
1720
}

www/src/pages/components/LandingPage.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@ import TeamSection from '../components/TeamSection';
44
import FeaturesSection from '../components/FeaturesSection';
55
import Image from 'next/image';
66
import Blogs from './Blogs';
7+
import { useState } from 'react';
8+
import { trpc } from '../../utils/trpc';
9+
10+
export default function LandingPage() {
11+
const [name, setName] = useState('');
12+
const [email, setEmail] = useState('');
13+
const { mutate } = trpc.user.createUser.useMutation();
14+
15+
const handleSubmit = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
16+
e.preventDefault();
17+
// grab the information of name and email
18+
// bundle those together to be an object to be sent to backend
19+
mutate({name, email});
20+
}
721

8-
export default function LandingPage():any {
922
return (
23+
<>
1024
<div className="bg-gray-50">
1125
<main>
1226
{/* Hero section */}
@@ -42,6 +56,18 @@ export default function LandingPage():any {
4256
</div>
4357
<form action="#" className="mt-12 sm:flex sm:w-full sm:max-w-lg">
4458
<div className="min-w-0 flex-1">
59+
<label htmlFor="name" className="sr-only">
60+
Name
61+
</label>
62+
<input
63+
id="name"
64+
type="text"
65+
className="block w-full rounded-md border border-gray-300 px-5 mb-2 py-3 text-base text-gray-900 placeholder-gray-500 shadow-sm focus:border-rose-500 focus:ring-rose-500"
66+
placeholder="Enter your name"
67+
required
68+
value = {name}
69+
onChange ={(e) => {setName(e.target.value)}}
70+
/>
4571
<label htmlFor="hero-email" className="sr-only">
4672
Email address
4773
</label>
@@ -50,12 +76,16 @@ export default function LandingPage():any {
5076
type="email"
5177
className="block w-full rounded-md border border-gray-300 px-5 py-3 text-base text-gray-900 placeholder-gray-500 shadow-sm focus:border-rose-500 focus:ring-rose-500"
5278
placeholder="Enter your email"
79+
required
80+
value = {email}
81+
onChange = {(e) => {setEmail(e.target.value)}}
5382
/>
5483
</div>
5584
<div className="mt-4 sm:mt-0 sm:ml-3">
5685
<button
5786
type="submit"
58-
className="block w-full rounded-md border border-transparent bg-rose-500 px-5 py-3 text-base font-medium text-white shadow hover:bg-rose-600 focus:outline-none focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 sm:px-10"
87+
className="block w-full rounded-md border border-transparent bg-rose-500 mt-8 px-5 py-3 text-base font-medium text-white shadow hover:bg-rose-600 focus:outline-none focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 sm:px-10"
88+
onClick={(e)=> handleSubmit(e)}
5989
>
6090
Notify me
6191
</button>
@@ -130,5 +160,6 @@ export default function LandingPage():any {
130160
</div>
131161
</footer>
132162
</div>
163+
</>
133164
)
134165
}

www/src/pages/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import Blogs from "./components/Blogs";
77
import { trpc } from "../utils/trpc";
88

99
const Home: NextPage = () => {
10-
const hello = trpc.example.hello.useQuery({ text: "from tRPC" });
11-
1210
return (
1311
<>
1412
<NavBar />

www/src/server/trpc/router/_app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { router } from "../trpc";
2-
import { exampleRouter } from "./example";
2+
import { userRouter } from "./user";
33

44
export const appRouter = router({
5-
example: exampleRouter,
5+
user : userRouter,
66
});
77

88
// export type definition of API

www/src/server/trpc/router/example.ts

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

www/src/server/trpc/router/user.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { z } from "zod";
2+
3+
import { router, publicProcedure } from "../trpc";
4+
5+
export const userRouter = router({
6+
createUser: publicProcedure
7+
.input(z.object({
8+
name: z.string(),
9+
email: z.string().email()}),
10+
11+
) // name and email
12+
.mutation(async ({ input, ctx }) => {
13+
// we want to add to our database with the name, email, admin defaulted to false as column values
14+
return await ctx.prisma.user.create({
15+
data: {
16+
name: input.name,
17+
email: input.email,
18+
}
19+
})
20+
})
21+
});
22+
23+
24+
//const greeting = trpc.userRouter.hello({text: ""});
25+
26+
/**
27+
* hello -- name of endpoint api
28+
* .input will be what we are going to be expecting
29+
* .query/.mutation will be what is going to happen once we go to this endpoint api
30+
* (differentiation is that query and mutation should be adjusted for read and CUD functionality)
31+
*/

0 commit comments

Comments
 (0)