Skip to content

Commit

Permalink
⬆️ Upgrade to React 18 (+ other upgrades) (#379)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
thibaudbrault authored Aug 2, 2023
1 parent 47dad31 commit 51b3c6b
Show file tree
Hide file tree
Showing 145 changed files with 6,857 additions and 2,613 deletions.
21 changes: 17 additions & 4 deletions client/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
{
"env": {
"browser": true,
"es6": true
"es2022": true
},
"extends": ["standard", "react-app", "prettier", "prettier/standard"],
"extends": ["standard", "plugin:react/recommended", "plugin:react/jsx-runtime", "prettier"],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"requireConfigFile": false,
"ecmaFeatures": {
"jsx": true
"jsx": true,
"modules": true
},
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"no-console": 1,
"no-console": "warn",
"react/prop-types": "off",
"react/no-unescaped-entities": "off",
"linebreak-style": ["error", "unix"],
"space-before-function-paren": [
"error",
Expand Down
4,721 changes: 3,897 additions & 824 deletions client/package-lock.json

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.15",
"@apollo/client": "^3.7.17",
"@uiw/react-md-editor": "^3.23.3",
"algoliasearch": "^3.35.1",
"apollo3-cache-persist": "^0.14.1",
"auth0-js": "^9.12.1",
"babel-runtime": "^6.26.0",
"classnames": "^2.2.5",
"copy-to-clipboard": "^3.2.0",
"date-fns": "^2.30.0",
"eslint-config-react-app": "^7.0.1",
"graphql": "^14.7.0",
"graphql-tag": "^2.8.0",
"lodash": "^4.17.15",
"normalize.css": "^8.0.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"modern-normalize": "^2.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.0.0-beta",
"react-mde": "^7.9.0",
"react-markdown": "^8.0.7",
"react-onclickoutside": "^6.9.0",
"react-pluralize": "^1.6.3",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-router": "^6.14.1",
"react-router-dom": "^6.14.1",
"showdown": "^1.9.1",
"showdown-xss-filter": "^0.2.0",
"subscriptions-transport-ws": "^0.9.16",
Expand All @@ -38,23 +36,33 @@
"prettier:write": "npm run prettier -- --write",
"prettier:check": "npm run prettier -- --check"
},
"lint-staged": {
"./src/**/*.{js,jsx}": [
"npm run lint",
"npm run prettier"
]
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
"pre-commit": "lint-staged"
}
},
"devDependencies": {
"@babel/eslint-parser": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@vitejs/plugin-react": "^4.0.0",
"dotenv": "^5.0.0",
"dotenv-cli": "^1.4.0",
"eslint-config-prettier": "^4.3.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-react-app": "^7.0.1",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"husky": "^3.1.0",
"prettier": "^1.19.1",
"pretty-quick": "^1.11.1",
"lint-staged": "^13.2.3",
"prettier": "^3.0.0",
"sass": "^1.52.3",
"vite": "^4.1.4"
},
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/AlertStack/Alert.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
.alert-wrapper {
position: relative;
max-height: 0;
transition: max-height 0.5s, margin-right 0.5s 0.5s;
transition:
max-height 0.5s,
margin-right 0.5s 0.5s;
margin-right: 0;
}

Expand Down
12 changes: 6 additions & 6 deletions client/src/components/AlertStack/Alert.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import cn from 'classnames'
import PropTypes from 'prop-types'
import { Component } from 'react'

import AlertContext from './AlertContext'

Expand All @@ -13,7 +13,7 @@ class Alert extends Component {
setTimeout(() => this.context.showAlert(this.props.alert), 0)
setTimeout(
() => this.context.closeAlert(this.props.alert),
this.props.alert.type === 'success' ? 5000 : 7000
this.props.alert.type === 'success' ? 5000 : 7000,
)
}

Expand All @@ -24,7 +24,7 @@ class Alert extends Component {
<div
className={cn('alert-wrapper', {
'is-shown': alert.shown,
'is-closed': alert.closed
'is-closed': alert.closed,
})}
>
<div className={cn('alert', 'is-' + alert.type)}>
Expand All @@ -39,8 +39,8 @@ class Alert extends Component {
Alert.propTypes = {
alert: PropTypes.shape({
type: PropTypes.string.isRequired,
message: PropTypes.node.isRequired
}).isRequired
message: PropTypes.node.isRequired,
}).isRequired,
}

export default Alert
26 changes: 13 additions & 13 deletions client/src/components/AlertStack/AlertContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class AlertProvider extends Component {
alerts: [],
pushAlert: this.pushAlert,
showAlert: this.showAlert,
closeAlert: this.closeAlert
closeAlert: this.closeAlert,
}

AlertProvider.pushAlert = this.pushAlert
}

pushAlert = alert => {
this.setState(state => ({
alerts: [{ ...alert, id: Math.random() }, ...state.alerts]
pushAlert = (alert) => {
this.setState((state) => ({
alerts: [{ ...alert, id: Math.random() }, ...state.alerts],
}))

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

showAlert = alert =>
this.setState(state => ({
alerts: state.alerts.map(a => {
showAlert = (alert) =>
this.setState((state) => ({
alerts: state.alerts.map((a) => {
if (a !== alert) return a
return { ...alert, shown: true }
})
}),
}))

closeAlert = alert =>
this.setState(state => ({
alerts: state.alerts.map(a => {
closeAlert = (alert) =>
this.setState((state) => ({
alerts: state.alerts.map((a) => {
if (a !== alert) return a
return { ...alert, closed: true }
})
}),
}))

render() {
Expand All @@ -50,7 +50,7 @@ class AlertProvider extends Component {
}

AlertProvider.propTypes = {
children: PropTypes.node.isRequired
children: PropTypes.node.isRequired,
}

export default AlertContext
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/AlertStack/AlertStack.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import { Component } from 'react'

import Alert from './Alert'
import AlertContext from './AlertContext'
Expand All @@ -10,7 +10,7 @@ class AlertStack extends Component {
render() {
return (
<div className="alert-stack">
{this.context.alerts.map(alert => (
{this.context.alerts.map((alert) => (
<Alert key={alert.id} alert={alert} />
))}
</div>
Expand Down
17 changes: 7 additions & 10 deletions client/src/components/Authenticated/Authenticated.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
import { Redirect } from 'react-router-dom'
import { Navigate } from 'react-router-dom'

import { useAuth } from 'contexts'

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

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

if (admin || specialist) {
return redirect ? <Redirect to="/" /> : ''
return redirect ? <Navigate replace to="/" /> : ''
}

if ((isAuth && !reverse) || (!isAuth && reverse)) {
return children
}

if (redirect) {
return <Redirect to={{ pathname: redirect, state: { from: currentURL } }} />
return <Navigate replace to={redirect} />
}

return ''
}

Authenticated.propTypes = {
location: PropTypes.object.isRequired,
reverse: PropTypes.bool,
redirect: PropTypes.string,
children: PropTypes.node,
admin: PropTypes.bool
admin: PropTypes.bool,
specialist: PropTypes.bool,
}

export default withRouter(Authenticated)
export default Authenticated
3 changes: 1 addition & 2 deletions client/src/components/Avatar/Avatar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import PropTypes from 'prop-types'

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

Avatar.propTypes = {
image: PropTypes.string.isRequired,
alt: PropTypes.string
alt: PropTypes.string,
}

export default Avatar
12 changes: 7 additions & 5 deletions client/src/components/Button/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import cn from 'classnames'
import PropTypes from 'prop-types'
import { Component } from 'react'

import './Button.css'

Expand All @@ -23,7 +23,7 @@ class Button extends Component {
...otherProps
} = this.props

const b2s = b => (b ? 'true' : 'false')
const b2s = (b) => (b ? 'true' : 'false')

const buttonModifiers = [
'primary',
Expand All @@ -33,7 +33,7 @@ class Button extends Component {
'active',
'raised',
'fixed',
'small'
'small',
].reduce((acc, m) => {
this.props[m] && (acc[m] = b2s(this.props[m]))
return acc
Expand Down Expand Up @@ -73,7 +73,9 @@ Button.propTypes = {
active: PropTypes.bool,
raised: PropTypes.bool,
disabled: PropTypes.bool,
fixed: PropTypes.bool
fixed: PropTypes.bool,
loading: PropTypes.bool,
small: PropTypes.bool,
}

export default Button
9 changes: 4 additions & 5 deletions client/src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react'
import PropTypes from 'prop-types'
import cn from 'classnames'
import PropTypes from 'prop-types'

import CardTitle from './CardTitle'
import CardText from './CardText'
import CardActions from './CardActions'
import CardText from './CardText'
import CardTitle from './CardTitle'

import './Card.css'

Expand All @@ -16,7 +15,7 @@ const Card = ({ children, className, ...otherProps }) => (

Card.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string
className: PropTypes.string,
}

Card.Title = CardTitle
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/Card/CardActions.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import PropTypes from 'prop-types'

const CardAction = ({ children, ...otherProps }) => (
Expand All @@ -8,7 +7,7 @@ const CardAction = ({ children, ...otherProps }) => (
)

CardAction.propTypes = {
children: PropTypes.node.isRequired
children: PropTypes.node.isRequired,
}

export default CardAction
5 changes: 2 additions & 3 deletions client/src/components/Card/CardText.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import PropTypes from 'prop-types'
import cn from 'classnames'
import PropTypes from 'prop-types'

const CardText = ({ children, collapsed, className, ...otherProps }) => (
<div className={cn('card-item card-text', { collapsed }, className)} {...otherProps}>
Expand All @@ -11,7 +10,7 @@ const CardText = ({ children, collapsed, className, ...otherProps }) => (
CardText.propTypes = {
children: PropTypes.node.isRequired,
collapsed: PropTypes.bool,
className: PropTypes.string
className: PropTypes.string,
}

export default CardText
Loading

0 comments on commit 51b3c6b

Please sign in to comment.