@@ -52,26 +52,37 @@ import { useOrganization } from "~/hooks/useOrganizations";
5252import { useHasAdminAccess } from "~/hooks/useUser" ;
5353import { redirectWithErrorMessage , redirectWithSuccessMessage } from "~/models/message.server" ;
5454import { findProjectBySlug } from "~/models/project.server" ;
55+ import { findEnvironmentBySlug } from "~/models/runtimeEnvironment.server" ;
5556import { type Region , RegionsPresenter } from "~/presenters/v3/RegionsPresenter.server" ;
5657import { requireUser } from "~/services/session.server" ;
5758import {
5859 docsPath ,
5960 EnvironmentParamSchema ,
60- ProjectParamSchema ,
6161 regionsPath ,
6262 v3BillingPath ,
6363} from "~/utils/pathBuilder" ;
6464import { SetDefaultRegionService } from "~/v3/services/setDefaultRegion.server" ;
6565
6666export const loader = async ( { request, params } : LoaderFunctionArgs ) => {
6767 const user = await requireUser ( request ) ;
68- const { projectParam } = ProjectParamSchema . parse ( params ) ;
68+ const { organizationSlug, projectParam, envParam } = EnvironmentParamSchema . parse ( params ) ;
69+
70+ const project = await findProjectBySlug ( organizationSlug , projectParam , user . id ) ;
71+ if ( ! project ) {
72+ throw new Response ( undefined , { status : 404 , statusText : "Project not found" } ) ;
73+ }
74+
75+ const environment = await findEnvironmentBySlug ( project . id , envParam , user . id ) ;
76+ if ( ! environment ) {
77+ throw new Response ( undefined , { status : 404 , statusText : "Environment not found" } ) ;
78+ }
6979
7080 const presenter = new RegionsPresenter ( ) ;
7181 const [ error , result ] = await tryCatch (
7282 presenter . call ( {
7383 userId : user . id ,
7484 projectSlug : projectParam ,
85+ environmentId : environment . id ,
7586 isAdmin : user . admin || user . isImpersonating ,
7687 } )
7788 ) ;
@@ -106,6 +117,11 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
106117 throw redirectWithErrorMessage ( redirectPath , request , "Project not found" ) ;
107118 }
108119
120+ const environment = await findEnvironmentBySlug ( project . id , envParam , user . id ) ;
121+ if ( ! environment ) {
122+ throw redirectWithErrorMessage ( redirectPath , request , "Environment not found" ) ;
123+ }
124+
109125 const formData = await request . formData ( ) ;
110126 const parsedFormData = FormSchema . safeParse ( Object . fromEntries ( formData ) ) ;
111127
@@ -116,7 +132,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
116132 const service = new SetDefaultRegionService ( ) ;
117133 const [ error , result ] = await tryCatch (
118134 service . call ( {
119- projectId : project . id ,
135+ environmentId : environment . id ,
120136 regionId : parsedFormData . data . regionId ,
121137 isAdmin : user . admin || user . isImpersonating ,
122138 } )
0 commit comments