@@ -16,16 +16,20 @@ import {
1616import {
1717 Form ,
1818 FormControl ,
19+ FormDescription ,
1920 FormField ,
2021 FormItem ,
22+ FormLabel ,
2123 FormMessage ,
2224} from "@/components/ui/form" ;
25+ import { Switch } from "@/components/ui/switch" ;
2326import { Toggle } from "@/components/ui/toggle" ;
2427import { api } from "@/utils/api" ;
2528import type { ServiceType } from "../advanced/show-resources" ;
2629
2730const addEnvironmentSchema = z . object ( {
2831 environment : z . string ( ) ,
32+ createEnvFile : z . boolean ( ) ,
2933} ) ;
3034
3135type EnvironmentSchema = z . infer < typeof addEnvironmentSchema > ;
@@ -71,18 +75,32 @@ export const ShowEnvironment = ({ id, type }: Props) => {
7175 const form = useForm < EnvironmentSchema > ( {
7276 defaultValues : {
7377 environment : "" ,
78+ createEnvFile : true ,
7479 } ,
7580 resolver : zodResolver ( addEnvironmentSchema ) ,
7681 } ) ;
7782
7883 // Watch form value
7984 const currentEnvironment = form . watch ( "environment" ) ;
80- const hasChanges = currentEnvironment !== ( data ?. env || "" ) ;
85+ const currentCreateEnvFile = form . watch ( "createEnvFile" ) ;
86+ const composeData =
87+ type === "compose"
88+ ? ( data as { createEnvFile ?: boolean ; sourceType ?: string } | undefined )
89+ : undefined ;
90+
91+ const showCreateEnvFileToggle =
92+ type === "compose" &&
93+ ( composeData ?. sourceType !== "raw" || composeData ?. createEnvFile === false ) ;
94+ const hasChanges =
95+ currentEnvironment !== ( data ?. env || "" ) ||
96+ ( showCreateEnvFileToggle &&
97+ currentCreateEnvFile !== ( composeData ?. createEnvFile ?? true ) ) ;
8198
8299 useEffect ( ( ) => {
83100 if ( data ) {
84101 form . reset ( {
85102 environment : data . env || "" ,
103+ createEnvFile : composeData ?. createEnvFile ?? true ,
86104 } ) ;
87105 }
88106 } , [ data , form ] ) ;
@@ -97,6 +115,9 @@ export const ShowEnvironment = ({ id, type }: Props) => {
97115 postgresId : id || "" ,
98116 redisId : id || "" ,
99117 env : formData . environment ,
118+ ...( type === "compose" && {
119+ createEnvFile : formData . createEnvFile ,
120+ } ) ,
100121 } )
101122 . then ( async ( ) => {
102123 toast . success ( "Environments Added" ) ;
@@ -110,6 +131,7 @@ export const ShowEnvironment = ({ id, type }: Props) => {
110131 const handleCancel = ( ) => {
111132 form . reset ( {
112133 environment : data ?. env || "" ,
134+ createEnvFile : composeData ?. createEnvFile ?? true ,
113135 } ) ;
114136 } ;
115137
@@ -190,6 +212,33 @@ PORT=3000
190212 ) }
191213 />
192214
215+ { showCreateEnvFileToggle && (
216+ < FormField
217+ control = { form . control }
218+ name = "createEnvFile"
219+ render = { ( { field } ) => (
220+ < FormItem className = "flex flex-row items-center justify-between p-3 border rounded-lg shadow-xs" >
221+ < div className = "space-y-0.5" >
222+ < FormLabel > Create Environment File</ FormLabel >
223+ < FormDescription >
224+ When enabled, an .env file will be created in the same
225+ directory as your compose file on every deploy.
226+ Disable this if you don't want to generate an
227+ environment file.
228+ </ FormDescription >
229+ </ div >
230+ < FormControl >
231+ < Switch
232+ checked = { field . value }
233+ onCheckedChange = { field . onChange }
234+ disabled = { ! canWrite }
235+ />
236+ </ FormControl >
237+ </ FormItem >
238+ ) }
239+ />
240+ ) }
241+
193242 { canWrite && (
194243 < div className = "flex flex-row justify-end gap-2" >
195244 { hasChanges && (
0 commit comments