Show errors when trying to redeem invites by yourself or by profiles you are already following

This commit is contained in:
Maximilian Harz 2025-12-04 00:42:12 +01:00
parent 68fb201907
commit f85ce81e30

View File

@ -72,22 +72,36 @@ export function InvitePage({ inviteApi, itemsApi }: Props) {
if (!invitingProfileId) { if (!invitingProfileId) {
toast.error('Invalid invite code') toast.error('Invalid invite code')
setValidationDone(true)
navigate('/') navigate('/')
return return
} }
const invitingProfile = await itemsApi.getItem(invitingProfileId) const invitingProfile = await itemsApi.getItem(invitingProfileId)
if (invitingProfileId === myProfile?.id) {
toast.error('You cannot invite yourself')
// Navigate to own profile
navigate('/item/' + myProfile.id)
return
}
if (
myProfile?.relations?.some(
(r) => r.type === 'is_following' && r.related_items_id === invitingProfileId,
)
) {
toast.error('You are already following this profile')
navigate('/item/' + invitingProfileId)
return
}
if (!invitingProfile) { if (!invitingProfile) {
toast.error('Inviting profile not found') toast.error('Inviting profile not found')
setValidationDone(true)
navigate('/') navigate('/')
return return
} }
setInvitingProfile(invitingProfile) setInvitingProfile(invitingProfile)
setValidationDone(true)
} }
if (!id) throw new Error('Invite ID is required') if (!id) throw new Error('Invite ID is required')
@ -101,7 +115,10 @@ export function InvitePage({ inviteApi, itemsApi }: Props) {
localStorage.setItem('inviteCode', id) localStorage.setItem('inviteCode', id)
} }
if (!isMyProfileLoaded) return
void validateInvite(id) void validateInvite(id)
setValidationDone(true)
}, [ }, [
id, id,
isAuthenticated, isAuthenticated,