added decline action for friend requests and room invites
This commit is contained in:
@@ -25,10 +25,22 @@ export async function apiFetch<T>(
|
||||
throw new Error("Session expired")
|
||||
}
|
||||
|
||||
// Handle error responses
|
||||
if (!res.ok) {
|
||||
const text = await res.text()
|
||||
throw new Error(text || res.statusText)
|
||||
}
|
||||
|
||||
return res.json() as Promise<T>
|
||||
// Get the response as text first
|
||||
const responseText = await res.text()
|
||||
|
||||
if (!responseText) {
|
||||
return {} as T
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(responseText) as T
|
||||
} catch (e) {
|
||||
return responseText as unknown as T
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,3 +22,10 @@ export function acceptFriendRequest(senderUuid: string) {
|
||||
body: JSON.stringify({ sender_uuid: senderUuid }),
|
||||
})
|
||||
}
|
||||
|
||||
export function declineFriendRequest(senderUuid: string) {
|
||||
return apiFetch<void>('/friends/decline', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ sender_uuid: senderUuid }),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -33,3 +33,10 @@ export function acceptRoomInvite(senderUuid: string, roomUuid: string) {
|
||||
body: JSON.stringify({ sender_uuid: senderUuid, room_uuid: roomUuid }),
|
||||
})
|
||||
}
|
||||
|
||||
export function declineRoomInvite(senderUuid: string, roomUuid: string) {
|
||||
return apiFetch<void>('/rooms/decline', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ sender_uuid: senderUuid, room_uuid: roomUuid }),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user