|
@@ -9,6 +9,8 @@ import { setCurrentUser } from "../../../redux/action";
|
9
|
9
|
const UserUpdateForm = () => {
|
10
|
10
|
const [userData, setUserData] = useState(null);
|
11
|
11
|
const currentUser = useSelector((state) => state.currentUser);
|
|
12
|
+ const dispatch = useDispatch();
|
|
13
|
+ const history = useHistory();
|
12
|
14
|
|
13
|
15
|
const handleSubmit = (e) => {
|
14
|
16
|
e.preventDefault();
|
|
@@ -51,6 +53,22 @@ const UserUpdateForm = () => {
|
51
|
53
|
const body = { user: { username: username, email: email } };
|
52
|
54
|
const response = await update(`/users/${currentUser.id}`, body, token);
|
53
|
55
|
console.log(response);
|
|
56
|
+ if (response.status === 200) {
|
|
57
|
+ handleChange(response);
|
|
58
|
+ }
|
|
59
|
+ };
|
|
60
|
+
|
|
61
|
+ const handleChange = (res) => {
|
|
62
|
+ console.log("handle change : " + res.data.attributes);
|
|
63
|
+ const payload = {
|
|
64
|
+ type: "user",
|
|
65
|
+ id: res.data.data.id,
|
|
66
|
+ email: res.data.data.attributes.email,
|
|
67
|
+ username: res.data.data.attributes.username
|
|
68
|
+ };
|
|
69
|
+ console.log("Payload : " + payload);
|
|
70
|
+ dispatch(setCurrentUser(payload));
|
|
71
|
+ history.push("/me");
|
54
|
72
|
};
|
55
|
73
|
|
56
|
74
|
useEffect(() => {
|