Skip to content

Commit

Permalink
fix(organizations: remove invite params on accept/decline TASK-1582 (#…
Browse files Browse the repository at this point in the history
…5535)

### 📣 Summary
Remove relevant search params when a user accepts or declines an MMO
invite
  • Loading branch information
jamesrkiger authored Feb 18, 2025
1 parent 93e73f2 commit cfea6e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion jsapp/js/account/organization/invites/OrgInviteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { endpoints } from 'jsapp/js/api.endpoints'
*
* Note: this is for a user that is NOT a part of an organization (and thus has no access to it).
*/
export default function OrgInviteModal(props: { orgId: string; inviteId: string }) {
export default function OrgInviteModal(props: { orgId: string; inviteId: string; onUserResponse: () => void }) {
const inviteUrl = endpoints.ORG_MEMBER_INVITE_DETAIL_URL.replace(':organization_id', props.orgId).replace(
':invite_id',
props.inviteId,
Expand All @@ -46,6 +46,7 @@ export default function OrgInviteModal(props: { orgId: string; inviteId: string
try {
await patchMemberInvite.mutateAsync({ status: MemberInviteStatus.declined })
setIsModalOpen(false)
props.onUserResponse()
notify(t('Invitation successfully declined'))
} catch (error) {
setMiscError(t('Unknown error while trying to update an invitation'))
Expand All @@ -56,6 +57,7 @@ export default function OrgInviteModal(props: { orgId: string; inviteId: string
try {
await patchMemberInvite.mutateAsync({ status: MemberInviteStatus.accepted })
setIsModalOpen(false)
props.onUserResponse()
notify(t('Invitation successfully accepted'))
} catch (error) {
setMiscError(t('Unknown error while trying to update an invitation'))
Expand Down
18 changes: 11 additions & 7 deletions jsapp/js/account/organization/invites/OrgInviteModalWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { useLocation } from 'react-router-dom'
import { useSearchParams } from 'react-router-dom'
import OrgInviteModal from './OrgInviteModal'

/**
* This is a wrapper for conditionally rendering the OrgInviteModal component. It simply looks for particular pair of
* search parameters.
* This is a wrapper for conditionally rendering the OrgInviteModal component. It looks for a particular pair of
* search parameters to pass to the modal. Also, if an invitation is deleted or accepted, it removes those params.
*/
export default function OrgInviteModalWrapper() {
// Get values from URL params
const location = useLocation()
const searchParams = new URLSearchParams(location.search)
const [searchParams, setSearchParams] = useSearchParams()
const inviteId = searchParams.get('organization_invite')
const orgId = searchParams.get('organization_id')

function handleUserResponse() {
searchParams.delete('organization_invite')
searchParams.delete('organization_id')
setSearchParams(searchParams)
}

// Avoid rendering anything if there is no invite in the URL
if (!inviteId || !orgId) {
return null
}

return <OrgInviteModal orgId={orgId} inviteId={inviteId} />
return <OrgInviteModal orgId={orgId} inviteId={inviteId} onUserResponse={handleUserResponse} />
}

0 comments on commit cfea6e4

Please sign in to comment.