()
| 226 | }, [session?.user, inviteId, token]) |
| 227 | |
| 228 | const handleAcceptInvitation = async () => { |
| 229 | if (!session?.user || !invitation) return |
| 230 | setIsAccepting(true) |
| 231 | |
| 232 | try { |
| 233 | const data = await requestJson(acceptInvitationContract, { |
| 234 | params: { id: inviteId }, |
| 235 | body: { token: token ?? undefined }, |
| 236 | }) |
| 237 | |
| 238 | if (invitation.organizationId) { |
| 239 | try { |
| 240 | await client.organization.setActive({ organizationId: invitation.organizationId }) |
| 241 | } catch (setActiveError) { |
| 242 | logger.warn('Failed to set active organization after accept', setActiveError) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | await Promise.all([ |
| 247 | queryClient.invalidateQueries({ queryKey: subscriptionKeys.all }), |
| 248 | queryClient.invalidateQueries({ queryKey: organizationKeys.all }), |
| 249 | ]) |
| 250 | |
| 251 | setAccepted(true) |
| 252 | setIsAccepting(false) |
| 253 | |
| 254 | setTimeout(() => router.push(data.redirectPath), 1200) |
| 255 | } catch (acceptError) { |
| 256 | logger.error('Error accepting invitation:', acceptError) |
| 257 | const code = |
| 258 | acceptError instanceof ApiClientError |
| 259 | ? codeFromApiClientError(acceptError) |
| 260 | : 'network-error' |
| 261 | setError(getInviteError(code)) |
| 262 | setIsAccepting(false) |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | const getCallbackUrl = () => { |
| 267 | const effectiveToken = |
no test coverage detected