Skip to content

Commit

Permalink
feat(setup-wizard): Allow project creation (#83811)
Browse files Browse the repository at this point in the history
Allow creating Sentry projects in the setup wizard workflow.
It is only enabled if the wizard passes the `project_platform` URL param
which is used to define the projects platform.

- part of getsentry/sentry-wizard#549
  • Loading branch information
ArthurKnaus authored Jan 22, 2025
1 parent 45ce4c3 commit da017ea
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 44 deletions.
5 changes: 5 additions & 0 deletions static/app/views/setupWizard/utils/features.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {Organization} from 'sentry/types/organization';

export function hasSetupWizardCreateProjectFeature(organization: Organization) {
return organization.features.includes('setup-wizard-create-project');
}
28 changes: 28 additions & 0 deletions static/app/views/setupWizard/utils/useCreateProjectFromWizard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {Project} from 'sentry/types/project';
import {useMutation} from 'sentry/utils/queryClient';
import useApi from 'sentry/utils/useApi';
import type {OrganizationWithRegion} from 'sentry/views/setupWizard/types';

export function useCreateProjectFromWizard() {
const api = useApi();
return useMutation({
mutationFn: (params: {
name: string;
organization: OrganizationWithRegion;
platform: string;
team: string;
}): Promise<Project> => {
const url = `/teams/${params.organization.slug}/${params.team}/projects/`;
return api.requestPromise(url, {
method: 'POST',
host: params.organization.region.url,
data: {
name: params.name,
platform: params.platform,
default_rules: true,
origin: 'ui',
},
});
},
});
}
28 changes: 28 additions & 0 deletions static/app/views/setupWizard/utils/useOrganizationDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {Organization} from 'sentry/types/organization';
import {useQuery} from 'sentry/utils/queryClient';
import type RequestError from 'sentry/utils/requestError/requestError';
import useApi from 'sentry/utils/useApi';
import type {OrganizationWithRegion} from 'sentry/views/setupWizard/types';

export function useOrganizationDetails({
organization,
}: {
organization?: OrganizationWithRegion;
}) {
const api = useApi();

return useQuery<Organization, RequestError>({
queryKey: [`/organizations/${organization?.slug}/`],
queryFn: () => {
return api.requestPromise(`/organizations/${organization?.slug}/`, {
host: organization?.region.url,
query: {
include_feature_flags: 1,
},
});
},
enabled: !!organization,
refetchOnWindowFocus: true,
retry: false,
});
}
25 changes: 25 additions & 0 deletions static/app/views/setupWizard/utils/useOrganizationTeams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {Team} from 'sentry/types/organization';
import {useQuery} from 'sentry/utils/queryClient';
import type RequestError from 'sentry/utils/requestError/requestError';
import useApi from 'sentry/utils/useApi';
import type {OrganizationWithRegion} from 'sentry/views/setupWizard/types';

export function useOrganizationTeams({
organization,
}: {
organization?: OrganizationWithRegion;
}) {
const api = useApi();

return useQuery<Team[], RequestError>({
queryKey: [`/organizations/${organization?.slug}/teams/`],
queryFn: () => {
return api.requestPromise(`/organizations/${organization?.slug}/teams/`, {
host: organization?.region.url,
});
},
enabled: !!organization,
refetchOnWindowFocus: true,
retry: false,
});
}
Loading

0 comments on commit da017ea

Please sign in to comment.