Skip to content

Commit

Permalink
feat(ui): setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin9 committed Mar 10, 2024
1 parent c0343a0 commit 4d387b2
Show file tree
Hide file tree
Showing 33 changed files with 3,419 additions and 16 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{
"directory": "./services/api",
"!cwd": false
},
{
"directory": "./services/ui",
"!cwd": false
}
],
"yaml.customTags": [
Expand All @@ -31,5 +35,6 @@
"!Ref scalar",
],
"go.testTimeout": "10m",
"go.testFlags": ["-count=1"]
"go.testFlags": ["-count=1"],
"less.lint.unknownAtRules": "ignore"
}
10 changes: 9 additions & 1 deletion services/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {GithubService} from 'src/github/github.service';
import {UserService} from 'src/user/user.service';
import {AuthService} from './auth.service';
import {PublicRoute} from 'src/shared/public-route';
import {JWTUser} from './jwt.decorator';
import {User} from 'src/user/user.entity';

@Controller('auth')
export class AuthController {
Expand All @@ -25,9 +27,15 @@ export class AuthController {
@Get('login')
async login() {}

@Get('info')
@PublicRoute()
authUserInfo(@JWTUser() user: User) {
return user;
}

@Get('callback')
@PublicRoute()
async callback(@Query('code') code) {
async callback(@Query('code') code: string) {
if (code) {
const accessToken = await this.githubService.getGithubAccessToken(code);
const user = await this.githubService.getUserFromAccessToken(accessToken);
Expand Down
4 changes: 4 additions & 0 deletions services/api/src/auth/jwt.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const JWTUser = createParamDecorator(

const user = new User();

if (!jwtExtract) {
return user;
}

user.id = jwtExtract.id;
user.email = jwtExtract.email;
user.username = jwtExtract.username;
Expand Down
14 changes: 0 additions & 14 deletions services/api/src/container-image/container-image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ export class ContainerImageController {
@JWTUser() user: User,
@Body() containerImage: ContainerImageDto,
) {
const isPullRequestActive =
await this.containerImageService.isPullRequestActive(
containerImage.githubRepoName,
containerImage.pullRequestNumber,
user,
);

if (isPullRequestActive) {
throw new HttpException(
`${containerImage.githubRepoName}/${containerImage.pullRequestNumber} has already attached container image`,
HttpStatus.CONFLICT,
);
}

const containerConfig = await this.containerConfigService.getConfigById(
user,
containerImage?.containerConfigurationId,
Expand Down
23 changes: 23 additions & 0 deletions services/ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
'plugin:prettier/recommended'
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
"@tanstack/query/exhaustive-deps": "error",
"@tanstack/query/no-rest-destructuring": "warn",
"@tanstack/query/stable-query-client": "error"
},
}
24 changes: 24 additions & 0 deletions services/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
5 changes: 5 additions & 0 deletions services/ui/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false
}
30 changes: 30 additions & 0 deletions services/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions services/ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/dophermal-logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dophermal</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/app.tsx"></script>
</body>
</html>
44 changes: 44 additions & 0 deletions services/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "ui",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@lukemorales/query-key-factory": "^1.3.4",
"@tanstack/react-query": "^5.25.0",
"@tanstack/react-router": "^1.19.4",
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zustand": "^4.5.2"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.20.1",
"@tanstack/router-devtools": "^1.19.4",
"@tanstack/router-vite-plugin": "^1.19.6",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.18",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"less": "^4.2.0",
"postcss": "^8.4.35",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.1.4",
"vite-tsconfig-paths": "^4.3.1"
}
}
Loading

0 comments on commit 4d387b2

Please sign in to comment.