wizeline / project-lab

Proposal Hunt / Project Lab experimental repo
MIT License
5 stars 0 forks source link

Blitz.js

This is a Blitz.js app.

proposalHunt

Requirements

First you should install postgres on your computer. For MacOS an easy method is to use Postgres.app. If you have an M1 chip, the lastest version has support for it without Rossetta. As documented in their page, you can add postgresql tools to your path using:

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

After that you can create a DB using this commands on the terminal:

createdb projectlab
createdb projectlab_test

For Windows you can install postgres from here and you can follow this easy setup (it also works for MacOS)

Then open the SQL Shell and write this commands for creating a DB:

CREATE DATABASE projectlab;
CREATE DATABASE projectlab_test;

Getting Started

Environment Variables

  1. In root, create .env.local file with the following:
DATABASE_URL=postgresql://[username]@localhost:5432/projectlab
AUTH0_CLIENT_ID=
AUTH0_DOMAIN=
AUTH0_CLIENT_SECRET=

## Optional, for WizelineOS sync-* commands
WOS_AUTH_API_URL=
WOS_AUTH_API_AUDIENCE=
WOS_AUTH_API_CLIENT_ID=
WOS_AUTH_API_CLIENT_SECRET=
WOS_API_URL=
  1. In root, create .env.test.local file with the following:
DATABASE_URL=postgresql://[username]@localhost:5432/projectlab_test

If you are using Windows, you should use this format in both files for the DATABASE_URL:

DATABASE_URL=postgresql://[username]:[password]@localhost:5432/[database]?schema=public
  1. Ask in #team-projectlab channel on Slack for the environment values for .env.local and .env.test.local.

  2. Edit db/seeds.ts file and add your user at the very bottom, make sure to replace with your data:

  await db.profiles.upsert({
    where: { email: "[YOUR_USERNAME]@wizeline.com" },
    update: {},
    create: {
      email: "[YOUR_USERNAME]@wizeline.com",
      firstName: "[YOUR_FIRNAME]",
      lastName: "[YOUR_LASTNAME]",
      department: "[YOUR_DEPARTMENT]",
    },
  })
  1. (Only dev environment) Set the project's node version with NVM. If you don't have NVM installed read the documentation:
nvm use
  1. Install dependencies:
yarn install
  1. Create or reset the database schema:
npx blitz prisma migrate reset
  1. Sync profiles and skills from Wizeline OS, this is optional and it takes a couple of minutes, the seeding contains sample data that can be enough to run locally:
yarn sync-all-from-wos
  1. Populate with test data:
npx blitz db seed
  1. Run blitz:
npx blitz dev

Finally, open http://localhost:3000 in a browser to see the result.


Tests

Runs your tests using Jest. The used database will be the defined in .env.test.local otherwise .env will be used.

yarn test

Blitz comes with a test setup using Jest and react-testing-library.

Update BlitzJS

BlitzJS is updated constantly so in order to get the latest features we need to mantain the package in its LTS version. These are the steps to upgarde BlitzJS in the project:

  1. Update the global BlitzJS package through yarn:
yarn global add blitz
  1. Navigate to the parent directory of the project, for example if the project is located at ~/dev/projects/project-lab you have to navigate to ~/dev/projects.

  2. Once you are located in the parent directory, run the following command:

blitz new project-lab
  1. A prompt will be launched with a series of options, you should skip the generation of the following files:

    • Database generation
    • package.json
    • Authentication
    • README.md
  2. Finally, follow the Getting started instructions from step 5 to make sure everything is working.

Impersonate Users

Admin users are allowed to impersonate other other in the App.

Prerequisites

  1. The User must be an admin user.
  2. The User you want to impersonate must exist in the Usertable.

Steps

  1. Go to the /impersonate path to access the impersonate page. There is no button for this path so you must type it manually.
  2. Type the user email you want to impersonate and click on 'Switch to User'.
  3. Click on 'GO HOME' and that's it! You are now impersonating this User.

To Stop impersonating, go to the /impersonate path and click on 'STOP IMPERSONATING', you will stop the impersonating, and it's done!

Commands

Blitz comes with a powerful CLI that is designed to make development easy and fast. You can install it with npm i -g blitz

  blitz [COMMAND]

  dev       Start a development server
  build     Create a production build
  start     Start a production server
  export    Export your Blitz app as a static application
  prisma    Run prisma commands
  generate  Generate new files for your Blitz project
  console   Run the Blitz console REPL
  install   Install a recipe
  help      Display help for blitz
  test      Run project tests

You can read more about it on the CLI Overview documentation.

What's included?

Here is the starting structure of your app.

proposalHunt
├── app/
│   ├── api/
│   ├── auth/
│   │   ├── components/
│   │   │   ├── LoginForm.tsx
│   │   │   └── SignupForm.tsx
│   │   ├── mutations/
│   │   │   ├── changePassword.ts
│   │   │   ├── forgotPassword.test.ts
│   │   │   ├── forgotPassword.ts
│   │   │   ├── login.ts
│   │   │   ├── logout.ts
│   │   │   ├── resetPassword.test.ts
│   │   │   ├── resetPassword.ts
│   │   │   └── signup.ts
│   │   ├── pages/
│   │   │   ├── forgot-password.tsx
│   │   │   ├── login.tsx
│   │   │   ├── reset-password.tsx
│   │   │   └── signup.tsx
│   │   └── validations.ts
│   ├── core/
│   │   ├── components/
│   │   │   ├── Form.tsx
│   │   │   └── LabeledTextField.tsx
│   │   ├── hooks/
│   │   │   └── useCurrentUser.ts
│   │   └── layouts/
│   │       └── Layout.tsx
│   ├── pages/
│   │   ├── 404.tsx
│   │   ├── _app.tsx
│   │   ├── _document.tsx
│   │   ├── index.test.tsx
│   │   └── index.tsx
│   └── users/
│       └── queries/
│           └── getCurrentUser.ts
├── db/
│   ├── index.ts
│   ├── schema.prisma
│   └── seeds.ts
├── integrations/
├── mailers/
│   └── forgotPasswordMailer.ts
├── public/
│   ├── favicon.ico*
│   └── logo.png
├── test/
│   ├── setup.ts
│   └── utils.tsx
├── README.md
├── babel.config.js
├── blitz.config.js
├── jest.config.js
├── package.json
├── tsconfig.json
├── types.d.ts
├── types.ts
└── yarn.lock

These files are:

You can read more about it in the File Structure section of the documentation.

Tools included

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.

Learn more

Read the Blitz.js Documentation to learn more.

The Blitz community is warm, safe, diverse, inclusive, and fun! Feel free to reach out to us in any of our communication channels.