Use redux hooks on polochon components
This commit is contained in:
parent
c5336c477a
commit
ac0d746cc9
@ -1,12 +1,13 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { addPolochon } from "../../actions/polochon";
|
import { addPolochon } from "../../actions/polochon";
|
||||||
|
|
||||||
import { PolochonEdit } from "./edit";
|
import { PolochonEdit } from "./edit";
|
||||||
|
|
||||||
export const PolochonAddConnected = ({ addPolochon }) => {
|
export const PolochonAdd = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
const [modal, setModal] = useState(false);
|
const [modal, setModal] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -21,13 +22,11 @@ export const PolochonAddConnected = ({ addPolochon }) => {
|
|||||||
icon="plus"
|
icon="plus"
|
||||||
show={modal}
|
show={modal}
|
||||||
setShow={setModal}
|
setShow={setModal}
|
||||||
update={addPolochon}
|
update={(params) => dispatch(addPolochon(params))}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
PolochonAddConnected.propTypes = {
|
PolochonAdd.propTypes = {
|
||||||
addPolochon: PropTypes.func,
|
addPolochon: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PolochonAdd = connect(null, { addPolochon })(PolochonAddConnected);
|
|
||||||
|
@ -1,25 +1,18 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import PropTypes from "prop-types";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { connect } from "react-redux";
|
|
||||||
import { List } from "immutable";
|
|
||||||
|
|
||||||
import { getManagedPolochons } from "../../actions/polochon";
|
import { getManagedPolochons } from "../../actions/polochon";
|
||||||
|
|
||||||
import { Polochon } from "./polochon";
|
import { Polochon } from "./polochon";
|
||||||
import { PolochonAdd } from "./add";
|
import { PolochonAdd } from "./add";
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
export const PolochonList = () => {
|
||||||
managedList: state.polochon.get("managed"),
|
const list = useSelector((state) => state.polochon.get("managed"));
|
||||||
});
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
|
||||||
getManagedPolochons,
|
|
||||||
};
|
|
||||||
|
|
||||||
const PolochonListConnected = ({ getManagedPolochons, managedList }) => {
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getManagedPolochons();
|
dispatch(getManagedPolochons());
|
||||||
}, [getManagedPolochons]);
|
}, [dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row mb-3">
|
<div className="row mb-3">
|
||||||
@ -27,7 +20,7 @@ const PolochonListConnected = ({ getManagedPolochons, managedList }) => {
|
|||||||
<h2>My polochons</h2>
|
<h2>My polochons</h2>
|
||||||
<hr />
|
<hr />
|
||||||
<span>
|
<span>
|
||||||
{managedList.map((el, index) => (
|
{list.map((el, index) => (
|
||||||
<Polochon
|
<Polochon
|
||||||
key={index}
|
key={index}
|
||||||
id={el.get("id")}
|
id={el.get("id")}
|
||||||
@ -44,12 +37,3 @@ const PolochonListConnected = ({ getManagedPolochons, managedList }) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
PolochonListConnected.propTypes = {
|
|
||||||
getManagedPolochons: PropTypes.func,
|
|
||||||
managedList: PropTypes.instanceOf(List),
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PolochonList = connect(
|
|
||||||
mapStateToProps,
|
|
||||||
mapDispatchToProps
|
|
||||||
)(PolochonListConnected);
|
|
||||||
|
@ -1,25 +1,18 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { List } from "immutable";
|
import { List } from "immutable";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { PolochonUsers } from "./users";
|
import { PolochonUsers } from "./users";
|
||||||
import { PolochonEdit } from "./edit";
|
import { PolochonEdit } from "./edit";
|
||||||
|
|
||||||
import { updatePolochon, deletePolochon } from "../../actions/polochon";
|
import { updatePolochon, deletePolochon } from "../../actions/polochon";
|
||||||
|
|
||||||
export const PolochonConnected = ({
|
export const Polochon = ({ id, name, token, url, authToken, users }) => {
|
||||||
id,
|
|
||||||
name,
|
|
||||||
token,
|
|
||||||
url,
|
|
||||||
authToken,
|
|
||||||
users,
|
|
||||||
updatePolochon,
|
|
||||||
deletePolochon,
|
|
||||||
}) => {
|
|
||||||
const [edit, setEdit] = useState(false);
|
const [edit, setEdit] = useState(false);
|
||||||
|
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<div className="card mb-2">
|
<div className="card mb-2">
|
||||||
@ -33,7 +26,7 @@ export const PolochonConnected = ({
|
|||||||
/>
|
/>
|
||||||
<i
|
<i
|
||||||
className="fa fa-trash clickable"
|
className="fa fa-trash clickable"
|
||||||
onClick={() => deletePolochon(id)}
|
onClick={() => dispatch(deletePolochon(id))}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -49,7 +42,7 @@ export const PolochonConnected = ({
|
|||||||
title="Polochon config"
|
title="Polochon config"
|
||||||
show={edit}
|
show={edit}
|
||||||
setShow={setEdit}
|
setShow={setEdit}
|
||||||
update={updatePolochon}
|
update={(params) => dispatch(updatePolochon(params))}
|
||||||
id={id}
|
id={id}
|
||||||
initialName={name}
|
initialName={name}
|
||||||
initialUrl={url}
|
initialUrl={url}
|
||||||
@ -58,17 +51,11 @@ export const PolochonConnected = ({
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
PolochonConnected.propTypes = {
|
Polochon.propTypes = {
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
token: PropTypes.string,
|
token: PropTypes.string,
|
||||||
url: PropTypes.string,
|
url: PropTypes.string,
|
||||||
authToken: PropTypes.string,
|
authToken: PropTypes.string,
|
||||||
users: PropTypes.instanceOf(List),
|
users: PropTypes.instanceOf(List),
|
||||||
updatePolochon: PropTypes.func,
|
|
||||||
deletePolochon: PropTypes.func,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Polochon = connect(null, { updatePolochon, deletePolochon })(
|
|
||||||
PolochonConnected
|
|
||||||
);
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { connect } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import { editPolochonUser } from "../../actions/polochon";
|
import { editPolochonUser } from "../../actions/polochon";
|
||||||
|
|
||||||
@ -9,14 +9,14 @@ import Toggle from "react-bootstrap-toggle";
|
|||||||
import { FormModal } from "../forms/modal";
|
import { FormModal } from "../forms/modal";
|
||||||
import { FormInput } from "../forms/input";
|
import { FormInput } from "../forms/input";
|
||||||
|
|
||||||
export const PolochonUserConnected = ({
|
export const PolochonUser = ({
|
||||||
polochonId,
|
polochonId,
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
initialToken,
|
initialToken,
|
||||||
initialActivated,
|
initialActivated,
|
||||||
editPolochonUser,
|
|
||||||
}) => {
|
}) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
const [edit, setEdit] = useState(false);
|
const [edit, setEdit] = useState(false);
|
||||||
const [token, setToken] = useState(initialToken);
|
const [token, setToken] = useState(initialToken);
|
||||||
const [activated, setActivated] = useState(initialActivated);
|
const [activated, setActivated] = useState(initialActivated);
|
||||||
@ -27,12 +27,14 @@ export const PolochonUserConnected = ({
|
|||||||
}, [initialActivated, initialToken]);
|
}, [initialActivated, initialToken]);
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
|
dispatch(
|
||||||
editPolochonUser({
|
editPolochonUser({
|
||||||
polochonId,
|
polochonId,
|
||||||
id,
|
id,
|
||||||
token,
|
token,
|
||||||
activated,
|
activated,
|
||||||
});
|
})
|
||||||
|
);
|
||||||
setEdit(false);
|
setEdit(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ export const PolochonUserConnected = ({
|
|||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
PolochonUserConnected.propTypes = {
|
PolochonUser.propTypes = {
|
||||||
polochonId: PropTypes.string,
|
polochonId: PropTypes.string,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
@ -75,7 +77,3 @@ PolochonUserConnected.propTypes = {
|
|||||||
initialActivated: PropTypes.bool,
|
initialActivated: PropTypes.bool,
|
||||||
editPolochonUser: PropTypes.func,
|
editPolochonUser: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PolochonUser = connect(null, { editPolochonUser })(
|
|
||||||
PolochonUserConnected
|
|
||||||
);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user