mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Show errors when trying to redeem invites by yourself or by profiles you are already following
This commit is contained in:
parent
68fb201907
commit
f85ce81e30
@ -72,22 +72,36 @@ export function InvitePage({ inviteApi, itemsApi }: Props) {
|
||||
|
||||
if (!invitingProfileId) {
|
||||
toast.error('Invalid invite code')
|
||||
setValidationDone(true)
|
||||
navigate('/')
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
toast.error('Inviting profile not found')
|
||||
setValidationDone(true)
|
||||
navigate('/')
|
||||
return
|
||||
}
|
||||
|
||||
setInvitingProfile(invitingProfile)
|
||||
setValidationDone(true)
|
||||
}
|
||||
|
||||
if (!id) throw new Error('Invite ID is required')
|
||||
@ -101,7 +115,10 @@ export function InvitePage({ inviteApi, itemsApi }: Props) {
|
||||
localStorage.setItem('inviteCode', id)
|
||||
}
|
||||
|
||||
if (!isMyProfileLoaded) return
|
||||
|
||||
void validateInvite(id)
|
||||
setValidationDone(true)
|
||||
}, [
|
||||
id,
|
||||
isAuthenticated,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user