Skip to content

Commit 51b3c6b

Browse files
⬆️ Upgrade to React 18 (+ other upgrades) (#379)
- Upgrade React from 16 to 18 - Upgrade React Router from 4 to 6 - Replace the markdown editor `react-mde`, which is no longer maintained and lacks a React 18-compatible version, by `react-markdown` - Upgrade Prettier from 1 to 3 - Replace `pretty-quick`, which is no longer maintained, by `lint-staged` - Revise how the no-auth mode works. When the server is running in this mode, the client must now send a user ID through the `Authorization` header. The server will no longer create a user automatically. This is useful for e2e tests, which can now have full control over the user profile. - Upgrade some ESLint plugins
1 parent 47dad31 commit 51b3c6b

File tree

145 files changed

+6857
-2613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+6857
-2613
lines changed

client/.eslintrc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
{
22
"env": {
33
"browser": true,
4-
"es6": true
4+
"es2022": true
55
},
6-
"extends": ["standard", "react-app", "prettier", "prettier/standard"],
6+
"extends": ["standard", "plugin:react/recommended", "plugin:react/jsx-runtime", "prettier"],
7+
"parser": "@babel/eslint-parser",
78
"parserOptions": {
89
"ecmaVersion": 2019,
910
"sourceType": "module",
11+
"requireConfigFile": false,
1012
"ecmaFeatures": {
11-
"jsx": true
13+
"jsx": true,
14+
"modules": true
15+
},
16+
"babelOptions": {
17+
"presets": ["@babel/preset-react"]
18+
}
19+
},
20+
"settings": {
21+
"react": {
22+
"version": "detect"
1223
}
1324
},
1425
"rules": {
15-
"no-console": 1,
26+
"no-console": "warn",
27+
"react/prop-types": "off",
28+
"react/no-unescaped-entities": "off",
1629
"linebreak-style": ["error", "unix"],
1730
"space-before-function-paren": [
1831
"error",

client/package-lock.json

Lines changed: 3897 additions & 824 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
"version": "1.0.0",
44
"private": true,
55
"dependencies": {
6-
"@apollo/client": "^3.7.15",
6+
"@apollo/client": "^3.7.17",
7+
"@uiw/react-md-editor": "^3.23.3",
78
"algoliasearch": "^3.35.1",
89
"apollo3-cache-persist": "^0.14.1",
910
"auth0-js": "^9.12.1",
1011
"babel-runtime": "^6.26.0",
1112
"classnames": "^2.2.5",
1213
"copy-to-clipboard": "^3.2.0",
1314
"date-fns": "^2.30.0",
14-
"eslint-config-react-app": "^7.0.1",
1515
"graphql": "^14.7.0",
16-
"graphql-tag": "^2.8.0",
1716
"lodash": "^4.17.15",
18-
"normalize.css": "^8.0.0",
19-
"react": "^16.12.0",
20-
"react-dom": "^16.12.0",
17+
"modern-normalize": "^2.0.0",
18+
"react": "^18.2.0",
19+
"react-dom": "^18.2.0",
2120
"react-helmet": "^6.0.0-beta",
22-
"react-mde": "^7.9.0",
21+
"react-markdown": "^8.0.7",
2322
"react-onclickoutside": "^6.9.0",
24-
"react-pluralize": "^1.6.3",
25-
"react-router": "^4.2.0",
26-
"react-router-dom": "^4.2.2",
23+
"react-router": "^6.14.1",
24+
"react-router-dom": "^6.14.1",
2725
"showdown": "^1.9.1",
2826
"showdown-xss-filter": "^0.2.0",
2927
"subscriptions-transport-ws": "^0.9.16",
@@ -38,23 +36,33 @@
3836
"prettier:write": "npm run prettier -- --write",
3937
"prettier:check": "npm run prettier -- --check"
4038
},
39+
"lint-staged": {
40+
"./src/**/*.{js,jsx}": [
41+
"npm run lint",
42+
"npm run prettier"
43+
]
44+
},
4145
"husky": {
4246
"hooks": {
43-
"pre-commit": "pretty-quick --staged"
47+
"pre-commit": "lint-staged"
4448
}
4549
},
4650
"devDependencies": {
51+
"@babel/eslint-parser": "^7.22.9",
52+
"@babel/preset-react": "^7.22.5",
4753
"@vitejs/plugin-react": "^4.0.0",
4854
"dotenv": "^5.0.0",
4955
"dotenv-cli": "^1.4.0",
50-
"eslint-config-prettier": "^4.3.0",
56+
"eslint": "^8.42.0",
57+
"eslint-config-prettier": "^8.8.0",
58+
"eslint-config-react-app": "^7.0.1",
5159
"eslint-config-standard": "^12.0.0",
52-
"eslint-plugin-node": "^7.0.1",
53-
"eslint-plugin-promise": "^4.2.1",
54-
"eslint-plugin-standard": "^4.0.1",
60+
"eslint-plugin-node": "^11.1.0",
61+
"eslint-plugin-promise": "^6.1.1",
62+
"eslint-plugin-react": "^7.32.2",
5563
"husky": "^3.1.0",
56-
"prettier": "^1.19.1",
57-
"pretty-quick": "^1.11.1",
64+
"lint-staged": "^13.2.3",
65+
"prettier": "^3.0.0",
5866
"sass": "^1.52.3",
5967
"vite": "^4.1.4"
6068
},

client/src/components/AlertStack/Alert.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
.alert-wrapper {
2121
position: relative;
2222
max-height: 0;
23-
transition: max-height 0.5s, margin-right 0.5s 0.5s;
23+
transition:
24+
max-height 0.5s,
25+
margin-right 0.5s 0.5s;
2426
margin-right: 0;
2527
}
2628

client/src/components/AlertStack/Alert.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { Component } from 'react'
2-
import PropTypes from 'prop-types'
31
import cn from 'classnames'
2+
import PropTypes from 'prop-types'
3+
import { Component } from 'react'
44

55
import AlertContext from './AlertContext'
66

@@ -13,7 +13,7 @@ class Alert extends Component {
1313
setTimeout(() => this.context.showAlert(this.props.alert), 0)
1414
setTimeout(
1515
() => this.context.closeAlert(this.props.alert),
16-
this.props.alert.type === 'success' ? 5000 : 7000
16+
this.props.alert.type === 'success' ? 5000 : 7000,
1717
)
1818
}
1919

@@ -24,7 +24,7 @@ class Alert extends Component {
2424
<div
2525
className={cn('alert-wrapper', {
2626
'is-shown': alert.shown,
27-
'is-closed': alert.closed
27+
'is-closed': alert.closed,
2828
})}
2929
>
3030
<div className={cn('alert', 'is-' + alert.type)}>
@@ -39,8 +39,8 @@ class Alert extends Component {
3939
Alert.propTypes = {
4040
alert: PropTypes.shape({
4141
type: PropTypes.string.isRequired,
42-
message: PropTypes.node.isRequired
43-
}).isRequired
42+
message: PropTypes.node.isRequired,
43+
}).isRequired,
4444
}
4545

4646
export default Alert

client/src/components/AlertStack/AlertContext.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class AlertProvider extends Component {
1111
alerts: [],
1212
pushAlert: this.pushAlert,
1313
showAlert: this.showAlert,
14-
closeAlert: this.closeAlert
14+
closeAlert: this.closeAlert,
1515
}
1616

1717
AlertProvider.pushAlert = this.pushAlert
1818
}
1919

20-
pushAlert = alert => {
21-
this.setState(state => ({
22-
alerts: [{ ...alert, id: Math.random() }, ...state.alerts]
20+
pushAlert = (alert) => {
21+
this.setState((state) => ({
22+
alerts: [{ ...alert, id: Math.random() }, ...state.alerts],
2323
}))
2424

2525
if (['error', 'warning'].includes(alert.type)) {
@@ -28,20 +28,20 @@ class AlertProvider extends Component {
2828
}
2929
}
3030

31-
showAlert = alert =>
32-
this.setState(state => ({
33-
alerts: state.alerts.map(a => {
31+
showAlert = (alert) =>
32+
this.setState((state) => ({
33+
alerts: state.alerts.map((a) => {
3434
if (a !== alert) return a
3535
return { ...alert, shown: true }
36-
})
36+
}),
3737
}))
3838

39-
closeAlert = alert =>
40-
this.setState(state => ({
41-
alerts: state.alerts.map(a => {
39+
closeAlert = (alert) =>
40+
this.setState((state) => ({
41+
alerts: state.alerts.map((a) => {
4242
if (a !== alert) return a
4343
return { ...alert, closed: true }
44-
})
44+
}),
4545
}))
4646

4747
render() {
@@ -50,7 +50,7 @@ class AlertProvider extends Component {
5050
}
5151

5252
AlertProvider.propTypes = {
53-
children: PropTypes.node.isRequired
53+
children: PropTypes.node.isRequired,
5454
}
5555

5656
export default AlertContext

client/src/components/AlertStack/AlertStack.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react'
1+
import { Component } from 'react'
22

33
import Alert from './Alert'
44
import AlertContext from './AlertContext'
@@ -10,7 +10,7 @@ class AlertStack extends Component {
1010
render() {
1111
return (
1212
<div className="alert-stack">
13-
{this.context.alerts.map(alert => (
13+
{this.context.alerts.map((alert) => (
1414
<Alert key={alert.id} alert={alert} />
1515
))}
1616
</div>
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import React from 'react'
21
import PropTypes from 'prop-types'
3-
import { withRouter } from 'react-router'
4-
import { Redirect } from 'react-router-dom'
2+
import { Navigate } from 'react-router-dom'
53

64
import { useAuth } from 'contexts'
75

8-
const Authenticated = ({ location, reverse, redirect, children, admin, specialist }) => {
6+
const Authenticated = ({ reverse, redirect, children, admin, specialist }) => {
97
const { isAuth, isAdmin, isSpecialist } = useAuth()
10-
const currentURL = location.pathname + location.search
118

129
if (admin && isAdmin) {
1310
return children
@@ -18,26 +15,26 @@ const Authenticated = ({ location, reverse, redirect, children, admin, specialis
1815
}
1916

2017
if (admin || specialist) {
21-
return redirect ? <Redirect to="/" /> : ''
18+
return redirect ? <Navigate replace to="/" /> : ''
2219
}
2320

2421
if ((isAuth && !reverse) || (!isAuth && reverse)) {
2522
return children
2623
}
2724

2825
if (redirect) {
29-
return <Redirect to={{ pathname: redirect, state: { from: currentURL } }} />
26+
return <Navigate replace to={redirect} />
3027
}
3128

3229
return ''
3330
}
3431

3532
Authenticated.propTypes = {
36-
location: PropTypes.object.isRequired,
3733
reverse: PropTypes.bool,
3834
redirect: PropTypes.string,
3935
children: PropTypes.node,
40-
admin: PropTypes.bool
36+
admin: PropTypes.bool,
37+
specialist: PropTypes.bool,
4138
}
4239

43-
export default withRouter(Authenticated)
40+
export default Authenticated

client/src/components/Avatar/Avatar.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import PropTypes from 'prop-types'
32

43
import './Avatar.css'
@@ -9,7 +8,7 @@ const Avatar = ({ image, alt, ...otherProps }) => (
98

109
Avatar.propTypes = {
1110
image: PropTypes.string.isRequired,
12-
alt: PropTypes.string
11+
alt: PropTypes.string,
1312
}
1413

1514
export default Avatar

client/src/components/Button/Button.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { Component } from 'react'
2-
import PropTypes from 'prop-types'
31
import cn from 'classnames'
2+
import PropTypes from 'prop-types'
3+
import { Component } from 'react'
44

55
import './Button.css'
66

@@ -23,7 +23,7 @@ class Button extends Component {
2323
...otherProps
2424
} = this.props
2525

26-
const b2s = b => (b ? 'true' : 'false')
26+
const b2s = (b) => (b ? 'true' : 'false')
2727

2828
const buttonModifiers = [
2929
'primary',
@@ -33,7 +33,7 @@ class Button extends Component {
3333
'active',
3434
'raised',
3535
'fixed',
36-
'small'
36+
'small',
3737
].reduce((acc, m) => {
3838
this.props[m] && (acc[m] = b2s(this.props[m]))
3939
return acc
@@ -73,7 +73,9 @@ Button.propTypes = {
7373
active: PropTypes.bool,
7474
raised: PropTypes.bool,
7575
disabled: PropTypes.bool,
76-
fixed: PropTypes.bool
76+
fixed: PropTypes.bool,
77+
loading: PropTypes.bool,
78+
small: PropTypes.bool,
7779
}
7880

7981
export default Button

0 commit comments

Comments
 (0)