Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit cd5c192

Browse files
committed
Brand new Blitz app!
0 parents  commit cd5c192

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1777
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This env file should be checked into source control
2+
# This is the place for default values for all environments
3+
# Values in `.env.local` and `.env.production` will override these values

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["blitz"],
3+
}

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# dependencies
2+
node_modules
3+
.yarn/*
4+
!.yarn/patches
5+
!.yarn/plugins
6+
!.yarn/releases
7+
!.yarn/sdks
8+
!.yarn/versions
9+
.pnp.*
10+
.npm
11+
web_modules/
12+
13+
# blitz
14+
/.blitz/
15+
/.next/
16+
*.sqlite
17+
*.sqlite-journal
18+
.now
19+
.blitz**
20+
blitz-log.log
21+
22+
# misc
23+
.DS_Store
24+
25+
# local env files
26+
.env.local
27+
.env.*.local
28+
.envrc
29+
30+
# Logs
31+
logs
32+
*.log
33+
34+
# Runtime data
35+
pids
36+
*.pid
37+
*.seed
38+
*.pid.lock
39+
40+
# Testing
41+
.coverage
42+
*.lcov
43+
.nyc_output
44+
lib-cov
45+
46+
# Caches
47+
*.tsbuildinfo
48+
.eslintcache
49+
.node_repl_history
50+
.yarn-integrity
51+
52+
# Serverless directories
53+
.serverless/
54+
55+
# Stores VSCode versions used for testing VSCode extensions
56+
.vscode-test

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged
5+
npx pretty-quick --staged

.husky/pre-push

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx tsc
5+
npm run lint
6+
npm run test

.npmrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
save-exact=true
2+
legacy-peer-deps=true
3+
4+
public-hoist-pattern[]=next
5+
public-hoist-pattern[]=secure-password
6+
public-hoist-pattern[]=*jest*
7+
public-hoist-pattern[]=@testing-library/*

.prettierignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gitkeep
2+
.env*
3+
*.ico
4+
*.lock
5+
db/migrations
6+
.next
7+
.blitz
8+
.yarn
9+
.pnp.*
10+
node_modules
11+
.blitz.config.compiled.js

README.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
[![Blitz.js](https://raw.githubusercontent.com/blitz-js/art/master/github-cover-photo.png)](https://blitzjs.com)
2+
3+
This is a [Blitz.js](https://github.com/blitz-js/blitz) app.
4+
5+
# **example-collaboration-app**
6+
7+
## Getting Started
8+
9+
Run your app in the development mode.
10+
11+
```
12+
blitz dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
## Environment Variables
18+
19+
Ensure the `.env.local` file has required environment variables:
20+
21+
```
22+
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/example-collaboration-app
23+
```
24+
25+
Ensure the `.env.test.local` file has required environment variables:
26+
27+
```
28+
DATABASE_URL=postgresql://<YOUR_DB_USERNAME>@localhost:5432/example-collaboration-app_test
29+
```
30+
31+
## Tests
32+
33+
Runs your tests using Jest.
34+
35+
```
36+
yarn test
37+
```
38+
39+
Blitz comes with a test setup using [Jest](https://jestjs.io/) and [react-testing-library](https://testing-library.com/).
40+
41+
## Commands
42+
43+
Blitz comes with a powerful CLI that is designed to make development easy and fast. You can install it with `npm i -g blitz`
44+
45+
```
46+
blitz [COMMAND]
47+
48+
dev Start a development server
49+
build Create a production build
50+
start Start a production server
51+
export Export your Blitz app as a static application
52+
prisma Run prisma commands
53+
generate Generate new files for your Blitz project
54+
console Run the Blitz console REPL
55+
install Install a recipe
56+
help Display help for blitz
57+
test Run project tests
58+
```
59+
60+
You can read more about it on the [CLI Overview](https://blitzjs.com/docs/cli-overview) documentation.
61+
62+
## What's included?
63+
64+
Here is the starting structure of your app.
65+
66+
```
67+
example-collaboration-app
68+
├── app/
69+
│ ├── api/
70+
│ ├── auth/
71+
│ │ ├── components/
72+
│ │ │ ├── LoginForm.tsx
73+
│ │ │ └── SignupForm.tsx
74+
│ │ ├── mutations/
75+
│ │ │ ├── changePassword.ts
76+
│ │ │ ├── forgotPassword.test.ts
77+
│ │ │ ├── forgotPassword.ts
78+
│ │ │ ├── login.ts
79+
│ │ │ ├── logout.ts
80+
│ │ │ ├── resetPassword.test.ts
81+
│ │ │ ├── resetPassword.ts
82+
│ │ │ └── signup.ts
83+
│ │ ├── pages/
84+
│ │ │ ├── forgot-password.tsx
85+
│ │ │ ├── login.tsx
86+
│ │ │ ├── reset-password.tsx
87+
│ │ │ └── signup.tsx
88+
│ │ └── validations.ts
89+
│ ├── core/
90+
│ │ ├── components/
91+
│ │ │ ├── Form.tsx
92+
│ │ │ └── LabeledTextField.tsx
93+
│ │ ├── hooks/
94+
│ │ │ └── useCurrentUser.ts
95+
│ │ └── layouts/
96+
│ │ └── Layout.tsx
97+
│ ├── pages/
98+
│ │ ├── _app.tsx
99+
│ │ ├── _document.tsx
100+
│ │ ├── 404.tsx
101+
│ │ ├── index.test.tsx
102+
│ │ └── index.tsx
103+
│ └── users/
104+
│ └── queries/
105+
│ └── getCurrentUser.ts
106+
├── db/
107+
│ ├── migrations/
108+
│ ├── index.ts
109+
│ ├── schema.prisma
110+
│ └── seeds.ts
111+
├── integrations/
112+
├── mailers/
113+
│ └── forgotPasswordMailer.ts
114+
├── public/
115+
│ ├── favicon.ico
116+
│ └── logo.png
117+
├── test/
118+
│ ├── setup.ts
119+
│ └── utils.tsx
120+
├── .eslintrc.js
121+
├── babel.config.js
122+
├── blitz.config.ts
123+
├── jest.config.ts
124+
├── package.json
125+
├── README.md
126+
├── tsconfig.json
127+
└── types.ts
128+
```
129+
130+
These files are:
131+
132+
- The `app/` folder is a container for most of your project. This is where you’ll put any pages or API routes.
133+
134+
- `db/` is where your database configuration goes. If you’re writing models or checking migrations, this is where to go.
135+
136+
- `public/` is a folder where you will put any static assets. If you have images, files, or videos which you want to use in your app, this is where to put them.
137+
138+
- `integrations/` is a folder to put all third-party integrations like with Stripe, Sentry, etc.
139+
140+
- `test/` is a folder where you can put test utilities and integration tests.
141+
142+
- `package.json` contains information about your dependencies and devDependencies. If you’re using a tool like `npm` or `yarn`, you won’t have to worry about this much.
143+
144+
- `tsconfig.json` is our recommended setup for TypeScript.
145+
146+
- `.babel.config.js`, `.eslintrc.js`, `.env`, etc. ("dotfiles") are configuration files for various bits of JavaScript tooling.
147+
148+
- `blitz.config.ts` is for advanced custom configuration of Blitz. [Here you can learn how to use it](https://blitzjs.com/docs/blitz-config).
149+
150+
- `jest.config.js` contains config for Jest tests. You can [customize it if needed](https://jestjs.io/docs/en/configuration).
151+
152+
You can read more about it in the [File Structure](https://blitzjs.com/docs/file-structure) section of the documentation.
153+
154+
### Tools included
155+
156+
Blitz comes with a set of tools that corrects and formats your code, facilitating its future maintenance. You can modify their options and even uninstall them.
157+
158+
- **ESLint**: It lints your code: searches for bad practices and tell you about it. You can customize it via the `.eslintrc.js`, and you can install (or even write) plugins to have it the way you like it. It already comes with the [`blitz`](https://github.com/blitz-js/blitz/tree/canary/packages/eslint-config) config, but you can remove it safely. [Learn More](https://blitzjs.com/docs/eslint-config).
159+
- **Husky**: It adds [githooks](https://git-scm.com/docs/githooks), little pieces of code that get executed when certain Git events are triggerd. For example, `pre-commit` is triggered just before a commit is created. You can see the current hooks inside `.husky/`. If are having problems commiting and pushing, check out ther [troubleshooting](https://typicode.github.io/husky/#/?id=troubleshoot) guide. [Learn More](https://blitzjs.com/docs/husky-config).
160+
- **Prettier**: It formats your code to look the same everywhere. You can configure it via the `.prettierrc` file. The `.prettierignore` contains the files that should be ignored by Prettier; useful when you have large files or when you want to keep a custom formatting. [Learn More](https://blitzjs.com/docs/prettier-config).
161+
162+
## Learn more
163+
164+
Read the [Blitz.js Documentation](https://blitzjs.com/docs/getting-started) to learn more.
165+
166+
The Blitz community is warm, safe, diverse, inclusive, and fun! Feel free to reach out to us in any of our communication channels.
167+
168+
- [Website](https://blitzjs.com)
169+
- [Discord](https://blitzjs.com/discord)
170+
- [Report an issue](https://github.com/blitz-js/blitz/issues/new/choose)
171+
- [Forum discussions](https://github.com/blitz-js/blitz/discussions)
172+
- [How to Contribute](https://blitzjs.com/docs/contributing)
173+
- [Sponsor or donate](https://github.com/blitz-js/blitz#sponsors-and-donations)

app/api/.keep

Whitespace-only changes.

app/auth/components/LoginForm.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { AuthenticationError, Link, useMutation, Routes, PromiseReturnType } from "blitz"
2+
import { LabeledTextField } from "app/core/components/LabeledTextField"
3+
import { Form, FORM_ERROR } from "app/core/components/Form"
4+
import login from "app/auth/mutations/login"
5+
import { Login } from "app/auth/validations"
6+
7+
type LoginFormProps = {
8+
onSuccess?: (user: PromiseReturnType<typeof login>) => void
9+
}
10+
11+
export const LoginForm = (props: LoginFormProps) => {
12+
const [loginMutation] = useMutation(login)
13+
14+
return (
15+
<div>
16+
<h1>Login</h1>
17+
18+
<Form
19+
submitText="Login"
20+
schema={Login}
21+
initialValues={{ email: "", password: "" }}
22+
onSubmit={async (values) => {
23+
try {
24+
const user = await loginMutation(values)
25+
props.onSuccess?.(user)
26+
} catch (error: any) {
27+
if (error instanceof AuthenticationError) {
28+
return { [FORM_ERROR]: "Sorry, those credentials are invalid" }
29+
} else {
30+
return {
31+
[FORM_ERROR]:
32+
"Sorry, we had an unexpected error. Please try again. - " + error.toString(),
33+
}
34+
}
35+
}
36+
}}
37+
>
38+
<LabeledTextField name="email" label="Email" placeholder="Email" />
39+
<LabeledTextField name="password" label="Password" placeholder="Password" type="password" />
40+
<div>
41+
<Link href={Routes.ForgotPasswordPage()}>
42+
<a>Forgot your password?</a>
43+
</Link>
44+
</div>
45+
</Form>
46+
47+
<div style={{ marginTop: "1rem" }}>
48+
Or <Link href={Routes.SignupPage()}>Sign Up</Link>
49+
</div>
50+
</div>
51+
)
52+
}
53+
54+
export default LoginForm

app/auth/components/SignupForm.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useMutation } from "blitz"
2+
import { LabeledTextField } from "app/core/components/LabeledTextField"
3+
import { Form, FORM_ERROR } from "app/core/components/Form"
4+
import signup from "app/auth/mutations/signup"
5+
import { Signup } from "app/auth/validations"
6+
7+
type SignupFormProps = {
8+
onSuccess?: () => void
9+
}
10+
11+
export const SignupForm = (props: SignupFormProps) => {
12+
const [signupMutation] = useMutation(signup)
13+
14+
return (
15+
<div>
16+
<h1>Create an Account</h1>
17+
18+
<Form
19+
submitText="Create Account"
20+
schema={Signup}
21+
initialValues={{ email: "", password: "" }}
22+
onSubmit={async (values) => {
23+
try {
24+
await signupMutation(values)
25+
props.onSuccess?.()
26+
} catch (error: any) {
27+
if (error.code === "P2002" && error.meta?.target?.includes("email")) {
28+
// This error comes from Prisma
29+
return { email: "This email is already being used" }
30+
} else {
31+
return { [FORM_ERROR]: error.toString() }
32+
}
33+
}
34+
}}
35+
>
36+
<LabeledTextField name="email" label="Email" placeholder="Email" />
37+
<LabeledTextField name="password" label="Password" placeholder="Password" type="password" />
38+
</Form>
39+
</div>
40+
)
41+
}
42+
43+
export default SignupForm

0 commit comments

Comments
 (0)