1717import React , { useEffect , useState } from 'react'
1818import { Switch , Route } from 'react-router-dom'
1919import { useDispatch , useSelector } from 'react-redux'
20-
20+ import {
21+ saveToPresignedBucket ,
22+ selectServiceToS3BucketMap ,
23+ } from '../settings/ducks'
2124import {
2225 fetchSettings ,
2326 fetchConfig ,
2427 updateConfig ,
25- saveToPresignedBucket ,
2628 selectAllSettings ,
2729 dismissError ,
2830 selectLoading ,
2931 selectConfig ,
3032 selectConfigLoading ,
3133 selectConfigError ,
3234 selectConfigMessage ,
33- createConfig ,
3435} from './ducks'
3536
3637import { ApplicationComponent } from './ApplicationComponent'
3738import { ConfirmModal } from './ConfirmModal'
38- import { selectDbOptions , selectOsOptions , selectDbUploadUrl } from '../options/ducks'
39+ import { selectDbOptions , selectOsOptions } from '../options/ducks'
3940import { fetchTenantsThunk , selectAllTenants } from '../tenant/ducks'
4041import { fetchTiersThunk , selectAllTiers } from '../tier/ducks'
4142
@@ -53,7 +54,8 @@ export function ApplicationContainer(props) {
5354 const configLoading = useSelector ( selectConfigLoading )
5455 const configMessage = useSelector ( selectConfigMessage )
5556 const configError = useSelector ( selectConfigError )
56- const dbUploadUrl = useSelector ( selectDbUploadUrl )
57+ const serviceToS3BucketMap = useSelector ( selectServiceToS3BucketMap )
58+
5759 const hasTenants = useSelector ( ( state ) => {
5860 return selectAllTenants ( state ) ?. length > 0
5961 } )
@@ -114,6 +116,21 @@ export function ApplicationContainer(props) {
114116 }
115117 } , [ dispatch ] )
116118
119+ useEffect ( ( ) => {
120+ Object . keys ( file ) . forEach ( ( fn ) => {
121+ const dbFile = file [ fn ]
122+ const url = serviceToS3BucketMap [ fn ]
123+ if ( dbFile && url ) {
124+ dispatch (
125+ saveToPresignedBucket ( {
126+ dbFile,
127+ url,
128+ } )
129+ )
130+ }
131+ } )
132+ } , [ serviceToS3BucketMap , appConfig , dispatch , file ] )
133+
117134 const presubmitCheck = ( values ) => {
118135 setFormValues ( values )
119136 if ( hasTenants ) {
@@ -143,16 +160,8 @@ export function ApplicationContainer(props) {
143160 return encryptedPw . substring ( 0 , 8 ) === pw
144161 }
145162
146- console . log ( "updateConfiguration!" )
147- console . log ( values )
148-
149163 try {
150- const {
151- services,
152- billing,
153- provisionBilling,
154- ...rest
155- } = values
164+ const { services, billing, provisionBilling, ...rest } = values
156165 let cleanedServicesMap = { }
157166 for ( var serviceIndex in services ) {
158167 let thisService = services [ serviceIndex ]
@@ -169,7 +178,11 @@ export function ApplicationContainer(props) {
169178 ...rest
170179 } = thisService . tiers [ tierName ]
171180 let { filesystemLifecycle, ...cleanedFs } = filesystem
172- let { weeklyMaintenanceDay, weeklyMaintenanceTime : time , ...cleanedFsx } = cleanedFs . fsx
181+ let {
182+ weeklyMaintenanceDay,
183+ weeklyMaintenanceTime : time ,
184+ ...cleanedFsx
185+ } = cleanedFs . fsx
173186 const weeklyTime = getFormattedTime ( time )
174187 const fsx = {
175188 ...cleanedFsx ,
@@ -180,13 +193,20 @@ export function ApplicationContainer(props) {
180193 efs : cleanedFs . fileSystemType === EFS ? cleanedFs . efs : null ,
181194 fsx : cleanedFs . fileSystemType === FSX ? fsx : null ,
182195 }
183- const { port, hasEncryptedPassword, encryptedPassword, ...restDb } = database
196+ const {
197+ port,
198+ hasEncryptedPassword,
199+ encryptedPassword,
200+ bootstrapFilename,
201+ ...restDb
202+ } = database
184203 // If we detected an encrypted password coming in, and it looks like they haven't changed it
185204 // then send the encrypted password back to the server. Otherwise send what they changed.
186205 const cleanedDb = {
187206 ...restDb ,
188207 password :
189- hasEncryptedPassword && isMatch ( restDb . password , encryptedPassword )
208+ hasEncryptedPassword &&
209+ isMatch ( restDb . password , encryptedPassword )
190210 ? encryptedPassword
191211 : restDb . password ,
192212 }
@@ -219,21 +239,14 @@ export function ApplicationContainer(props) {
219239 billing : provisionBilling ? billing : null ,
220240 services : cleanedServicesMap ,
221241 }
222-
223- // TODO this file is controlled as a single state and setter passed to all DB forms
224- // TODO also, the settings API implementation of the DB init file will need to change for multiple services as well
225- // if (!!file && file.name && provisionDb) {
226- // await dispatch(saveToPresignedBucket({ dbFile: file, url: dbUploadUrl }))
227- // }
228- console . log ( 'dispatching the following appConfig...' )
229- console . log ( configToSend )
230- await dispatch ( updateConfig ( configToSend ) )
242+ dispatch ( updateConfig ( configToSend ) )
231243 } catch ( e ) {
232244 console . error ( e )
233245 }
234246 }
235247
236- const handleFileSelected = ( file ) => {
248+ const handleFileSelected = ( newFile ) => {
249+ file [ newFile . serviceName ] = newFile . file
237250 setFile ( file )
238251 }
239252
@@ -262,7 +275,11 @@ export function ApplicationContainer(props) {
262275 settingsObj = { settingsObj }
263276 error = { configError }
264277 message = { configMessage }
265- loading = { loading === 'idle' && configLoading === 'idle' ? 'idle' : 'pending' }
278+ loading = {
279+ loading === 'idle' && configLoading === 'idle'
280+ ? 'idle'
281+ : 'pending'
282+ }
266283 updateConfiguration = { presubmitCheck }
267284 tiers = { tiers }
268285 { ...props }
0 commit comments