Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2051 - Enhance the logic handling 'Already-joined group' error #2273

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions frontend/views/pages/Join.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ export default ({
return
}
if (this.ourIdentityContractId) {
const myGroupIds = Object.keys(this.$store.state[this.ourIdentityContractId]?.groups || {})
const targetGroupId = this.ephemeral.hash?.get('groupId') || ''
const targetGroupState = this.$store.state[targetGroupId] || {}

if (this.currentGroupId && [PROFILE_STATUS.ACTIVE, PROFILE_STATUS.PENDING].includes(targetGroupState?.profiles?.[this.ourIdentityContractId])) {
this.goToDashboard()
} else if (myGroupIds.includes(targetGroupId)) { // if the user is already part of the target group.
} else if (this.checkAlreadyJoinedGroup(targetGroupId)) { // if the user is already part of the target group.
this.ephemeral.groupInfo = {
name: targetGroupState.settings?.groupName || '',
id: targetGroupId
Expand Down Expand Up @@ -187,6 +186,12 @@ export default ({
goHome () {
this.$router.push({ path: '/' })
},
checkAlreadyJoinedGroup (targetGroupId) {
if (this.ourIdentityContractId) {
const myGroupIds = Object.keys(this.$store.state[this.ourIdentityContractId]?.groups || {})
return myGroupIds.includes(targetGroupId)
} else return false
},
goToDashboard (toGroupId) {
if (toGroupId && this.currentGroupId !== toGroupId) {
sbp('gi.app/group/switch', toGroupId)
Expand All @@ -209,7 +214,18 @@ export default ({
} catch (e) {
console.error('Join.vue accept() error:', e)
this.ephemeral.errorMsg = e.message
this.pageStatus = 'INVALID'

const alreadyJoinedErr = this.checkAlreadyJoinedGroup(groupId)
this.pageStatus = alreadyJoinedErr ? 'JOINED' : 'INVALID'
if (alreadyJoinedErr) {
// if errored by attempting to join an already-joined group, show a different UI informing it.
const targetGroupState = this.$store.state[groupId] || {}

this.ephemeral.groupInfo = {
name: targetGroupState.settings?.groupName || '',
id: groupId
}
}
}
}
}
Expand Down
Loading