Skip to content

Commit a3ba828

Browse files
committed
feat: make SingleChatCreate customizable
1 parent fa34489 commit a3ba828

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+228
-117
lines changed

packages/components/modules/messages/web/ChatRoomsComponent/index.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { GroupDetailsQuery as GroupDetailsQueryType } from '../../../../__genera
1010
import { GroupDetailsQuery, useChatRoom } from '../../common'
1111
import DefaultAllChatRoomsList from '../AllChatRoomsList'
1212
import ChatRoom from '../ChatRoom'
13-
import DefaultGroupChatRoomCreate from '../GroupChatRoomCreate'
14-
import DefaultGroupChatRoomDetails from '../GroupChatRoomDetail'
15-
import DefaultGroupChatRoomEdit from '../GroupChatRoomEdit'
16-
import DefaultSingleChatRoomCreate from '../SingleChatRoomCreate'
13+
import DefaultGroupChatCreate from '../GroupChatCreate'
14+
import DefaultGroupChatDetails from '../GroupChatDetails'
15+
import DefaultGroupChatEdit from '../GroupChatEdit'
16+
import DefaultSingleChatCreate from '../SingleChatCreate'
1717
import { LEFT_PANEL_CONTENT, LeftPanelContentValues } from './constants'
1818
import { ChatRoomContainer, ChatRoomsContainer, ChatRoomsListContainer } from './styled'
1919
import { ChatRoomsComponentProps } from './types'
@@ -23,14 +23,14 @@ const ChatRoomsComponent: FC<ChatRoomsComponentProps> = ({
2323
settings,
2424
AllChatRoomsListComponent = DefaultAllChatRoomsList,
2525
AllChatRoomsListComponentProps = {},
26-
GroupChatRoomCreateComponent = DefaultGroupChatRoomCreate,
27-
GroupChatRoomCreateComponentProps = {},
28-
GroupChatRoomDetailsComponent = DefaultGroupChatRoomDetails,
29-
GroupChatRoomDetailsComponentProps = {},
30-
GroupChatRoomEditComponent = DefaultGroupChatRoomEdit,
31-
GroupChatRoomEditComponentProps = {},
32-
SingleChatRoomCreateComponent = DefaultSingleChatRoomCreate,
33-
SingleChatRoomCreateComponentProps = {},
26+
GroupChatCreateComponent = DefaultGroupChatCreate,
27+
GroupChatCreateComponentProps = {},
28+
GroupChatDetailsComponent = DefaultGroupChatDetails,
29+
GroupChatDetailsComponentProps = {},
30+
GroupChatEditComponent = DefaultGroupChatEdit,
31+
GroupChatEditComponentProps = {},
32+
SingleChatCreateComponent = DefaultSingleChatCreate,
33+
SingleChatCreateComponentProps = {},
3434
}) => {
3535
const isUpToMd = useResponsive('up', 'md')
3636
const [leftPanelContent, setLeftPanelContent] = useState<LeftPanelContentValues>(
@@ -57,46 +57,46 @@ const ChatRoomsComponent: FC<ChatRoomsComponentProps> = ({
5757
switch (leftPanelContent) {
5858
case LEFT_PANEL_CONTENT.createGroupChat:
5959
return (
60-
<GroupChatRoomCreateComponent
60+
<GroupChatCreateComponent
6161
allProfilesRef={chatRoomsQueryData}
6262
onValidSubmission={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)}
6363
onBackButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.createChat)}
64-
{...GroupChatRoomCreateComponentProps}
64+
{...GroupChatCreateComponentProps}
6565
/>
6666
)
6767
case LEFT_PANEL_CONTENT.editGroupChat:
6868
if (!groupDetailsQueryRef) return null
6969
return (
70-
<GroupChatRoomEditComponent
70+
<GroupChatEditComponent
7171
onCancellation={() => setLeftPanelContent(LEFT_PANEL_CONTENT.groupDetails)}
7272
onRemovalFromGroup={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)}
7373
onValidSubmission={() => setLeftPanelContent(LEFT_PANEL_CONTENT.groupDetails)}
7474
queryRef={groupDetailsQueryRef}
7575
roomId={selectedRoom}
7676
allProfilesRef={chatRoomsQueryData}
77-
{...GroupChatRoomEditComponentProps}
77+
{...GroupChatEditComponentProps}
7878
/>
7979
)
8080
case LEFT_PANEL_CONTENT.groupDetails:
8181
if (!groupDetailsQueryRef) return null
8282
return (
83-
<GroupChatRoomDetailsComponent
83+
<GroupChatDetailsComponent
8484
queryRef={groupDetailsQueryRef}
8585
onBackButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)}
8686
onEditButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.editGroupChat)}
87-
{...GroupChatRoomDetailsComponentProps}
87+
{...GroupChatDetailsComponentProps}
8888
/>
8989
)
9090
case LEFT_PANEL_CONTENT.createChat:
9191
return (
92-
<SingleChatRoomCreateComponent
92+
<SingleChatCreateComponent
9393
allProfilesRef={chatRoomsQueryData}
9494
onHeaderClick={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)}
9595
onChatCreation={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)}
9696
onGroupChatCreationButtonClicked={() =>
9797
setLeftPanelContent(LEFT_PANEL_CONTENT.createGroupChat)
9898
}
99-
{...SingleChatRoomCreateComponentProps}
99+
{...SingleChatCreateComponentProps}
100100
/>
101101
)
102102
default:

packages/components/modules/messages/web/ChatRoomsComponent/types.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { BoxProps } from '@mui/material'
44

55
import { ChatRoomsQuery$data } from '../../../../__generated__/ChatRoomsQuery.graphql'
66
import { AllChatRoomsListProps } from '../AllChatRoomsList/types'
7-
import { GroupChatRoomCreateProps } from '../GroupChatRoomCreate/types'
8-
import { GroupChatRoomDetailProps } from '../GroupChatRoomDetail/types'
9-
import { GroupChatRoomEditProps } from '../GroupChatRoomEdit/types'
10-
import { SingleChatRoomCreateProps } from '../SingleChatRoomCreate/types'
7+
import { GroupChatCreateProps } from '../GroupChatCreate/types'
8+
import { GroupChatDetailsProps } from '../GroupChatDetails/types'
9+
import { GroupChatEditProps } from '../GroupChatEdit/types'
10+
import { SingleChatCreateProps } from '../SingleChatCreate/types'
1111

1212
export interface HidableContainerProps extends BoxProps {
1313
hide: boolean
@@ -18,12 +18,12 @@ export interface ChatRoomsComponentProps {
1818
settings: any
1919
AllChatRoomsListComponent?: FC<AllChatRoomsListProps>
2020
AllChatRoomsListComponentProps?: Partial<AllChatRoomsListProps>
21-
GroupChatRoomCreateComponent?: FC<GroupChatRoomCreateProps>
22-
GroupChatRoomCreateComponentProps?: Partial<GroupChatRoomCreateProps>
23-
GroupChatRoomEditComponent?: FC<GroupChatRoomEditProps>
24-
GroupChatRoomEditComponentProps?: Partial<GroupChatRoomEditProps>
25-
GroupChatRoomDetailsComponent?: FC<GroupChatRoomDetailProps>
26-
GroupChatRoomDetailsComponentProps?: Partial<GroupChatRoomDetailProps>
27-
SingleChatRoomCreateComponent?: FC<SingleChatRoomCreateProps>
28-
SingleChatRoomCreateComponentProps?: Partial<SingleChatRoomCreateProps>
21+
GroupChatCreateComponent?: FC<GroupChatCreateProps>
22+
GroupChatCreateComponentProps?: Partial<GroupChatCreateProps>
23+
GroupChatDetailsComponent?: FC<GroupChatDetailsProps>
24+
GroupChatDetailsComponentProps?: Partial<GroupChatDetailsProps>
25+
GroupChatEditComponent?: FC<GroupChatEditProps>
26+
GroupChatEditComponentProps?: Partial<GroupChatEditProps>
27+
SingleChatCreateComponent?: FC<SingleChatCreateProps>
28+
SingleChatCreateComponentProps?: Partial<SingleChatCreateProps>
2929
}

packages/components/modules/messages/web/GroupChatRoomCreate/index.tsx packages/components/modules/messages/web/GroupChatCreate/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {
2222
import { CreateOrEditGroup } from '../__shared__/types'
2323
import Header from './Header'
2424
import { ProfilesContainer } from './styled'
25-
import { GroupChatRoomCreateProps } from './types'
25+
import { GroupChatCreateProps } from './types'
2626

27-
const GroupChatRoomCreate: FC<GroupChatRoomCreateProps> = ({
27+
const GroupChatCreate: FC<GroupChatCreateProps> = ({
2828
allProfilesRef,
2929
GroupChatMembersList = DefaultGroupChatMembersList,
3030
GroupChatMembersListProps = {},
@@ -162,4 +162,4 @@ const GroupChatRoomCreate: FC<GroupChatRoomCreateProps> = ({
162162
)
163163
}
164164

165-
export default GroupChatRoomCreate
165+
export default GroupChatCreate

packages/components/modules/messages/web/GroupChatRoomCreate/types.ts packages/components/modules/messages/web/GroupChatCreate/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FC, PropsWithChildren } from 'react'
33
import { ChatRoomsQuery$data } from '../../../../__generated__/ChatRoomsQuery.graphql'
44
import { GroupChatMembersListProps } from '../__shared__/GroupChatMembersList/types'
55

6-
export interface GroupChatRoomCreateProps extends PropsWithChildren {
6+
export interface GroupChatCreateProps extends PropsWithChildren {
77
allProfilesRef: ChatRoomsQuery$data
88
GroupChatMembersList?: FC<GroupChatMembersListProps>
99
GroupChatMembersListProps?: Partial<GroupChatMembersListProps>

packages/components/modules/messages/web/GroupChatRoomDetail/index.tsx packages/components/modules/messages/web/GroupChatDetails/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import DefaultBody from './Body'
2424
import DefaultHeader from './Header'
2525
import DefaultProfileCard from './ProfileCard'
2626
import { GroupMembersEdge } from './ProfileCard/types'
27-
import { GroupChatRoomDetailProps } from './types'
27+
import { GroupChatDetailsProps } from './types'
2828

29-
const GroupChatRoomDetail: FC<GroupChatRoomDetailProps> = ({
29+
const GroupChatDetails: FC<GroupChatDetailsProps> = ({
3030
onBackButtonClicked,
3131
onEditButtonClicked,
3232
queryRef,
@@ -144,7 +144,7 @@ const GroupChatRoomDetail: FC<GroupChatRoomDetailProps> = ({
144144
)
145145
}
146146

147-
const SuspendedGroupDetails: FC<GroupChatRoomDetailProps> = ({
147+
const SuspendedGroupDetails: FC<GroupChatDetailsProps> = ({
148148
onBackButtonClicked,
149149
Header = DefaultHeader,
150150
HeaderProps = {},
@@ -164,7 +164,7 @@ const SuspendedGroupDetails: FC<GroupChatRoomDetailProps> = ({
164164
</>
165165
}
166166
>
167-
<GroupChatRoomDetail onBackButtonClicked={onBackButtonClicked} {...props} />
167+
<GroupChatDetails onBackButtonClicked={onBackButtonClicked} {...props} />
168168
</Suspense>
169169
)
170170

packages/components/modules/messages/web/GroupChatRoomDetail/types.ts packages/components/modules/messages/web/GroupChatDetails/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BodyProps } from './Body/types'
88
import { HeaderProps } from './Header/types'
99
import { ProfileCardProps } from './ProfileCard/types'
1010

11-
export type GroupChatRoomDetailProps = {
11+
export type GroupChatDetailsProps = {
1212
onBackButtonClicked: () => void
1313
onEditButtonClicked: () => void
1414
queryRef: PreloadedQuery<GroupDetailsQueryType>

packages/components/modules/messages/web/GroupChatRoomEdit/index.tsx packages/components/modules/messages/web/GroupChatEdit/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import AddMembersDialog from './AddMembersDialog'
3131
import AddMembersMobile from './AddMembersMobile'
3232
import { DEFAULT_FORM_VALIDATION, getDefaultFormValues } from './constants'
3333
import { HeaderContainer } from './styled'
34-
import { GroupChatRoomEditProps } from './types'
34+
import { GroupChatEditProps } from './types'
3535

36-
const GroupChatRoomEdit: FC<GroupChatRoomEditProps & { profileId: string }> = ({
36+
const GroupChatEdit: FC<GroupChatEditProps & { profileId: string }> = ({
3737
profileId,
3838
allProfilesRef,
3939
queryRef,
@@ -218,12 +218,12 @@ const GroupChatRoomEdit: FC<GroupChatRoomEditProps & { profileId: string }> = ({
218218
)
219219
}
220220

221-
const WrappedEditGroup: FC<GroupChatRoomEditProps> = (props) => {
221+
const WrappedEditGroup: FC<GroupChatEditProps> = (props) => {
222222
const { currentProfile } = useCurrentProfile()
223223
if (!currentProfile?.id) {
224224
return null
225225
}
226-
return <GroupChatRoomEdit profileId={currentProfile.id} {...props} />
226+
return <GroupChatEdit profileId={currentProfile.id} {...props} />
227227
}
228228

229229
export default WrappedEditGroup

packages/components/modules/messages/web/GroupChatRoomEdit/types.ts packages/components/modules/messages/web/GroupChatEdit/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ChatRoomsQuery$data } from '../../../../__generated__/ChatRoomsQuery.gr
66
import { GroupDetailsQuery } from '../../../../__generated__/GroupDetailsQuery.graphql'
77
import { GroupChatMembersListProps } from '../__shared__/GroupChatMembersList/types'
88

9-
export interface GroupChatRoomEditProps extends PropsWithChildren {
9+
export interface GroupChatEditProps extends PropsWithChildren {
1010
allProfilesRef: ChatRoomsQuery$data
1111
queryRef: PreloadedQuery<GroupDetailsQuery>
1212
roomId: string | undefined
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use client'
2+
3+
import { FC } from 'react'
4+
5+
import { AvatarButton } from '@baseapp-frontend/design-system/components/web/buttons'
6+
import { NewGroupIcon } from '@baseapp-frontend/design-system/components/web/icons'
7+
import { Searchbar as DefaultSearchbar } from '@baseapp-frontend/design-system/components/web/inputs'
8+
9+
import { MainContainer, SearchbarContainer } from './styled'
10+
import { BodyProps } from './types'
11+
12+
const Body: FC<BodyProps> = ({
13+
children,
14+
control,
15+
handleSearchChange,
16+
handleSearchClear,
17+
isPending,
18+
onGroupChatCreationButtonClicked,
19+
Searchbar = DefaultSearchbar,
20+
SearchbarProps = {},
21+
}) => (
22+
<MainContainer>
23+
<SearchbarContainer>
24+
<Searchbar
25+
name="search"
26+
onChange={handleSearchChange}
27+
onClear={handleSearchClear}
28+
control={control}
29+
isPending={isPending}
30+
{...SearchbarProps}
31+
/>
32+
</SearchbarContainer>
33+
<AvatarButton
34+
onClick={onGroupChatCreationButtonClicked}
35+
caption="New Group"
36+
Icon={NewGroupIcon}
37+
/>
38+
{children}
39+
</MainContainer>
40+
)
41+
42+
export default Body

packages/components/modules/messages/web/SingleChatRoomCreate/styled.tsx packages/components/modules/messages/web/SingleChatCreate/Body/styled.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,3 @@ export const GroupChatContainer: ComponentType<BoxProps> = styled(Box)(({ theme
2828
padding: `${theme.spacing(1.5)} ${theme.spacing(1.5)}`,
2929
},
3030
}))
31-
32-
export const Header: ComponentType<BoxProps> = styled(Box)(({ theme }) => ({
33-
borderBottom: `1px ${theme.palette.divider} solid`,
34-
width: '100%',
35-
padding: `${theme.spacing(2)}`,
36-
[theme.breakpoints.down('sm')]: {
37-
padding: `${theme.spacing(2)} ${theme.spacing(1.5)} ${theme.spacing(2)}`,
38-
},
39-
}))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ChangeEventHandler, PropsWithChildren } from 'react'
2+
3+
import { SearchbarProps } from '@baseapp-frontend/design-system/components/web/inputs'
4+
5+
export interface BodyProps extends PropsWithChildren {
6+
control: any
7+
handleSearchChange: ChangeEventHandler<HTMLInputElement>
8+
handleSearchClear: () => void
9+
isPending: boolean
10+
onGroupChatCreationButtonClicked: () => void
11+
// TODO: type this better
12+
Searchbar: any
13+
SearchbarProps?: Partial<SearchbarProps>
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use client'
2+
3+
import { FC } from 'react'
4+
5+
import { IconButton } from '@baseapp-frontend/design-system/components/web/buttons'
6+
import { Iconify } from '@baseapp-frontend/design-system/components/web/images'
7+
8+
import { Box, Typography } from '@mui/material'
9+
10+
import { HeaderContainer } from './styled'
11+
12+
const Header: FC<{ onHeaderClick: () => void }> = ({ onHeaderClick }) => (
13+
<HeaderContainer>
14+
<Box
15+
display="grid"
16+
width="100%"
17+
gridTemplateColumns="24px auto 24px"
18+
gap={1.5}
19+
alignItems="center"
20+
>
21+
<IconButton
22+
aria-label="return to existing chat rooms"
23+
onClick={onHeaderClick}
24+
sx={{ maxWidth: 'fit-content' }}
25+
>
26+
<Iconify icon="eva:arrow-ios-back-fill" width={24} />
27+
</IconButton>
28+
<Typography component="span" variant="subtitle2" sx={{ textAlign: 'center' }}>
29+
New Chat
30+
</Typography>
31+
<div />
32+
</Box>
33+
</HeaderContainer>
34+
)
35+
36+
export default Header
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ComponentType } from 'react'
2+
3+
import { Box, BoxProps } from '@mui/material'
4+
import { styled } from '@mui/material/styles'
5+
6+
export const HeaderContainer: ComponentType<BoxProps> = styled(Box)(({ theme }) => ({
7+
borderBottom: `1px ${theme.palette.divider} solid`,
8+
width: '100%',
9+
padding: `${theme.spacing(2)}`,
10+
[theme.breakpoints.down('sm')]: {
11+
padding: `${theme.spacing(2)} ${theme.spacing(1.5)} ${theme.spacing(2)}`,
12+
},
13+
}))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface HeaderProps {
2+
onHeaderClick: () => void
3+
}

0 commit comments

Comments
 (0)