diff --git a/frontend/dashboard/components/NewApplicationForm/NewApplicationForm.tsx b/frontend/dashboard/components/NewApplicationForm/NewApplicationForm.tsx index e3947330491..6a335bb0dcc 100644 --- a/frontend/dashboard/components/NewApplicationForm/NewApplicationForm.tsx +++ b/frontend/dashboard/components/NewApplicationForm/NewApplicationForm.tsx @@ -1,4 +1,4 @@ -import React, { type FormEvent, type ChangeEvent } from 'react'; +import React, { type FormEvent, type ChangeEvent, useState } from 'react'; import classes from './NewApplicationForm.module.css'; import { StudioButton, StudioSpinner } from '@studio/components'; import { useTranslation } from 'react-i18next'; @@ -11,6 +11,7 @@ import { SelectedContextType } from 'dashboard/context/HeaderContext'; import { type NewAppForm } from '../../types/NewAppForm'; import { useCreateAppFormValidation } from './hooks/useCreateAppFormValidation'; import { Link } from 'react-router-dom'; +import { useUserOrgPermissionQuery } from '../../hooks/queries/useUserOrgPermissionsQuery'; type CancelButton = { onClick: () => void; @@ -47,11 +48,14 @@ export const NewApplicationForm = ({ const { t } = useTranslation(); const selectedContext = useSelectedContext(); const { validateRepoOwnerName, validateRepoName } = useCreateAppFormValidation(); - const defaultSelectedOrgOrUser: string = selectedContext === SelectedContextType.Self || selectedContext === SelectedContextType.All ? user.login : selectedContext; + const [currentSelectedOrg, setCurrentSelectedOrg] = useState(defaultSelectedOrgOrUser); + const { data: userOrgPermission, isFetching } = useUserOrgPermissionQuery(currentSelectedOrg, { + enabled: Boolean(currentSelectedOrg), + }); const validateTextValue = (event: ChangeEvent) => { const { errorMessage: repoNameErrorMessage, isValid: isRepoNameValid } = validateRepoName( @@ -96,14 +100,22 @@ export const NewApplicationForm = ({ return isOrgValid && isRepoNameValid; }; + const createRepoAccessError = + !userOrgPermission?.canCreateOrgRepo && !isFetching + ? t('dashboard.missing_service_owner_rights_error_message') + : ''; + + const hasCreateRepoAccessError = Boolean(createRepoAccessError); + return (
) : ( <> - + {submitButtonText} diff --git a/frontend/dashboard/components/ServiceOwnerSelector/ServiceOwnerSelector.tsx b/frontend/dashboard/components/ServiceOwnerSelector/ServiceOwnerSelector.tsx index 80f89c6c80f..bf6cabc0e2c 100644 --- a/frontend/dashboard/components/ServiceOwnerSelector/ServiceOwnerSelector.tsx +++ b/frontend/dashboard/components/ServiceOwnerSelector/ServiceOwnerSelector.tsx @@ -10,6 +10,7 @@ export type ServiceOwnerSelectorProps = { organizations: Organization[]; errorMessage?: string; name?: string; + onChange?: (org: string) => void; }; export const ServiceOwnerSelector = ({ @@ -18,6 +19,7 @@ export const ServiceOwnerSelector = ({ organizations, errorMessage, name, + onChange, }: ServiceOwnerSelectorProps) => { const { t } = useTranslation(); const serviceOwnerId: string = useId(); @@ -38,6 +40,7 @@ export const ServiceOwnerSelector = ({ name={name} id={serviceOwnerId} defaultValue={defaultValue} + onChange={(event) => onChange(event.target.value)} > {selectableOptions.map(({ value, label }) => (