Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

fix: resolve source & storage field resetting issue on plan creation screen

towfiqi8946878da9b7
diff --git a/frontend/src/components/Plan/PlanSettings/PlanSourceSettings.tsx b/frontend/src/components/Plan/PlanSettings/PlanSourceSettings.tsx
index 06d36eb..ae9a386 100644
--- a/frontend/src/components/Plan/PlanSettings/PlanSourceSettings.tsx
+++ b/frontend/src/components/Plan/PlanSettings/PlanSourceSettings.tsx
@@ -1,4 +1,4 @@
-import { useEffect } from 'react';
+import { useEffect, useRef } from 'react';
import classes from './PlanSettings.module.scss';
import PathPicker from '../../common/PathPicker/PathPicker';
import { NewPlanSettings } from '../../../@types/plans';
@@ -28,9 +28,16 @@ const PlanSourceSettings = ({ plan, onUpdate, error, isEditing }: PlanSourceSett
);
}
- // When the device changes, reset the sourceConfig paths to prevent invalid paths from being submitted
+ // When the device changes, reset the sourceConfig paths to prevent invalid paths from being submitted.
+ // Use a ref to track the previous deviceId so we only reset on an actual change (not on mount/remount,
+ // e.g. when navigating between steps in the Add Plan form).
+ const prevDeviceIdRef = useRef<string | null>(null);
useEffect(() => {
- if (!isEditing) {
+ if (isEditing) {
+ prevDeviceIdRef.current = deviceId;
+ return;
+ }
+ if (prevDeviceIdRef.current !== null && prevDeviceIdRef.current !== deviceId) {
onUpdate({
...plan,
sourceConfig: {
@@ -39,6 +46,7 @@ const PlanSourceSettings = ({ plan, onUpdate, error, isEditing }: PlanSourceSett
},
});
}
+ prevDeviceIdRef.current = deviceId;
}, [isEditing, deviceId]);
return (
diff --git a/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx b/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
index 089b966..757ad6f 100644
--- a/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
+++ b/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import classes from './StoragePicker.module.scss';
import Select from '../Select/Select';
import { useGetStorages } from '../../../../services/storage';
@@ -70,11 +70,19 @@ const StoragePicker = ({ onUpdate, storagePath = '', storageId, disabled = false
}
}, [selectedStorage, path]);
+ // Reset the storage selection only when the device actually changes (not on mount/remount,
+ // e.g. when navigating between steps in the Add Plan form).
+ const prevDeviceIdRef = useRef<string | undefined | null>(null);
useEffect(() => {
- if (!disabled) {
+ if (disabled) {
+ prevDeviceIdRef.current = deviceId;
+ return;
+ }
+ if (prevDeviceIdRef.current !== null && prevDeviceIdRef.current !== deviceId) {
setSelectedStorage(null);
setPath('');
}
+ prevDeviceIdRef.current = deviceId;
}, [deviceId, disabled]);
// console.log('Storage path :', path, !disabled && isLocalStorage && !path);