-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
feat(organizations): handle user removes itself flow TASK-1354 #5393
base: main
Are you sure you want to change the base?
feat(organizations): handle user removes itself flow TASK-1354 #5393
Conversation
@@ -119,11 +119,11 @@ export const useOrganizationQuery = (params?: OrganizationQueryParams) => { | |||
// the session data loaded. Account data is needed to fetch the organization | |||
// data. | |||
|
|||
const query = useQuery<Organization, FailResponse, Organization, QueryKeys[]>({ | |||
const query = useQuery<Organization, FailResponse, Organization, string[]>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but note to self: do we need to specify angle brackets here, or can we get better type safety and readability by leaving this blank and fixing types upstream of it?
- 📚 reference: "Type-safe React Query # About angle brackets"
Skimmed, will test soon. |
15bae53
to
f0541cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review inline, not tested. Also:
- the title is confusing to have both "feat" and "fix" keywords in it, how about "feat(organizations): handle user removes itself flow" or similar?
if (params?.isRemovingSelf) { | ||
session.refreshAccount(); | ||
} else { | ||
queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing self should skip invalidation? 🤔
Even if removing self invalidates it indirectly, AFAIK multiple invalidations are batched, so let's keep it simple and with a clearer intent.
if (params?.isRemovingSelf) { | |
session.refreshAccount(); | |
} else { | |
queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); | |
} | |
queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); | |
if (params?.isRemovingSelf) { | |
session.refreshAccount(); | |
} |
onSettled: () => { | ||
queryClient.invalidateQueries({queryKey: [QueryKeys.organizationMembers]}); | ||
if (params?.isRemovingSelf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this hook can be simplified by removing the isRemovingSelf
parameter and accessing variables within onSettled
instead.
onSettled: (_data, _error, username) => {
if (session.currentLoggedAccount?.username === username) {
fetchDelete(getMemberEndpoint(orgId!, username)) | ||
), | ||
return fetchDelete(getMemberEndpoint(orgId!, username)); | ||
}, | ||
onSettled: () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps use onSuccess
instead? It would be confusing to get logged out on a failure to remove oneself.
@@ -12,6 +12,8 @@ import envStore from 'jsapp/js/envStore'; | |||
import subscriptionStore from 'jsapp/js/account/subscriptionStore'; | |||
import {useRemoveOrganizationMember} from './membersQuery'; | |||
import {notify} from 'alertifyjs'; | |||
import {ROUTES} from 'jsapp/js/router/routerConstants'; | |||
import router from 'jsapp/js/router/router'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused imports
@@ -18,6 +18,11 @@ import {OrganizationUserRole} from './organizationQuery'; | |||
|
|||
// Styles | |||
import styles from './memberActionsDropdown.module.scss'; | |||
import {queryClient} from 'jsapp/js/query/queryClient'; | |||
import {QueryKeys} from 'jsapp/js/query/queryKeys'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple minor notes. On testing, I see the remaining issues from usage, but this is certainly an improvement. I will test again once you go through Kalvis' requested changes.
🗒️ Checklist
<type>(<scope>)<!>: <title> TASK-1234
frontend
orbackend
unless it's global📣 Summary
The navigation and data flow is improved when an MMO organization admin removes itself from the organization.
📖 Description
The objective of this PR is to:
There's still a big margin for improving, mainly due to some work needed in
useUsage
, but it unfolds into several other files and flows, so it's better to be handled in a separated PR👀 Preview steps