Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration : Frontend #77

Merged
merged 8 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ broker
migrations/
dist/
.idea
sample.env
10 changes: 10 additions & 0 deletions apps/frontend-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
12 changes: 12 additions & 0 deletions apps/frontend-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": false,
"video": true,
"videosFolder": "../../dist/cypress/apps/frontend-e2e/videos",
"screenshotsFolder": "../../dist/cypress/apps/frontend-e2e/screenshots",
"chromeWebSecurity": false
}
28 changes: 28 additions & 0 deletions apps/frontend-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "..\\..\\node_modules\\nx\\schemas\\project-schema.json",
"sourceRoot": "apps/frontend-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/frontend-e2e/cypress.json",
"devServerTarget": "frontend:serve:development"
},
"configurations": {
"production": {
"devServerTarget": "frontend:serve:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/frontend-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["frontend"]
}
4 changes: 4 additions & 0 deletions apps/frontend-e2e/src/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}
13 changes: 13 additions & 0 deletions apps/frontend-e2e/src/integration/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getGreeting } from "../support/app.po";

describe("frontend", () => {
beforeEach(() => cy.visit("/"));

it("should display welcome message", () => {
// Custom command example, see `../support/commands.ts` file
cy.login("[email protected]", "myPassword");

// Function helper example, see `../support/app.po.ts` file
getGreeting().contains("Welcome frontend");
});
});
1 change: 1 addition & 0 deletions apps/frontend-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get("h1");
33 changes: 33 additions & 0 deletions apps/frontend-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add("login", (email, password) => {
console.log("Custom command example: Login", email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/frontend-e2e/src/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";
10 changes: 10 additions & 0 deletions apps/frontend-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js"]
}
11 changes: 11 additions & 0 deletions apps/frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
16 changes: 16 additions & 0 deletions apps/frontend/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is used by:
# 1. autoprefixer to adjust CSS to support the below specified browsers
# 2. babel preset-env to adjust included polyfills
#
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# If you need to support different browsers in production, you may tweak the list below.

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major version
last 2 iOS major versions
Firefox ESR
not IE 9-11 # For IE 9-11 support, remove 'not'.
23 changes: 23 additions & 0 deletions apps/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"import/resolver": {
"node": {
"paths": ["src"]
}
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions apps/frontend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: "frontend",
preset: "../../jest.preset.js",
transform: {
"^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "@nrwl/react/plugins/jest",
"^.+\\.[tj]sx?$": "babel-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/apps/frontend",
};
80 changes: 80 additions & 0 deletions apps/frontend/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"$schema": "..\\..\\node_modules\\nx\\schemas\\project-schema.json",
"sourceRoot": "apps/frontend/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/web:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
"outputPath": "dist/apps/frontend",
"index": "apps/frontend/src/index.html",
"baseHref": "/",
"main": "apps/frontend/src/main.tsx",
"polyfills": "apps/frontend/src/polyfills.ts",
"tsConfig": "apps/frontend/tsconfig.app.json",
"assets": ["apps/frontend/src/favicon.ico", "apps/frontend/src/assets"],
"styles": ["apps/frontend/src/styles.css"],
"scripts": [],
"webpackConfig": "@nrwl/react/plugins/webpack"
},
"configurations": {
"development": {
"extractLicenses": false,
"optimization": false,
"sourceMap": true,
"vendorChunk": true
},
"production": {
"fileReplacements": [
{
"replace": "apps/frontend/src/environments/environment.ts",
"with": "apps/frontend/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false
}
}
},
"serve": {
"executor": "@nrwl/web:dev-server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "frontend:build",
"hmr": true
},
"configurations": {
"development": {
"buildTarget": "frontend:build:development"
},
"production": {
"buildTarget": "frontend:build:production",
"hmr": false
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/frontend/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/frontend"],
"options": {
"jestConfig": "apps/frontend/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
78 changes: 78 additions & 0 deletions apps/frontend/src/app/apis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import routes from "app/constants/Routes";
const getSignUpReqBody = (user) => {
return {
registration: {
applicationId: `${process.env.REACT_APP_APPLICATION_ID}`,
},
user: { name: user.name, email: user.email, password: user.password },
};
};
const getSignInReqBody = (email, password) => {
return {
loginId: email,
password: password,
applicationId: `${process.env.REACT_APP_APPLICATION_ID}`,
};
};

const getResponse = async (url, reqBody) => {
const result = await fetch(url, {
method: "POST",
credentials: "omit",
headers: {
Authorization: `${process.env.REACT_APP_AUTH_TOKEN}`,
"Content-Type": "application/json",
},

body: JSON.stringify(reqBody),
});
return await result.json();
};

const Login = async (email, password, history) => {
const reqBody = getSignInReqBody(email, password);
console.log(reqBody);
try {
const result = await getResponse(routes.AUTH_BASE_URL + "/login", reqBody);
localStorage.setItem("user-info", JSON.stringify(result));
history.push("/dashboard");
console.log("Result");
} catch (e) {
console.log(e);
}
};

const SignUp = async (user, history) => {
const reqBody = getSignUpReqBody(user);
try {
const result = await getResponse(
routes.AUTH_BASE_URL + "/user/registration",
reqBody
);
localStorage.setItem("user-info", JSON.stringify(result));
history.push("/dashboard");
} catch (e) {
console.log(e);
}
};

// async function signUp() {
// const reqBody = apiUtil.getSignUpReqBody({
// name: name,
// email: email,
// password: password,
// });
// console.log(reqBody);
// try {
// const result = await apiUtil.getResponse(
// apiUtil.baseUrl + "/user/registration",
// reqBody
// );
// console.log(result);
// localStorage.setItem("user-info", JSON.stringify(result));
// history.push("/dashboard");
// } catch (e) {
// console.log(e);
// }
// }
export { getSignUpReqBody, getSignInReqBody, getResponse, Login, SignUp };
18 changes: 18 additions & 0 deletions apps/frontend/src/app/app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Routes, Route } from "react-router-dom";
import SignIn from "app/pages/Auth/SignIn";
import SignUp from "app/pages/Auth/SignUp";
import Main from "app/components/Main";
import routes from "app/constants/Routes";
function App() {
return (
<div className="App">
<Routes>
<Route path={`${routes.SIGN_UP}`} element={<SignUp />} />
<Route path={`${routes.SIGN_IN}`} element={<SignIn />} />
<Route path="/*" element={<Main />}></Route>
</Routes>
</div>
);
}

export default App;
Loading