@@ -15,7 +15,7 @@ import {
15
15
useConfigurePeriodicBackup ,
16
16
} from "api/backups" ;
17
17
import { useCurrentProject } from "api/projects" ;
18
- import { useId , useState } from "react" ;
18
+ import { useId , useMemo , useState } from "react" ;
19
19
import {
20
20
DeploymentResponse ,
21
21
Team ,
@@ -266,6 +266,13 @@ export function BackupScheduleSelector({
266
266
const [ minutesUtc , hoursUtc , , , dayOfWeekPart = "*" ] = parts ;
267
267
const isWeekly = dayOfWeekPart !== "*" ;
268
268
const dayOfWeekNum = isWeekly ? Number ( dayOfWeekPart ) : null ;
269
+ const defaultDayOfWeek = useMemo (
270
+ ( ) =>
271
+ // We randomize the default day of week to spread out the backups
272
+ // of users that don’t specify a custom time
273
+ Math . floor ( Math . random ( ) * 7 ) ,
274
+ [ ] ,
275
+ ) ;
269
276
const date = new Date ( ) ;
270
277
date . setUTCHours ( + hoursUtc , + minutesUtc ) ;
271
278
@@ -312,7 +319,7 @@ export function BackupScheduleSelector({
312
319
< BackupScheduleSelectorInner
313
320
defaultValue = { date }
314
321
defaultPeriodicity = { isWeekly ? "weekly" : "daily" }
315
- defaultDayOfWeek = { dayOfWeekNum }
322
+ defaultDayOfWeek = { dayOfWeekNum ?? defaultDayOfWeek }
316
323
onClose = { close }
317
324
deployment = { deployment }
318
325
/>
@@ -330,7 +337,7 @@ export function BackupScheduleSelectorInner({
330
337
} : {
331
338
defaultValue : Date ;
332
339
defaultPeriodicity : "daily" | "weekly" ;
333
- defaultDayOfWeek : number | null ;
340
+ defaultDayOfWeek : number ;
334
341
onClose : ( ) => void ;
335
342
deployment : DeploymentResponse ;
336
343
} ) {
@@ -344,13 +351,7 @@ export function BackupScheduleSelectorInner({
344
351
const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
345
352
346
353
const [ periodicity , setPeriodicity ] = useState ( defaultPeriodicity ) ;
347
- const [ selectedDow , setSelectedDow ] = useState (
348
- ( ) =>
349
- defaultDayOfWeek ??
350
- // We randomize the default day of week to spread out the backups
351
- // of users that don’t specify a custom time
352
- Math . floor ( Math . random ( ) * 7 ) ,
353
- ) ;
354
+ const [ selectedDow , setSelectedDow ] = useState ( defaultDayOfWeek ) ;
354
355
355
356
return (
356
357
< form
0 commit comments