Skip to content

Commit 4436c12

Browse files
committed
fix(user-modal): implement data limit handling in user modal form
1 parent 1b66cab commit 4436c12

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

dashboard/src/components/dialogs/user-modal.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ export default function UserModal({ isDialogOpen, onOpenChange, form, editingUse
402402
// Get the expire value from the form
403403
const expireValue = form.watch('expire')
404404
const onHoldValue = form.watch('on_hold_timeout')
405+
const dataLimitValue = form.watch('data_limit')
405406

406407
let displayDate: Date | null = null
407408
let onHoldDisplayDate: Date | null = null
@@ -1175,18 +1176,36 @@ export default function UserModal({ isDialogOpen, onOpenChange, form, editingUse
11751176
}
11761177
}
11771178

1178-
// On first load (create user), auto-generate UUIDs for all fields
11791179
useEffect(() => {
1180-
if (isDialogOpen && !editingUser) {
1181-
// Remove auto-fill of proxy settings
1182-
form.setValue('proxy_settings', undefined)
1183-
// Set default flow and method from generalSettings if available
1184-
if (generalSettings) {
1185-
form.setValue('proxy_settings.vless.flow', generalSettings.default_flow || '')
1186-
const validMethods = ['aes-128-gcm', 'aes-256-gcm', 'chacha20-ietf-poly1305', 'xchacha20-poly1305'] as const
1187-
const method = validMethods.find(m => m === generalSettings.default_method)
1188-
if (method) {
1189-
form.setValue('proxy_settings.shadowsocks.method', method)
1180+
if (isDialogOpen && editingUser && dataLimitValue !== null && dataLimitValue !== undefined) {
1181+
if (dataLimitValue > 0) {
1182+
dataLimitInputRef.current = String(dataLimitValue)
1183+
} else {
1184+
dataLimitInputRef.current = ''
1185+
}
1186+
}
1187+
}, [isDialogOpen, editingUser, dataLimitValue])
1188+
1189+
useEffect(() => {
1190+
if (isDialogOpen) {
1191+
if (!editingUser) {
1192+
form.setValue('proxy_settings', undefined)
1193+
dataLimitInputRef.current = ''
1194+
form.setValue('data_limit', 0)
1195+
if (generalSettings) {
1196+
form.setValue('proxy_settings.vless.flow', generalSettings.default_flow || '')
1197+
const validMethods = ['aes-128-gcm', 'aes-256-gcm', 'chacha20-ietf-poly1305', 'xchacha20-poly1305'] as const
1198+
const method = validMethods.find(m => m === generalSettings.default_method)
1199+
if (method) {
1200+
form.setValue('proxy_settings.shadowsocks.method', method)
1201+
}
1202+
}
1203+
} else {
1204+
const currentDataLimit = form.getValues('data_limit')
1205+
if (currentDataLimit !== null && currentDataLimit !== undefined && currentDataLimit > 0) {
1206+
dataLimitInputRef.current = String(currentDataLimit)
1207+
} else {
1208+
dataLimitInputRef.current = ''
11901209
}
11911210
}
11921211
}

0 commit comments

Comments
 (0)