Skip to content

Commit

Permalink
Merge pull request #2 from TomaszPilch/TECH-add-dynamic-translation-s…
Browse files Browse the repository at this point in the history
…upport

Tech add dynamic translation support
  • Loading branch information
TomaszPilch authored Jan 12, 2021
2 parents a03ca43 + 1687966 commit c0f2015
Show file tree
Hide file tree
Showing 20 changed files with 2,936 additions and 2,650 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ yarn-error.log*
.env.development.local
.env.test.local
.env.production.local

# locales
public/static/locales/en/*
public/static/locales/*/*
!public/static/locales/.gitkeep
!public/static/locales/en/.gitkeep
!public/static/locales/en
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ yarn dev

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Env

```
API_URL
COPYRIGHT
CLIENT_SECRET
CLIENT_ID
NODE_ENV
LOCALE_PASS
APP_TITLE
```

## Link

```
node .\scripts\prelink.js
yarn link @bheui\components
```

## Created from BHE be v1

First commit 2018-01-17.
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
localeSubpaths,
apiUrl: process.env.API_URL,
copyright: process.env.COPYRIGHT,
appTitle: process.env.APP_TITLE || 'DevX BE',
},
serverRuntimeConfig: {
clientSecret: process.env.CLIENT_SECRET,
Expand Down
88 changes: 52 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,82 @@
{
"name": "bhe-be-ui-v2",
"version": "0.1.0",
"version": "0.2.0-beta1",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "node server.js",
"build": "next build",
"start": "next start",
"start": "better-npm-run start",
"test": "jest",
"test:watch": "jest --watch"
},
"betterScripts": {
"start": {
"command": "node server.js",
"env": {
"NODE_ENV": "production"
}
}
},
"dependencies": {
"@bheui/components": "^0.0.6",
"@fluentui/react": "^7.137.1",
"@uifabric/fluent-theme": "^7.3.7",
"@uifabric/icons": "^7.5.0",
"@bheui/components": "1.0.0-beta2",
"@bheui/server-functions": "^0.1.3",
"@fluentui/react": "^7.153.3",
"@uifabric/experiments": "^7.37.2",
"@uifabric/fluent-theme": "^7.3.47",
"@uifabric/icons": "^7.5.17",
"axios": "^0.21.1",
"better-npm-run": "^0.1.1",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"devx-js-utilities": "^0.1.5",
"express": "^4.17.1",
"i18next-intervalplural-postprocessor": "^2.0.2",
"next": "9.5.3",
"next-i18next": "^6.0.2",
"next": "10.0.3",
"next-i18next": "^7.0.1",
"next-redux-wrapper": "^6.0.2",
"node-sass": "^4.14.1",
"node-sass": "^5.0.0",
"office-ui-fabric-core": "^11.0.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-redux": "^7.2.1",
"ramda": "^0.27.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-redux": "^7.2.2",
"react-toastr": "^3.0.0",
"redux": "^4.0.5",
"redux-observable": "^1.2.0",
"redux-thunk": "^2.3.0",
"reduxsauce": "^1.1.3",
"rxjs": "^6.6.0",
"sass": "^1.26.10",
"reduxsauce": "^1.2.0",
"rxjs": "^6.6.3",
"sass": "^1.29.0",
"seamless-immutable": "^7.1.4"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.10.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-export-default-from": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
"@babel/cli": "^7.12.8",
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-export-default-from": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-flow": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.10.5",
"@babel/plugin-syntax-flow": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-flow": "^7.10.4",
"@babel/register": "^7.10.5",
"@babel/runtime": "^7.10.5",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@babel/register": "^7.12.1",
"@babel/runtime": "^7.12.5",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint": "^7.14.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.20.3",
"flow-bin": "^0.129.0",
"jest": "^26.1.0",
"prettier": "^2.0.5",
"eslint-plugin-react": "^7.21.5",
"flow-bin": "^0.138.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"redux-logger": "^3.0.6"
},
"jest": {
Expand Down
6 changes: 5 additions & 1 deletion pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Head from 'next/head'
import App from 'next/app'
import { Provider } from 'react-redux'
import { initializeIcons } from '@uifabric/icons'
import getConfig from 'next/config'

import withReduxAndAxios from '@bheui/components/lib/components/WithReduxAndAxios'

import '../src/styles/main.scss'
Expand All @@ -16,6 +18,8 @@ import createApis from '../src/store/createApis'
type AppTypes = {}

initializeIcons()

const { publicRuntimeConfig } = getConfig()
class MyApp extends App<AppTypes> {
componentDidCatch(error, info) {
console.error(error)
Expand All @@ -28,7 +32,7 @@ class MyApp extends App<AppTypes> {
return (
<>
<Head>
<title>DevX NextJS starterpack</title>
<title>{publicRuntimeConfig.appTitle}</title>
</Head>
<Provider store={store}>
<Component {...pageProps} router={router} setToken={setToken} t={t} />
Expand Down
31 changes: 2 additions & 29 deletions pages/api/login.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import axios from 'axios'
const loginRoute = require('@bheui/server-functions/lib/login/login')

const axiosLoginInstance = axios.create({
baseURL: `${process.env.API_URL}/api/v1`,
timeout: 100000,
headers: {
'Content-Type': 'application/json',
},
})

export default (req, res) => {
const formData = encodeURI(
`username=${req.body.email}&password=${req.body.password}&client_id=${process.env.CLIENT_ID}&client_secret=${process.env.CLIENT_SECRET}&grant_type=password`,
)
axiosLoginInstance
.post('/oauth/token', formData, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})
.then((response) => {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(response.data))
})
.catch((e) => {
res.statusCode = 400
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify(e.message))
})
}
module.exports = loginRoute
File renamed without changes.
1 change: 1 addition & 0 deletions public/static/defaultLocales/en/login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"loginScreen":{"signIn":"Sign In","remember":"Remember","submitButton":"Submit"},"general":{"email":"Email","password":"Password","login":"Login"},"validationErrors":{"required":"This value is required.","badFormat":"Value format is not valid.","tooShort":"This value is to short, min. length is {{length}}.","tooLong":"This value is to long, max. length is {{length}}.","badPhoneFormat":"This phone number is not valid.","email":"Invalid email address format.","cardNumber":"Card number is not valid.","range":"The value must be in range from {{start}} to {{end}}.","numeric":"Value must be numeric.","integer":"Value must be an integer.","badRegExp":"Bad format! Pattern: {{pattern}}","suffix_interval":"(1){ 1 other error };(2-inf){ {{count}} other errors};"}}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"delete": "Delete"
},
"group": "Group",
"description": "Description"
"description": "Description",
"selectValue": "Select value"
},
"modules": {
"dashboard": {
Expand Down
Empty file added public/static/locales/.gitkeep
Empty file.
Empty file.
26 changes: 0 additions & 26 deletions public/static/locales/en/login.json

This file was deleted.

19 changes: 19 additions & 0 deletions scripts/postlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { exec } = require('child_process')

const runCommand = (cmd) => {
exec(cmd, (e, stdout, stderr) => {
console.log(e)
console.log(stdout)
console.log(stderr)
})
}

runCommand('cd node_modules/react & yarn unlink')
runCommand('cd node_modules/react-redux & yarn unlink')
runCommand('cd node_modules/next & yarn unlink')
runCommand('cd node_modules/@fluentui/react & yarn unlink')
runCommand('cd node_modules/@uifabric/experiments & yarn unlink')
runCommand('cd node_modules/office-ui-fabric-core & yarn unlink')
runCommand('cd node_modules/office-ui-fabric-react & yarn unlink')
runCommand('cd node_modules/react & yarn unlink')
runCommand('cd node_modules/react-dom & yarn unlink')
19 changes: 19 additions & 0 deletions scripts/prelink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { exec } = require('child_process')

const runCommand = (cmd) => {
exec(cmd, (e, stdout, stderr) => {
console.log(e)
console.log(stdout)
console.log(stderr)
})
}

runCommand('cd node_modules/react & yarn link')
runCommand('cd node_modules/react-redux & yarn link')
runCommand('cd node_modules/next & yarn link')
runCommand('cd node_modules/@fluentui/react & yarn link')
runCommand('cd node_modules/@uifabric/experiments & yarn link')
runCommand('cd node_modules/office-ui-fabric-core & yarn link')
runCommand('cd node_modules/office-ui-fabric-react & yarn link')
runCommand('cd node_modules/react & yarn link')
runCommand('cd node_modules/react-dom & yarn link')
55 changes: 55 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const express = require('express')
const next = require('next')
const compression = require('compression')
const bodyParser = require('body-parser')

const processLocale = require('@bheui/server-functions/lib/locale/process-locale')

const apiLogin = require('./pages/api/login').default

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const renderPageOrContinue = (req, res, nextCl) => {
if (req.path.includes('_next') || req.path.includes('api/')) {
return nextCl()
}
const query = { ...req.params }
if (req.params.id) {
query.page = '/[module]/[action]/[id]'
} else if (req.params.action) {
query.page = '/[module]/[action]'
} else if (req.params.module) {
query.page = '/[module]'
}
return app.render(req, res, req.path, query)
}

app.prepare().then(async () => {
await processLocale()

const server = express()
server.use(`/static`, express.static('public'))
server.use(compression())

server.get('/is-ready', (req, res) => {
res.sendStatus(200)
})

server.use('/api/login', bodyParser.json({ limit: '50mb' }))
server.post('/api/login', apiLogin)

server.get('/:module/:action/:id', renderPageOrContinue, (req, res) => handle(req, res))
server.get('/:module/:action', renderPageOrContinue, (req, res) => handle(req, res))

server.get('*', (req, res) => handle(req, res))

server.listen(3000, (err) => {
if (err) {
console.error(err.stack)
process.exit(1)
}
console.log(`> Ready on http://localhost:${3000}`)
})
})
2 changes: 2 additions & 0 deletions src/containers/ListContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'
import TitleWithBreadcrumbs from '@bheui/components/lib/components/TitleWithBreadcrumbs'
import withModule from '@bheui/components/lib/components/WithModule'
import ListComponent from '@bheui/components/lib/components/ListComponent'
import CustomModuleComponents from '@bheui/components/lib/components/modules/CustomModuleComponents'

// types

Expand Down Expand Up @@ -35,6 +36,7 @@ class ListContainer extends React.Component<Props, State> {
<div className="container ms-bgColor-white list-container">
<ListComponent
changeRedirectUrl={changeRedirectUrl}
customComponents={CustomModuleComponents}
module={module}
navigationItem={navigationItem}
rights={rights}
Expand Down
Loading

0 comments on commit c0f2015

Please sign in to comment.