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

Use app context in organizationLogic too #6565

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion frontend/src/scenes/organizationLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { organizationLogicType } from './organizationLogicType'
import { AvailableFeature, OrganizationType } from '~/types'
import { toast } from 'react-toastify'
import { userLogic } from './userLogic'
import { getAppContext } from '../lib/utils/getAppContext'

type OrganizationUpdatePayload = Partial<
Pick<OrganizationType, 'name' | 'personalization' | 'domain_whitelist' | 'is_member_join_email_enabled'>
Expand Down Expand Up @@ -80,6 +81,16 @@ export const organizationLogic = kea<organizationLogicType<OrganizationUpdatePay
},
}),
events: ({ actions }) => ({
afterMount: [actions.loadCurrentOrganization],
afterMount: () => {
const appContext = getAppContext()
const contextualOrganization = appContext?.current_user?.organization
if (contextualOrganization) {
// If app context is available (it should be practically always) we can immediately know currentOrganization
actions.loadCurrentOrganizationSuccess(contextualOrganization)
} else {
// If app context is not available, a traditional request is needed
actions.loadCurrentOrganization()
}
},
}),
})
5 changes: 3 additions & 2 deletions frontend/src/scenes/teamLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ export const teamLogic = kea<teamLogicType>({
events: ({ actions }) => ({
afterMount: () => {
const appContext = getAppContext()
if (appContext) {
const contextualTeam = appContext?.current_team
if (contextualTeam) {
// If app context is available (it should be practically always) we can immediately know currentTeam
actions.loadCurrentTeamSuccess(appContext.current_team)
actions.loadCurrentTeamSuccess(contextualTeam)
} else {
// If app context is not available, a traditional request is needed
actions.loadCurrentTeam()
Expand Down