Skip to content
Snippets Groups Projects
Commit 67211873 authored by Matthias Feyll's avatar Matthias Feyll :cookie:
Browse files

added rtx query to redux

parent 900aaa63
No related branches found
No related tags found
1 merge request!1005Draft: feature-ui-361_setup-project
Pipeline #201008 passed
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/coverage /coverage
# api # api
/src/api /src/api/**
# production # production
/build /build
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
"start": "vite", "start": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
"test": "react-scripts test", "test": "react-scripts test",
"build::api": "./scripts/build-api.sh", "build::api_old": "./scripts/build-api.sh",
"build::api": "npx @rtk-query/codegen-openapi ./scripts/openapi-config.json",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint::fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix" "lint::fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix"
}, },
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
"proxy": "http://localhost:55055", "proxy": "http://localhost:55055",
"devDependencies": { "devDependencies": {
"@babel/runtime": "^7.21.5", "@babel/runtime": "^7.21.5",
"@rtk-query/codegen-openapi": "^1.2.0",
"@types/react": "^18.2.66", "@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22", "@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/eslint-plugin": "^7.2.0",
......
...@@ -7,4 +7,4 @@ API_PATH=/api/openapiv2 ...@@ -7,4 +7,4 @@ API_PATH=/api/openapiv2
OUTPUT=${PROJECT_NAME}/src/api OUTPUT=${PROJECT_NAME}/src/api
docker run -i --rm \ docker run -i --rm \
-v ${PROJECT_ROOT}:/local openapitools/openapi-generator-cli generate -i /local${API_PATH}/gosdn_northbound.swagger.json -g typescript -o /local/${OUTPUT} -v ${PROJECT_ROOT}:/local openapitools/openapi-generator-cli generate -i /local${API_PATH}/gosdn_northbound.swagger.json -g typescript-redux-query -o /local/${OUTPUT}
\ No newline at end of file \ No newline at end of file
{
"schemaFile": "../../api/openapiv2/gosdn_northbound.swagger.json",
"apiFile": "../src/stores/api.store.ts",
"apiImport": "emptySplitApi",
"outputFile": "../src/api/api.ts",
"exportName": "api",
"hooks": true
}
\ No newline at end of file
{
"$schema": "../node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "4.3.1",
"storageDir": "~/my/custom/storage/dir", // optional
"generators": { // optional
"v2.0": { // any name you like (just printed to the console log or reference it using --generator-key)
"generatorName": "typescript-angular",
"output": "#{cwd}/output/v2.0/#{ext}/#{name}",
"glob": "examples/v2.0/{json,yaml}/*.{json,yaml}",
"additionalProperties": {
"ngVersion": "6.1.7",
"npmName": "restClient",
"supportsES6": "true",
"npmVersion": "6.9.0",
"withInterfaces": true
}
},
"v3.0": { // any name you like (just printed to the console log or reference it using --generator-key)
"generatorName": "typescript-fetch",
"output": "#{cwd}/output/v3.0/#{ext}/#{name}",
"glob": "examples/v3.0/petstore.{json,yaml}"
}
}
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -10,13 +10,12 @@ import { ...@@ -10,13 +10,12 @@ import {
import './index.scss' import './index.scss'
import Landingpage from './pages/landingpage/landingpage' import Landingpage from './pages/landingpage/landingpage'
import LoginPage from './pages/login/login' import LoginPage from './pages/login/login'
import initStore from './stores/api.store'
import './i18n/config' import './i18n/config'
import { I18nextProvider } from 'react-i18next' import { I18nextProvider } from 'react-i18next'
import i18next from 'i18next' import i18next from 'i18next'
import { Provider } from 'react-redux'
initStore() import { store } from './stores'
const root = ReactDOM.createRoot(document.getElementById('root') as Container) const root = ReactDOM.createRoot(document.getElementById('root') as Container)
...@@ -34,8 +33,10 @@ const router = createBrowserRouter( ...@@ -34,8 +33,10 @@ const router = createBrowserRouter(
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<I18nextProvider i18n={i18next}> <Provider store={store}>
<RouterProvider router={router} /> <I18nextProvider i18n={i18next}>
</I18nextProvider> <RouterProvider router={router} />
</I18nextProvider>
</Provider>
</React.StrictMode> </React.StrictMode>
) )
...@@ -2,43 +2,42 @@ import { Button, Col, Container, Form, Image, Row } from 'react-bootstrap' ...@@ -2,43 +2,42 @@ import { Button, Col, Container, Form, Image, Row } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import './login.scss' import './login.scss'
import { AuthServiceApiAuthServiceLoginRequest } from '@api/types/ObjectParamAPI'
import logo from '@assets/logo.svg' import logo from '@assets/logo.svg'
import React, { useRef } from 'react' import React, { useRef } from 'react'
import { AuthServiceApi, RbacLoginRequest, RbacLoginResponse, createConfiguration } from '@api/index' import { AuthServiceLoginApiArg, useAuthServiceLoginMutation } from '@api/api'
const LoginPage = () => { const LoginPage = () => {
const { t } = useTranslation('common') const { t } = useTranslation('common')
const usernameRef = useRef<HTMLInputElement>(null) const usernameRef = useRef<HTMLInputElement>(null)
const passwordRef = useRef<HTMLInputElement>(null) const passwordRef = useRef<HTMLInputElement>(null)
const getAuthPayload = (): RbacLoginRequest => { const getAuthPayload = (): AuthServiceLoginApiArg => {
const username = usernameRef.current?.value const username = usernameRef.current?.value
const password = passwordRef.current?.value const password = passwordRef.current?.value
// TODO check values // TODO check values
const payload: RbacLoginRequest = { const payload: AuthServiceLoginApiArg = {
username: username, rbacLoginRequest: {
pwd: password, username: username,
timestamp: new Date().toString(), pwd: password,
timestamp: new Date().getTime().toString(),
}
} }
return payload; return payload;
} }
const [
sendLogin,
] = useAuthServiceLoginMutation()
const login = (event: React.FormEvent<HTMLFormElement>) => { const login = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault() event.preventDefault()
const configuration = createConfiguration();
const apiInstance = new AuthServiceApi(configuration);
const payload = getAuthPayload(); const payload = getAuthPayload();
sendLogin(payload).unwrap()
.then((payload) => console.log('fulfilled', payload))
apiInstance.authServiceLogin(payload).then((response:RbacLoginResponse) => { .catch((error) => console.error('rejected', error));
console.log('API called successfully. Returned data: ' + response);
}).catch((error:any) => console.error(error));
} }
return ( return (
......
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://127.0.0.1:8089',
changeOrigin: true,
})
);
};
\ No newline at end of file
import { combineReducers } from 'redux' import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import userReducer from './slices/user.reducer'
import { configureStore } from '@reduxjs/toolkit'
const getReducers = () => { // initialize an empty api service that we'll inject endpoints into later as needed
return combineReducers({ export const emptySplitApi = createApi({
userReducer, baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
}) endpoints: () => ({}),
} })
\ No newline at end of file
const initStore = () => {
return configureStore({
reducer: getReducers(),
})
}
//export type RootState = ReturnType<typeof store.getState>
export default initStore
import { combineReducers } from 'redux'
import userReducer from './slices/user.reducer'
import { configureStore } from '@reduxjs/toolkit'
import { emptySplitApi } from './api.store'
import { setupListeners } from '@reduxjs/toolkit/query'
const getReducers = () => {
return combineReducers({
userReducer,
[emptySplitApi.reducerPath]: emptySplitApi.reducer
})
}
export const store = configureStore({
reducer: getReducers(),
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(emptySplitApi.middleware),
})
setupListeners(store.dispatch)
//export type RootState = ReturnType<typeof store.getState>
\ No newline at end of file
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"include": [ "include": [
"src/**/*.d.ts", "src/**/*.d.ts",
"src/**/*.ts", "src/**/*.ts",
"src/**/*.tsx", "src/**/*.tsx", "src/stores/api.store.ts", "scripts/test.ts",
], ],
//"references": [{ "path": "./tsconfig.node.json" }] //"references": [{ "path": "./tsconfig.node.json" }]
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"skipLibCheck": true, "skipLibCheck": true,
"module": "ESNext", "module": "ES2020",
"moduleResolution": "bundler", "moduleResolution": "bundler",
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true "strict": true
......
...@@ -8,10 +8,10 @@ export default defineConfig({ ...@@ -8,10 +8,10 @@ export default defineConfig({
port: 3000, port: 3000,
proxy: { proxy: {
'/api': { '/api': {
target: 'https://localhost:8089', target: 'http://127.0.0.1:8080',
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
ws: true, rewrite: (path) => path.replace(/^\/api/, ''),
configure: (proxy, _options) => { configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => { proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err); console.log('proxy error', err);
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment