Skip to content

Commit

Permalink
#12 Show team invite list on front-end, implement invitation button
Browse files Browse the repository at this point in the history
* Add separate property in Convex function invitations and show in separate list in team dashboard
* Style chat input and implement enter press handler
  • Loading branch information
varunsingh87 committed Jan 17, 2024
1 parent dc2c1c9 commit b040fd4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 38 deletions.
44 changes: 27 additions & 17 deletions Components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { Button, Input, List } from 'reactstrap'
import React, { useState } from 'react'
import { Button, Container, Input, List } from 'reactstrap'
import React, { useState, KeyboardEvent } from 'react'
import { useMutation } from 'convex/react'
import { api } from '../convex/_generated/api'
import { Id } from '../convex/_generated/dataModel'
import { UserBubble } from './User'
import classnames from 'classnames'
import { UserBubble } from './User'

export default function Chat(props: { id: Id<'teams'>; messages: Array<any> }) {
const sendMessage = useMutation(api.team.sendMessage)
const [newMessage, setNewMessage] = useState('')

const handleMessageSend = () => {
if (!newMessage) return
setNewMessage('')
sendMessage({ teamId: props.id, message: newMessage })
}

const handleEnterPressed = (e: KeyboardEvent) => {
if (e.key === 'Enter') handleMessageSend()
}

return (
<>
<Container>
<h1>Team Chat</h1>
<List className="p-0 mt-2">
{props.messages.map((item) => (
Expand All @@ -28,18 +38,18 @@ export default function Chat(props: { id: Id<'teams'>; messages: Array<any> }) {
</li>
))}
</List>
<Input
type="text"
value={newMessage}
onChange={(e) => setNewMessage(e.target.value)}
/>
<Button
className="my-2"
color="primary"
onClick={() => sendMessage({ teamId: props.id, message: newMessage })}
>
Chat
</Button>
</>
<Container className="d-flex">
<Input
className="me-2 my-2"
type="text"
value={newMessage}
onChange={(e) => setNewMessage(e.target.value)}
onKeyDown={handleEnterPressed}
/>
<Button className="my-2" color="primary" onClick={handleMessageSend}>
Chat
</Button>
</Container>
</Container>
)
}
32 changes: 15 additions & 17 deletions Components/Teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ export default function Teams(props: any) {
setJoinButtonMessage('Join requested!')
}

const handleInviteClick = (
joinerId: Id<'users'>,
competitionId: Id<'competitions'>
) => {
invite({ joinerId, competitionId })
const handleInviteClick = (joinerId: Id<'users'>) => {
invite({ joinerId, competitionId: props.competitionId })
setInviteBtnMsg('Invite sent!')
}

Expand All @@ -44,6 +41,19 @@ export default function Teams(props: any) {
alt={'Profile picture of ' + member.name}
/>{' '}
{member.name}
<Button
className="ms-2"
color="primary"
hidden={
participant &&
participant.userMembership.team == item._id
}
onClick={() => {
handleInviteClick(member._id)
}}
>
{inviteButtonMessage}
</Button>
</ListInlineItem>
))}
</List>
Expand All @@ -59,18 +69,6 @@ export default function Teams(props: any) {
>
{joinButtonMessage}
</Button>
<Button
className="ms-2"
color="primary"
hidden={
participant && participant.userMembership.team == item._id
}
onClick={() => {
handleInviteClick
}}
>
{inviteButtonMessage}
</Button>
</li>
))}
</List>
Expand Down
4 changes: 3 additions & 1 deletion convex/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ export const inviteToTeam = mutation({
userConsent: false,
teamConsent: true,
})
return await db.replace(inviterTeam._id, inviterTeam)
return await db.patch(inviterTeam._id, {
joinRequests: inviterTeam.joinRequests,
})
case RequestValidity.REQUESTED:
return addUserToTeam(db, joiner, inviterTeam)
default:
Expand Down
3 changes: 2 additions & 1 deletion convex/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const get = query({
}
})
),
joinRequests,
joinRequests: joinRequests.filter((item) => item.userConsent),
invitations: joinRequests.filter((item) => item.teamConsent),
}
},
})
Expand Down
11 changes: 9 additions & 2 deletions pages/competitions/[id]/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ export default function Team(props: any) {
{teamInfo.joinRequests.map(request => (
<li className="border list-unstyled">
<UserBubble {...request.user} />
{request.teamConsent ? "Team Consent" : ""}
{request.userConsent ? "User Consent" : ""}
<Button onClick={() => handleAcceptJoin(request.user._id)}>Accept</Button>
</li>
))}
</List>
<h2>Pending Invitations</h2>
<List className="p-2">
{teamInfo.invitations.map(invitation => (
<li className="border list-unstyled">
<UserBubble {...invitation.user} />
{invitation.user.name}
</li>
))}
</List>
</Col>
</Row>
<Row>
Expand Down

0 comments on commit b040fd4

Please sign in to comment.