38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { Page } from '../Page';
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
import { RootState } from '../../store/reducers/root';
|
|
import { UserForm } from '../UserForm';
|
|
import { Loader } from '../Loader';
|
|
import { User } from '../../types/user';
|
|
import { updateProfile } from '../../store/actions/profile';
|
|
|
|
export function ProfilePage() {
|
|
const currentUser = useSelector((state: RootState) => state.auth.currentUser);
|
|
const dispatch = useDispatch();
|
|
|
|
const onUserChange = (user: User) => {
|
|
if (currentUser.name !== user.name) {
|
|
dispatch(updateProfile({ name: user.name }))
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Page title="Mon profil">
|
|
<div className="container is-fluid">
|
|
<section className="section">
|
|
<div className="columns">
|
|
<div className="column is-6 is-offset-3">
|
|
<h2 className="is-size-2 subtitle">Mon profil</h2>
|
|
{
|
|
currentUser ?
|
|
<UserForm onChange={onUserChange} user={currentUser} /> :
|
|
<Loader />
|
|
}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</Page>
|
|
);
|
|
} |