Skip to content

Commit

Permalink
LOGIN
Browse files Browse the repository at this point in the history
  • Loading branch information
xdzqyyds committed Dec 4, 2024
1 parent 7c9ca60 commit 0b47a10
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
28 changes: 17 additions & 11 deletions webapp/components/window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ interface InviteWindowProps {
inviteeId: string
}

interface Invitation {
value: string;
}

export default function InviteWindow({ inviteeId }: InviteWindowProps) {
const [invitation, setInvitation] = useState<string | null>(null)
const [invitation, setInvitation] = useState<Invitation | null>(null)
const [isOpen, setIsOpen] = useState(false)
const [_, setLoc] = useAtom(locationAtom)
const [__, setAtomMeetingId] = useAtom(meetingIdAtom)

type invitation = { value: string }

const checkInvitation = async () => {
try {
const value = await getInvitation(inviteeId)
Expand All @@ -24,7 +26,9 @@ export default function InviteWindow({ inviteeId }: InviteWindowProps) {
setInvitation(value)
setIsOpen(true)
}
} catch { /* empty */ }
} catch (error) {
console.error('Failed to check invitation:', error)
}
}

useEffect(() => {
Expand All @@ -35,12 +39,14 @@ export default function InviteWindow({ inviteeId }: InviteWindowProps) {

const handleAccept = () => {
console.log('Accepted the invitation')
const invitationValue = invitation?.value
const roomId = invitationValue.split(' ')[0]
setStorageMeeting(roomId)
setAtomMeetingId(roomId)
setLoc(prev => ({ ...prev, pathname: `/${roomId}` }))
setIsOpen(false)
if (invitation) {
const invitationValue = invitation.value
const roomId = invitationValue.split(' ')[0]
setStorageMeeting(roomId)
setAtomMeetingId(roomId)
setLoc(prev => ({ ...prev, pathname: `/${roomId}` }))
setIsOpen(false)
}
}

const handleReject = () => {
Expand All @@ -54,7 +60,7 @@ export default function InviteWindow({ inviteeId }: InviteWindowProps) {
<div className="fixed top-4 right-4 bg-white p-4 rounded-lg shadow-lg max-w-xs w-64">
<h3 className="font-bold mb-2">You have an invitation!</h3>
<p className="mb-4">
{invitation.value}
{invitation.value} {/* 直接访问 value */}
</p>
<div className="flex justify-between space-x-4">
<button
Expand Down
5 changes: 4 additions & 1 deletion webapp/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ async function sendInvite(meetingId: string, inviterId: string, inviteeId: strin
})).json()
}

async function getInvitation(inviteeId: string): Promise<string | null> {
interface InvitationResponse {
value: string;
}
async function getInvitation(inviteeId: string): Promise<InvitationResponse | null> {
return (await fetch('/login/invitee', {
method: 'PATCH',
headers: {
Expand Down

0 comments on commit 0b47a10

Please sign in to comment.