@@ -822,9 +822,15 @@ function ConnectedVercelProjectForm({
822822 hasPreviewEnvironment
823823 ) ;
824824
825+ const hasVercelCustomEnvironments = customEnvironments . length > 0 ;
826+
825827 const disabledEnvSlugsForBuildSettings : Partial < Record < EnvSlug , string > > | undefined =
826828 hasStagingEnvironment && ! configValues . vercelStagingEnvironment
827- ? { stg : "Set a Vercel environment for Staging first." }
829+ ? {
830+ stg : hasVercelCustomEnvironments
831+ ? "Set a Vercel environment for Staging first."
832+ : "Add a custom environment to this project in Vercel to use Staging." ,
833+ }
828834 : undefined ;
829835
830836 return (
@@ -935,60 +941,68 @@ function ConnectedVercelProjectForm({
935941 ref = { clearTriggerVersionInputRef }
936942 />
937943
938- { /* Staging environment mapping */ }
939- { hasStagingEnvironment && customEnvironments && customEnvironments . length > 0 && (
944+ { hasStagingEnvironment && (
940945 < SettingsRow
941946 title = "Vercel environment for Staging"
942947 description = "Required to enable the Staging options below."
943948 action = {
944- < div data-unlock-target = "staging-env" >
945- < Select
946- value = { configValues . vercelStagingEnvironment ?. environmentId || "" }
947- setValue = { ( value ) => {
948- if ( ! Array . isArray ( value ) ) {
949- const env = customEnvironments ?. find ( ( e ) => e . id === value ) ;
950- setConfigValues ( ( prev ) => {
951- const next = {
952- ...prev ,
953- vercelStagingEnvironment : env
954- ? { environmentId : env . id , displayName : env . slug }
955- : null ,
956- } ;
957- // When clearing the staging mapping, strip "stg" from build settings
958- if ( ! env ) {
959- next . pullEnvVarsBeforeBuild = prev . pullEnvVarsBeforeBuild . filter (
960- ( s ) => s !== "stg"
961- ) ;
962- next . discoverEnvVars = prev . discoverEnvVars . filter ( ( s ) => s !== "stg" ) ;
963- }
964- return next ;
965- } ) ;
949+ ! hasVercelCustomEnvironments ? (
950+ < Paragraph variant = "extra-small" className = "w-64" >
951+ This Vercel project has no custom environments. Add one in Vercel under Settings{ " " }
952+ → Environments, then reload this page.
953+ </ Paragraph >
954+ ) : (
955+ < div data-unlock-target = "staging-env" >
956+ < Select
957+ value = { configValues . vercelStagingEnvironment ?. environmentId || "" }
958+ setValue = { ( value ) => {
959+ if ( ! Array . isArray ( value ) ) {
960+ const env = customEnvironments ?. find ( ( e ) => e . id === value ) ;
961+ setConfigValues ( ( prev ) => {
962+ const next = {
963+ ...prev ,
964+ vercelStagingEnvironment : env
965+ ? { environmentId : env . id , displayName : env . slug }
966+ : null ,
967+ } ;
968+ // When clearing the staging mapping, strip "stg" from build settings
969+ if ( ! env ) {
970+ next . pullEnvVarsBeforeBuild = prev . pullEnvVarsBeforeBuild . filter (
971+ ( s ) => s !== "stg"
972+ ) ;
973+ next . discoverEnvVars = prev . discoverEnvVars . filter ( ( s ) => s !== "stg" ) ;
974+ }
975+ return next ;
976+ } ) ;
977+ }
978+ } }
979+ items = { [ { id : "" , slug : "None" } , ...customEnvironments ] }
980+ variant = "secondary/small"
981+ placeholder = "Select environment"
982+ dropdownIcon
983+ text = {
984+ configValues . vercelStagingEnvironment ? (
985+ < StagingEnvOption
986+ name = { configValues . vercelStagingEnvironment . displayName }
987+ />
988+ ) : (
989+ "None"
990+ )
966991 }
967- } }
968- items = { [ { id : "" , slug : "None" } , ...customEnvironments ] }
969- variant = "secondary/small"
970- placeholder = "Select environment"
971- dropdownIcon
972- text = {
973- configValues . vercelStagingEnvironment ? (
974- < StagingEnvOption name = { configValues . vercelStagingEnvironment . displayName } />
975- ) : (
976- "None"
977- )
978- }
979- >
980- { [
981- < SelectItem key = "" value = "" >
982- < span className = "text-text-bright" > None</ span >
983- </ SelectItem > ,
984- ...customEnvironments . map ( ( env ) => (
985- < SelectItem key = { env . id } value = { env . id } >
986- < StagingEnvOption name = { env . slug } />
987- </ SelectItem >
988- ) ) ,
989- ] }
990- </ Select >
991- </ div >
992+ >
993+ { [
994+ < SelectItem key = "" value = "" >
995+ < span className = "text-text-bright" > None</ span >
996+ </ SelectItem > ,
997+ ...customEnvironments . map ( ( env ) => (
998+ < SelectItem key = { env . id } value = { env . id } >
999+ < StagingEnvOption name = { env . slug } />
1000+ </ SelectItem >
1001+ ) ) ,
1002+ ] }
1003+ </ Select >
1004+ </ div >
1005+ )
9921006 }
9931007 />
9941008 ) }
0 commit comments