-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): set current user as global context
- Loading branch information
Showing
41 changed files
with
249 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,30 @@ | ||
/* eslint-disable react/jsx-no-target-blank */ | ||
import React from 'react' | ||
import gql from 'graphql-tag' | ||
import { useQuery } from '@apollo/client' | ||
|
||
import authService from '../auth' | ||
import { ErrorPanel, Loader, TimeAgo } from '.' | ||
import { matchResponse, getRoboHash } from '../helpers' | ||
import { TimeAgo } from '.' | ||
import { getRoboHash } from '../helpers' | ||
import styles from './UserInfos.module.css' | ||
|
||
export const GetCurrentUser = gql` | ||
query { | ||
me { | ||
username | ||
hash | ||
hashid | ||
plan | ||
customer_id | ||
last_login_at | ||
created_at | ||
} | ||
} | ||
` | ||
|
||
export interface User { | ||
username: string | ||
hash: string | ||
hashid: string | ||
plan: string | ||
customer_id: string | ||
created_at: string | ||
last_login_at: string | ||
} | ||
|
||
export interface GetCurrentUserResponse { | ||
me: User | ||
} | ||
import { useCurrentUser } from '../contexts' | ||
|
||
export const UserInfos = () => { | ||
const { data, error, loading } = useQuery<GetCurrentUserResponse>(GetCurrentUser) | ||
|
||
const render = matchResponse<GetCurrentUserResponse>({ | ||
Loading: () => <Loader />, | ||
Error: (err) => <ErrorPanel>{err.message}</ErrorPanel>, | ||
Data: (data) => ( | ||
<> | ||
<span> | ||
<strong title={data.me.username}>{data.me.username}</strong> | ||
<small> | ||
Member <TimeAgo dateTime={data.me.created_at} /> | ||
</small> | ||
</span> | ||
<a href={authService.getAccountUrl()} target="_blank" title="Go to my profile page"> | ||
<img src={getRoboHash(data.me.hash, '48')} alt={data.me.username} /> | ||
</a> | ||
</> | ||
), | ||
}) | ||
|
||
return <div className={styles.userInfos}>{render(loading, data, error)}</div> | ||
const user = useCurrentUser() | ||
if (!user) { | ||
return null | ||
} | ||
return ( | ||
<div className={styles.userInfos}> | ||
<span> | ||
<strong title={user.username}>{user.username}</strong> | ||
<small> | ||
Member <TimeAgo dateTime={user.created_at} /> | ||
</small> | ||
</span> | ||
<a href={authService.getAccountUrl()} target="_blank" title="Go to my profile page"> | ||
<img src={getRoboHash(user.hash, '48')} alt={user.username} /> | ||
</a> | ||
</div> | ||
) | ||
} | ||
|
||
export default UserInfos |
Oops, something went wrong.