-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathuseprofile.js
More file actions
54 lines (46 loc) · 1.54 KB
/
useprofile.js
File metadata and controls
54 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable react/button-has-type */
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable max-len */
/* eslint-disable import/order */
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable react/self-closing-comp */
/* eslint-disable no-unused-vars */
import { useMutation, useQuery } from '@apollo/client';
import React, { useEffect, useState } from 'react';
import { Container } from 'react-bootstrap';
import { useNavigate } from 'react-router';
import LOGOUT from '../../../graphql/mutation/LOGOUT';
import GET_USER from '../../../graphql/queries/GET_USER';
import { SectionLayout } from '../../marginals';
import { FormInputBtn } from '../styles';
import { Card, H1, Heading, Title } from './styles';
function Profile() {
const { data } = useQuery(GET_USER);
const [logout, { data1, error }] = useMutation(LOGOUT);
const [user, setUser] = useState('');
const history = useNavigate();
useEffect(() => {
if (data) {
setUser(data.getCurrentUser);
}
}, [setUser, data]);
const handlelogout = async (event) => {
logout({});
history.push('/signup');
};
return (
<SectionLayout>
<Container>
<Heading style={{ textAlign: 'center' }}>User Profile</Heading>
<Card>
<H1>Name: {user.fullName}</H1>
<H1>Username: {user.username}</H1>
<Title>{user.role}</Title>
<H1>Email: {user.email}</H1>
<FormInputBtn onClick={handlelogout}>Logout</FormInputBtn>
</Card>
</Container>
</SectionLayout>
);
}
export default Profile;