Skip to content

Commit

Permalink
invite
Browse files Browse the repository at this point in the history
  • Loading branch information
xdzqyyds committed Dec 2, 2024
1 parent a24c047 commit 12bbc5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
37 changes: 37 additions & 0 deletions webapp/components/Invite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useState } from 'react'
import { sendInvite } from '../lib/api'

interface InviteProps {
meetingId: string;
inviterId: string;
inviteeId: string;
}

export default function Invite({ meetingId, inviterId, inviteeId }: InviteProps) {
const [isInvited, setIsInvited] = useState<boolean>(false)

const handleInvite = async () => {
try {
const response = await sendInvite(meetingId, inviterId, inviteeId)
if (response.success) {
setIsInvited(true)
console.log('Invite sent successfully')
} else {
console.error('Failed to send invite')
}
} catch (error) {
console.error('Error sending invite:', error)
}
}

return (
<div>
<button
onClick={handleInvite}
className={`bg-blue-500 text-white p-2 rounded-md ${isInvited ? 'bg-green-500' : ''}`}
>
{isInvited ? 'Invited' : 'Invite'}
</button>
</div>
)
}
15 changes: 15 additions & 0 deletions webapp/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ async function updateUserStatus(userId: string, status: string): Promise<void> {
})
}

async function sendInvite(meetingId: string, inviterId: string, inviteeId: string): Promise<{ success: boolean; message: string }> {
return (await fetch('/invite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
meetingId,
inviterId,
inviteeId,
}),
})).json()
}


export {
setRoomId,
Expand All @@ -167,6 +181,7 @@ export {
login,
getUserOnlineStatus,
updateUserStatus,
sendInvite,

StreamState,
}
Expand Down

0 comments on commit 12bbc5c

Please sign in to comment.