mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 06:22:59 +00:00
Convert redux state access to hooks
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
import { connect } from "react-redux";
|
||||
import { compose, withProps } from "recompose";
|
||||
import { jhapiRequest } from "../../util/jhapiUtil";
|
||||
import AddUser from "./AddUser.pre";
|
||||
|
||||
const withUserAPI = withProps((props) => ({
|
||||
addUsers: (usernames, admin) =>
|
||||
jhapiRequest("/users", "POST", { usernames, admin }),
|
||||
failRegexEvent: () =>
|
||||
alert(
|
||||
"Removed " +
|
||||
JSON.stringify(removed_users) +
|
||||
" for either containing special characters or being too short."
|
||||
),
|
||||
refreshUserData: () =>
|
||||
jhapiRequest("/users", "GET")
|
||||
.then((data) => data.json())
|
||||
.then((data) => props.dispatch({ type: "USER_DATA", value: data })),
|
||||
}));
|
||||
|
||||
export default compose(connect(), withUserAPI)(AddUser);
|
@@ -1,11 +1,23 @@
|
||||
import React, { useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { compose, withProps } from "recompose";
|
||||
import { Link } from "react-router-dom";
|
||||
import PropTypes from "prop-types";
|
||||
import { jhapiRequest } from "../../util/jhapiUtil";
|
||||
|
||||
const AddUser = (props) => {
|
||||
var [users, setUsers] = useState([]),
|
||||
[admin, setAdmin] = useState(false);
|
||||
|
||||
var dispatch = useDispatch();
|
||||
|
||||
var dispatchUserData = (data) => {
|
||||
dispatch({
|
||||
type: "USER_DATA",
|
||||
value: data,
|
||||
});
|
||||
};
|
||||
|
||||
var { addUsers, failRegexEvent, refreshUserData, history } = props;
|
||||
|
||||
return (
|
||||
@@ -66,7 +78,11 @@ const AddUser = (props) => {
|
||||
}
|
||||
|
||||
addUsers(filtered_users, admin)
|
||||
.then(() => refreshUserData())
|
||||
.then(
|
||||
refreshUserData()
|
||||
.then((data) => dispatchUserData(data))
|
||||
.catch((err) => console.log(err))
|
||||
)
|
||||
.then(() => history.push("/"))
|
||||
.catch((err) => console.log(err));
|
||||
}}
|
||||
@@ -91,4 +107,17 @@ AddUser.propTypes = {
|
||||
}),
|
||||
};
|
||||
|
||||
export default AddUser;
|
||||
const withUserAPI = withProps((props) => ({
|
||||
addUsers: (usernames, admin) =>
|
||||
jhapiRequest("/users", "POST", { usernames, admin }),
|
||||
failRegexEvent: () =>
|
||||
alert(
|
||||
"Removed " +
|
||||
JSON.stringify(removed_users) +
|
||||
" for either containing special characters or being too short."
|
||||
),
|
||||
refreshUserData: () =>
|
||||
jhapiRequest("/users", "GET").then((data) => data.json()),
|
||||
}));
|
||||
|
||||
export default compose(withUserAPI)(AddUser);
|
Reference in New Issue
Block a user