update requete ok : un user peut update ses informations
This commit is contained in:
parent
2e9234c1c9
commit
720599832e
1 changed files with 18 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ import { setCurrentUser } from "../../../redux/action";
|
|||
const UserUpdateForm = () => {
|
||||
const [userData, setUserData] = useState(null);
|
||||
const currentUser = useSelector((state) => state.currentUser);
|
||||
const dispatch = useDispatch();
|
||||
const history = useHistory();
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
|
|
@ -51,6 +53,22 @@ const UserUpdateForm = () => {
|
|||
const body = { user: { username: username, email: email } };
|
||||
const response = await update(`/users/${currentUser.id}`, body, token);
|
||||
console.log(response);
|
||||
if (response.status === 200) {
|
||||
handleChange(response);
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = (res) => {
|
||||
console.log("handle change : " + res.data.attributes);
|
||||
const payload = {
|
||||
type: "user",
|
||||
id: res.data.data.id,
|
||||
email: res.data.data.attributes.email,
|
||||
username: res.data.data.attributes.username
|
||||
};
|
||||
console.log("Payload : " + payload);
|
||||
dispatch(setCurrentUser(payload));
|
||||
history.push("/me");
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue