Skip to content

Commit d4f9e7d

Browse files
committed
configure the front end to be able to send requests to the backend
Coauthors: James, Ben, Eric, Wilton
1 parent 9a431f3 commit d4f9e7d

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

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(): JSX.Element {
11+
const [name, setName] = useState('');
12+
const [email, setEmail] = useState('');
13+
14+
const handleSubmit = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
15+
e.preventDefault();
16+
// grab the information of name and email
17+
// bundle those together to be an object to be sent to backend
18+
const { mutate } = trpc.user.createUser.useMutation();
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/user.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ export const userRouter = router({
66
createUser: publicProcedure
77
.input(z.object({
88
name: z.string(),
9-
email: z.string().email()})
9+
email: z.string().email()}),
10+
1011
) // name and email
11-
.mutation(({ input, ctx }) => {
12+
.mutation(async ({ input, ctx }) => {
1213
// we want to add to our database with the name, email, admin defaulted to false as column values
13-
return ctx.prisma.user.create({
14+
return await ctx.prisma.user.create({
1415
data: {
1516
name: input.name,
1617
email: input.email,
1718
}
1819
})
19-
}),
20+
})
2021
});
2122

2223

0 commit comments

Comments
 (0)