Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ba 2114 add members to existing group #206

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @baseapp-frontend/components

## 1.0.10

### Patch Changes

- Enable adding a member to an existing group
- Refactor member and contacts list into a reusable component
- Updated dependencies
- @baseapp-frontend/design-system@1.0.5

## 1.0.9

### Patch Changes
Expand Down
255 changes: 255 additions & 0 deletions packages/components/__generated__/ActivityLogsFragment.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { FC, useRef, useState, useTransition } from 'react'

import { AvatarWithPlaceholder } from '@baseapp-frontend/design-system/components/web/avatars'

import { Typography } from '@mui/material'
import { useRefetchableFragment } from 'react-relay'
import { AvatarWithPlaceholder } from '@baseapp-frontend/design-system/components/web/avatars'

import { CommentItemRefetchQuery } from '../../../../__generated__/CommentItemRefetchQuery.graphql'
import { CommentItem_comment$key } from '../../../../__generated__/CommentItem_comment.graphql'
Expand Down
7 changes: 7 additions & 0 deletions packages/components/modules/messages/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ export const MESSAGE_TYPE = {
user: 'USER_MESSAGE',
system: 'SYSTEM_GENERATED',
} as const

export const CHAT_ROOM_PARTICIPANT_ROLES = {
admin: 'ADMIN',
member: 'MEMBER',
} as const

export const ADMIN_LABEL = 'Admin'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const RoomTitleFragment = graphql`
url
}
}
role
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/components/modules/messages/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ValueOf } from '@baseapp-frontend/utils'

import { MessagesListFragment$data } from '../../../__generated__/MessagesListFragment.graphql'
import { MESSAGE_TYPE } from './constants'
import { CHAT_ROOM_PARTICIPANT_ROLES, MESSAGE_TYPE } from './constants'

export type AllMessages = NonNullable<MessagesListFragment$data['allMessages']>
export type MessageEdges = AllMessages['edges']
export type MessageNode = NonNullable<MessageEdges[number]>['node']

export type MessageTypeOptions = ValueOf<typeof MESSAGE_TYPE>

export type ChatRoomParticipantRoles = ValueOf<typeof CHAT_ROOM_PARTICIPANT_ROLES>
23 changes: 21 additions & 2 deletions packages/components/modules/messages/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import ConnectionHandler from 'relay-connection-handler-plus'
import { RecordProxy, RecordSourceSelectorProxy, Variables } from 'relay-runtime'

import { GroupTitleFragment$key } from '../../../__generated__/GroupTitleFragment.graphql'
import { MembersListFragment$data } from '../../../__generated__/MembersListFragment.graphql'
import { RoomTitleFragment$key } from '../../../__generated__/RoomTitleFragment.graphql'
import { TitleFragment$data } from '../../../__generated__/TitleFragment.graphql'
import { CHAT_ROOM_PARTICIPANT_ROLES } from './constants'
import { GroupTitleFragment } from './graphql/fragments/GroupTitle'
import { RoomTitleFragment } from './graphql/fragments/RoomTitle'

export const useGroupNameAndAvatar = (headerRef: GroupTitleFragment$key | null | undefined) => {
const header = useFragment<GroupTitleFragment$key>(GroupTitleFragment, headerRef)
export const useGroupNameAndAvatar = (
headerRef: GroupTitleFragment$key | RoomTitleFragment$key | null | undefined,
) => {
const header = useFragment<GroupTitleFragment$key>(
GroupTitleFragment,
headerRef as GroupTitleFragment$key,
)
return {
title: header?.title,
avatar: header?.image?.url,
Expand All @@ -26,6 +33,7 @@ const useRoomNameAndAvatar = (headerRef: RoomTitleFragment$key | null | undefine
title: 'Error: No participants',
}
}

const otherParticipant = header.participants.edges.find(
(edge) => edge?.node?.profile?.id && edge?.node?.profile?.id !== currentProfile?.id,
)
Expand Down Expand Up @@ -60,3 +68,14 @@ export const getChatRoomConnections: (
}
return []
}

export const useCheckIsAdmin = (participants: MembersListFragment$data['participants']) => {
const { currentProfile } = useCurrentProfile()
const me = participants?.edges?.find((edge) => edge?.node?.profile?.id === currentProfile?.id)
const isAdmin = me?.node?.role === CHAT_ROOM_PARTICIPANT_ROLES.admin
const isSoleAdmin =
isAdmin &&
participants?.edges?.filter((edge) => edge?.node?.role === CHAT_ROOM_PARTICIPANT_ROLES.admin)
.length === 1
return { isAdmin, isSoleAdmin }
}
Loading
Loading