11import { useSandboxEnvironments } from "@features/settings/hooks/useSandboxEnvironments" ;
22import { useSettingsDialogStore } from "@features/settings/stores/settingsDialogStore" ;
33import { PencilSimple , Plus , Trash } from "@phosphor-icons/react" ;
4+ import { ChevronDownIcon } from "@radix-ui/react-icons" ;
45import {
56 Badge ,
67 Button ,
@@ -10,8 +11,11 @@ import {
1011 TextArea ,
1112 TextField ,
1213} from "@radix-ui/themes" ;
13- import { ChevronDownIcon } from "@radix-ui/react-icons" ;
14- import type { NetworkAccessLevel , SandboxEnvironment } from "@shared/types" ;
14+ import type {
15+ NetworkAccessLevel ,
16+ SandboxEnvironment ,
17+ SandboxEnvironmentInput ,
18+ } from "@shared/types" ;
1519import { useCallback , useEffect , useMemo , useState } from "react" ;
1620import { toast } from "sonner" ;
1721
@@ -37,14 +41,18 @@ const NETWORK_ACCESS_OPTIONS: {
3741 } ,
3842] ;
3943
40- const DOMAIN_RE = / ^ ( \* \. ) ? [ a - z A - Z 0 - 9 ] ( [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? ( \. [ a - z A - Z 0 - 9 ] ( [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? ) * $ / ;
44+ const DOMAIN_RE =
45+ / ^ ( \* \. ) ? [ a - z A - Z 0 - 9 ] ( [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? ( \. [ a - z A - Z 0 - 9 ] ( [ a - z A - Z 0 - 9 - ] * [ a - z A - Z 0 - 9 ] ) ? ) * $ / ;
4146const ENV_KEY_RE = / ^ [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * $ / ;
4247
4348function isValidDomain ( domain : string ) : boolean {
4449 return DOMAIN_RE . test ( domain ) ;
4550}
4651
47- function validateDomains ( text : string ) : { domains : string [ ] ; errors : string [ ] } {
52+ function validateDomains ( text : string ) : {
53+ domains : string [ ] ;
54+ errors : string [ ] ;
55+ } {
4856 const domains : string [ ] = [ ] ;
4957 const errors : string [ ] = [ ] ;
5058 for ( const line of text . split ( "\n" ) ) {
@@ -161,7 +169,10 @@ function NetworkAccessSelect({
161169 className = "flex w-full cursor-pointer flex-col gap-0 border-0 bg-transparent px-3 py-2 text-left transition-colors hover:bg-gray-3 data-[active]:bg-accent-4"
162170 data-active = { opt . value === value || undefined }
163171 >
164- < Text size = "2" weight = { opt . value === value ? "medium" : undefined } >
172+ < Text
173+ size = "2"
174+ weight = { opt . value === value ? "medium" : undefined }
175+ >
165176 { opt . label }
166177 </ Text >
167178 < Text size = "1" color = "gray" >
@@ -202,7 +213,8 @@ export function CloudEnvironmentsSettings() {
202213 const isFormOpen = isCreating || editingEnv !== null ;
203214
204215 const domainValidation = useMemo ( ( ) => {
205- if ( form . network_access_level !== "custom" ) return { domains : [ ] , errors : [ ] } ;
216+ if ( form . network_access_level !== "custom" )
217+ return { domains : [ ] , errors : [ ] } ;
206218 return validateDomains ( form . allowed_domains_text ) ;
207219 } , [ form . network_access_level , form . allowed_domains_text ] ) ;
208220
@@ -237,25 +249,22 @@ export function CloudEnvironmentsSettings() {
237249 return ;
238250 }
239251
240- const payload : Record < string , unknown > = {
252+ const payload : SandboxEnvironmentInput = {
241253 name : form . name ,
242254 network_access_level : form . network_access_level ,
243255 allowed_domains :
244- form . network_access_level === "custom"
245- ? domainValidation . domains
246- : [ ] ,
256+ form . network_access_level === "custom" ? domainValidation . domains : [ ] ,
247257 include_default_domains :
248258 form . network_access_level === "custom"
249259 ? form . include_default_domains
250260 : false ,
251261 private : form . private ,
252262 repositories : [ ] ,
263+ ...( form . environment_variables_text . trim ( )
264+ ? { environment_variables : envVarValidation . vars }
265+ : { } ) ,
253266 } ;
254267
255- if ( form . environment_variables_text . trim ( ) ) {
256- payload . environment_variables = envVarValidation . vars ;
257- }
258-
259268 if ( editingEnv ) {
260269 await updateMutation . mutateAsync ( { id : editingEnv . id , ...payload } ) ;
261270 } else {
0 commit comments