fix: user profile not rendering in top navbar

This commit is contained in:
Jordan Knott
2021-10-30 17:20:41 -05:00
parent 800dd2014c
commit cea99397db
17 changed files with 280 additions and 160 deletions

View File

@ -57,7 +57,7 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
fetch('/auth/logout', {
method: 'POST',
credentials: 'include',
}).then(async x => {
}).then(async (x) => {
const { status } = x;
if (status === 200) {
cache.reset();
@ -99,11 +99,11 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
showPopup(
$target,
<NotificationPopup>
{data.notifications.map(notification => (
{data.notifications.map((notification) => (
<NotificationItem
title={notification.entity.name}
description={`${notification.actor.name} added you as a meber to the task "${notification.entity.name}"`}
createdAt={notification.createdAt}
title={notification.notification.actionType}
description={`${notification.notification.causedBy.fullname} added you as a meber to the task "${notification.notification.actionType}"`}
createdAt={notification.notification.createdAt}
/>
))}
</NotificationPopup>,
@ -116,7 +116,7 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
// const userIsTeamOrProjectAdmin = user.isAdmin(PermissionLevel.TEAM, PermissionObjectType.TEAM, teamID);
const userIsTeamOrProjectAdmin = true;
const onInvitedMemberProfile = ($targetRef: React.RefObject<HTMLElement>, email: string) => {
const member = projectInvitedMembers ? projectInvitedMembers.find(u => u.email === email) : null;
const member = projectInvitedMembers ? projectInvitedMembers.find((u) => u.email === email) : null;
if (member) {
showPopup(
$targetRef,
@ -144,7 +144,7 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
};
const onMemberProfile = ($targetRef: React.RefObject<HTMLElement>, memberID: string) => {
const member = projectMembers ? projectMembers.find(u => u.id === memberID) : null;
const member = projectMembers ? projectMembers.find((u) => u.id === memberID) : null;
const warning =
'You cant leave because you are the only admin. To make another user an admin, click their avatar, select “Change permissions…”, and select “Admin”.';
if (member) {
@ -153,7 +153,7 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
<MiniProfile
warning={member.role && member.role.code === 'owner' ? warning : null}
canChangeRole={userIsTeamOrProjectAdmin}
onChangeRole={roleCode => {
onChangeRole={(roleCode) => {
if (onChangeRole) {
onChangeRole(member.id, roleCode);
}
@ -174,6 +174,12 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
}
};
if (data) {
console.log('HERE DATA');
console.log(data.me);
} else {
console.log('NO DATA');
}
const user = data ? data.me?.user : null;
return (
@ -181,7 +187,7 @@ const LoggedInNavbar: React.FC<GlobalTopNavbarProps> = ({
<TopNavbar
name={name}
menuType={menuType}
onOpenProjectFinder={$target => {
onOpenProjectFinder={($target) => {
showPopup(
$target,
<Popup tab={0} title={null}>

View File

@ -42,10 +42,6 @@ export enum ActivityType {
TaskChecklistRemoved = 'TASK_CHECKLIST_REMOVED'
}
export enum ActorType {
User = 'USER'
}
export type AddTaskLabelInput = {
taskID: Scalars['UUID'];
projectLabelID: Scalars['UUID'];
@ -268,10 +264,6 @@ export type DuplicateTaskGroupPayload = {
taskGroup: TaskGroup;
};
export enum EntityType {
Task = 'TASK'
}
export type FindProject = {
projectID: Scalars['UUID'];
};
@ -791,25 +783,31 @@ export type NewUserAccount = {
export type Notification = {
__typename?: 'Notification';
id: Scalars['ID'];
entity: NotificationEntity;
actionType: ActionType;
actor: NotificationActor;
read: Scalars['Boolean'];
causedBy: NotificationCausedBy;
data: Array<NotificationData>;
createdAt: Scalars['Time'];
};
export type NotificationActor = {
__typename?: 'NotificationActor';
id: Scalars['UUID'];
type: ActorType;
name: Scalars['String'];
export type NotificationCausedBy = {
__typename?: 'NotificationCausedBy';
fullname: Scalars['String'];
username: Scalars['String'];
id: Scalars['ID'];
};
export type NotificationEntity = {
__typename?: 'NotificationEntity';
id: Scalars['UUID'];
type: EntityType;
name: Scalars['String'];
export type NotificationData = {
__typename?: 'NotificationData';
key: Scalars['String'];
value: Scalars['String'];
};
export type Notified = {
__typename?: 'Notified';
id: Scalars['ID'];
notification: Notification;
read: Scalars['Boolean'];
readAt?: Maybe<Scalars['Time']>;
};
export enum ObjectType {
@ -902,7 +900,7 @@ export type Query = {
labelColors: Array<LabelColor>;
me?: Maybe<MePayload>;
myTasks: MyTasksPayload;
notifications: Array<Notification>;
notifications: Array<Notified>;
organizations: Array<Organization>;
projects: Array<Project>;
searchMembers: Array<MemberSearchResult>;
@ -995,6 +993,11 @@ export type SortTaskGroupPayload = {
tasks: Array<Task>;
};
export type Subscription = {
__typename?: 'Subscription';
notificationAdded: Notified;
};
export type Task = {
__typename?: 'Task';
id: Scalars['ID'];
@ -2355,14 +2358,15 @@ export type TopNavbarQueryVariables = Exact<{ [key: string]: never; }>;
export type TopNavbarQuery = (
{ __typename?: 'Query' }
& { notifications: Array<(
{ __typename?: 'Notification' }
& Pick<Notification, 'createdAt' | 'read' | 'id' | 'actionType'>
& { entity: (
{ __typename?: 'NotificationEntity' }
& Pick<NotificationEntity, 'id' | 'type' | 'name'>
), actor: (
{ __typename?: 'NotificationActor' }
& Pick<NotificationActor, 'id' | 'type' | 'name'>
{ __typename?: 'Notified' }
& Pick<Notified, 'id' | 'read' | 'readAt'>
& { notification: (
{ __typename?: 'Notification' }
& Pick<Notification, 'id' | 'actionType' | 'createdAt'>
& { causedBy: (
{ __typename?: 'NotificationCausedBy' }
& Pick<NotificationCausedBy, 'username' | 'fullname' | 'id'>
) }
) }
)>, me?: Maybe<(
{ __typename?: 'MePayload' }
@ -4819,20 +4823,19 @@ export type ToggleTaskLabelMutationOptions = Apollo.BaseMutationOptions<ToggleTa
export const TopNavbarDocument = gql`
query topNavbar {
notifications {
createdAt
read
id
entity {
read
readAt
notification {
id
type
name
actionType
causedBy {
username
fullname
id
}
createdAt
}
actor {
id
type
name
}
actionType
}
me {
user {
@ -5527,4 +5530,4 @@ export function useUsersLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<User
}
export type UsersQueryHookResult = ReturnType<typeof useUsersQuery>;
export type UsersLazyQueryHookResult = ReturnType<typeof useUsersLazyQuery>;
export type UsersQueryResult = Apollo.QueryResult<UsersQuery, UsersQueryVariables>;
export type UsersQueryResult = Apollo.QueryResult<UsersQuery, UsersQueryVariables>;

View File

@ -3,20 +3,19 @@ import gql from 'graphql-tag';
export const TOP_NAVBAR_QUERY = gql`
query topNavbar {
notifications {
createdAt
read
id
entity {
read
readAt
notification {
id
type
name
actionType
causedBy {
username
fullname
id
}
createdAt
}
actor {
id
type
name
}
actionType
}
me {
user {