From 1764b12a91137a7bd5e461386ef66854829a086b Mon Sep 17 00:00:00 2001 From: Hin Yan Liew Date: Mon, 9 Dec 2024 19:15:40 -0500 Subject: [PATCH] Fixed small issues with FormFeedback and min/max bounds, added final check to submit button --- .../components/admin/PreferencesComponent.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client/app/components/admin/PreferencesComponent.tsx b/src/client/app/components/admin/PreferencesComponent.tsx index b1d453c27..34f891e41 100644 --- a/src/client/app/components/admin/PreferencesComponent.tsx +++ b/src/client/app/components/admin/PreferencesComponent.tsx @@ -46,7 +46,7 @@ export default function PreferencesComponent() { setLocalAdminPref(cloneDeep(adminPreferences)); }; - // small functions that determine if fields are invalid to warn the user + // small functions that determine if fields are invalid const invalidReadingFreq = () => { const frequency = moment.duration(localAdminPref.defaultMeterReadingFrequency); return !frequency.isValid() || frequency.asSeconds() <= 0; @@ -197,6 +197,9 @@ export default function PreferencesComponent() { onChange={e => makeLocalChanges('defaultMeterReadingFrequency', e.target.value)} invalid={invalidReadingFreq()} /> + + +

@@ -206,6 +209,8 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultMeterMinimumValue} onChange={e => makeLocalChanges('defaultMeterMinimumValue', e.target.value)} + min={MIN_VAL} + max={Number(localAdminPref.defaultMeterMaximumValue)} maxLength={50} invalid={invalidMinValue()} /> @@ -221,6 +226,8 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultMeterMaximumValue} onChange={e => makeLocalChanges('defaultMeterMaximumValue', e.target.value)} + min={Number(localAdminPref.defaultMeterMinimumValue)} + max={MAX_VAL} maxLength={50} invalid={invalidMaxValue()} /> @@ -255,7 +262,7 @@ export default function PreferencesComponent() { invalid={invalidMaxDate()} /> - +

@@ -266,6 +273,7 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultMeterReadingGap} onChange={e => makeLocalChanges('defaultMeterReadingGap', e.target.value)} + min='0' maxLength={50} invalid={invalidReadingGap()} /> @@ -281,6 +289,8 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultMeterMaximumErrors} onChange={e => makeLocalChanges('defaultMeterMaximumErrors', e.target.value)} + min='0' + max={MAX_ERRORS} maxLength={50} invalid={invalidMeterErrors()} /> @@ -374,6 +384,8 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultWarningFileSize} onChange={e => makeLocalChanges('defaultWarningFileSize', e.target.value)} + min='0' + max={Number(localAdminPref.defaultFileSizeLimit)} maxLength={50} invalid={invalidWarningFileSize()} /> @@ -389,6 +401,7 @@ export default function PreferencesComponent() { type='number' value={localAdminPref.defaultFileSizeLimit} onChange={e => makeLocalChanges('defaultFileSizeLimit', e.target.value)} + min='0' maxLength={50} invalid={invalidFileSizeLimit()} /> @@ -427,7 +440,9 @@ export default function PreferencesComponent() { showErrorNotification(translate('failed.to.submit.changes')); }) } - disabled={!hasChanges} + disabled={!hasChanges || invalidReadingFreq() || invalidMinValue() || invalidMaxValue() || invalidMinDate() || invalidMaxDate() + || invalidReadingGap() || invalidMeterErrors() || invalidFileSizeLimit() || invalidWarningFileSize() + } > {translate('submit')}