daddy/client/src/components/ProfilePage/ProfilePage.tsx

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-07-22 09:18:50 +02:00
import React from 'react';
2020-07-16 20:21:58 +02:00
import { Page } from '../Page';
import { UserForm } from '../UserForm';
import { User } from '../../types/user';
import { useUserProfile } from '../../gql/queries/profile';
2020-07-21 22:25:39 +02:00
import { useUpdateUserProfileMutation } from '../../gql/mutations/profile';
2020-07-16 20:21:58 +02:00
export function ProfilePage() {
const { user, loading } = useUserProfile();
const [ updateProfile, updateUserProfileMutation ] = useUpdateUserProfileMutation();
const isLoading = updateUserProfileMutation.loading || loading;
2020-07-16 20:21:58 +02:00
const onUserChange = (user: User) => {
if (user.name !== user.name) {
updateProfile({ variables: {changes: { name: user.name }}});
2020-07-16 20:21:58 +02:00
}
};
return (
<Page title="Mon profil">
<div className="container is-fluid">
<section className="section">
<div className="columns">
<div className="column is-6 is-offset-3">
2020-10-01 11:44:29 +02:00
<div className="box">
<h2 className="is-size-2 subtitle">Mon profil</h2>
2020-10-13 14:27:40 +02:00
{ !isLoading ? <UserForm onChange={onUserChange} user={user} /> : null }
2020-10-01 11:44:29 +02:00
</div>
2020-07-16 20:21:58 +02:00
</div>
</div>
</section>
</div>
</Page>
);
}
export default ProfilePage;