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

fix(projects): reload organization after project creation #18198

Merged
merged 3 commits into from
Oct 27, 2023
Merged
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
2 changes: 2 additions & 0 deletions frontend/src/scenes/project/CreateProjectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function CreateProjectModal({
inline?: boolean
}): JSX.Element {
const { createTeam } = useActions(teamLogic)
const { loadCurrentOrganization } = useActions(organizationLogic)
const { currentOrganization } = useValues(organizationLogic)
const { reportProjectCreationSubmitted } = useActions(eventUsageLogic)
const [name, setName] = useState<string>('')
Expand All @@ -31,6 +32,7 @@ export function CreateProjectModal({
const handleSubmit = (): void => {
createTeam({ name, is_demo: false })
reportProjectCreationSubmitted(currentOrganization?.teams ? currentOrganization.teams.length : 0, name.length)
loadCurrentOrganization()
Copy link
Member

@Twixes Twixes Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this is a race condition, because we are calling the non-blocking version of createTeam earlier. We could use useAsyncActions(organizationLogic) for it instead, and then call await createTeam(...) in this function, so that by the time we call loadCurrentOrganization(), we're sure that the new project actually exists by now.

However, this code basically connects two logics – it really belongs in the logics. This way if we ever call createTeam anywhere else, we won't have to remember about loadCurrentOrganization().
Let's call loadCurrentOrganization via a listener in teamLogic. Specifically, it should be a createTeamSuccess listener (every Kea loader action has *Success and *Failure companions, which are fired when loading finishes).

closeModal()
}

Expand Down
Loading