Skip to content

Commit

Permalink
Clarify presentation
Browse files Browse the repository at this point in the history
- There is no login or signup mechanism.
- Signup button adds new author
- This commit simply renames UI text to reflect that more clearly
  • Loading branch information
mayank1513 committed Jul 21, 2023
1 parent ac01f3b commit 54f510d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
31 changes: 14 additions & 17 deletions typescript/rest-nextjs-api-routes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ npx prisma migrate dev --name init

When `npx prisma migrate dev` is executed against a newly created database, seeding is also triggered. The seed file in [`prisma/seed.ts`](./prisma/seed.ts) will be executed and your database will be populated with the sample data.


### 3. Start the app

```
Expand All @@ -63,7 +62,7 @@ The app is now running, navigate to [`http://localhost:3000/`](http://localhost:

![](https://imgur.com/eepbOUO.png)

**Signup** (located in [`./pages/signup.tsx`](./pages/signup.tsx))
**Add Author** (located in [`./pages/add-author.tsx`](./pages/add-author.tsx))

![](https://imgur.com/iE6OaBI.png)

Expand Down Expand Up @@ -137,8 +136,8 @@ model Post {
}

model User {
id Int @default(autoincrement()) @id
name String?
id Int @default(autoincrement()) @id
name String?
email String @unique
posts Post[]
+ profile Profile?
Expand Down Expand Up @@ -167,56 +166,54 @@ You can now use your `PrismaClient` instance to perform operations against the n
```ts
const profile = await prisma.profile.create({
data: {
bio: "Hello World",
bio: 'Hello World',
user: {
connect: { email: "[email protected]" },
connect: { email: '[email protected]' },
},
},
});
})
```

#### Create a new user with a new profile

```ts
const user = await prisma.user.create({
data: {
email: "[email protected]",
name: "John",
email: '[email protected]',
name: 'John',
profile: {
create: {
bio: "Hello World",
bio: 'Hello World',
},
},
},
});
})
```

#### Update the profile of an existing user

```ts
const userWithUpdatedProfile = await prisma.user.update({
where: { email: "[email protected]" },
where: { email: '[email protected]' },
data: {
profile: {
update: {
bio: "Hello Friends",
bio: 'Hello Friends',
},
},
},
});
})
```


### 3. Build new UI features in React

Once you have added a new endpoint to the API (e.g. `/api/profile` with `/POST`, `/PUT` and `GET` operations), you can start building a new UI component in React. It could e.g. be called `profile.tsx` and would be located in the `pages` directory.

In the application code, you can access the new endpoint via `fetch` operations and populate the UI with the data you receive from the API calls.


## Switch to another database (e.g. PostgreSQL, MySQL, SQL Server, MongoDB)

If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block.
If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block.

Learn more about the different connection configurations in the [docs](https://www.prisma.io/docs/reference/database-reference/connection-urls).

Expand Down
4 changes: 2 additions & 2 deletions typescript/rest-nextjs-api-routes/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default function Header() {
</Link>
</div>
<div className={styles.right}>
<Link href="/signup" legacyBehavior>
<a data-active={isActive('/signup')}>Signup</a>
<Link href="/add-author" legacyBehavior>
<a data-active={isActive('/add-author')}>Add Author</a>
</Link>
<Link href="/create" legacyBehavior>
<a data-active={isActive('/create')}>+ Create draft</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react'
import Router from 'next/router'
import styles from '@/styles/SignUp.module.css'
import styles from '@/styles/AddAuthor.module.css'

export default function SignUp() {
export default function AddAuthor() {
const [name, setName] = useState('')
const [email, setEmail] = useState('')

Expand All @@ -24,7 +24,7 @@ export default function SignUp() {
return (
<div className={styles.page}>
<form onSubmit={submitData}>
<h1>Signup user</h1>
<h1>Add Author</h1>
<input
autoFocus
onChange={(e) => setName(e.target.value)}
Expand All @@ -38,7 +38,7 @@ export default function SignUp() {
type="text"
value={email}
/>
<input disabled={!name || !email} type="submit" value="Signup" />
<input disabled={!name || !email} type="submit" value="Add Author" />
<a className={styles.black} href="#" onClick={() => Router.push('/')}>
or Cancel
</a>
Expand Down
1 change: 1 addition & 0 deletions typescript/rest-nextjs-api-routes/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ input[type='submit'] {
background: #ececec;
border: 0;
padding: 1rem 2rem;
margin: 0.5rem;
}

nav {
Expand Down

0 comments on commit 54f510d

Please sign in to comment.