Fix Duration widget error-message logic
- It didn't remove the error msg when the input is cleared. - It didn't update to the latest error msg if one already existed.
This commit is contained in:
parent
6a5ea5d3c6
commit
124aa90525
1 changed files with 11 additions and 6 deletions
|
@ -95,16 +95,16 @@ export default function ModalBlockChannel(props: Props) {
|
|||
|
||||
// 'timeoutInput' to 'timeoutSec' conversion.
|
||||
React.useEffect(() => {
|
||||
const setInvalid = (errMsg: string) => {
|
||||
const handleInvalidInput = (errMsg: string) => {
|
||||
if (timeoutSec !== -1) {
|
||||
setTimeoutSec(-1);
|
||||
}
|
||||
if (!timeoutInputErr) {
|
||||
if (timeoutInputErr !== errMsg) {
|
||||
setTimeoutInputErr(errMsg);
|
||||
}
|
||||
};
|
||||
|
||||
const setValid = (seconds) => {
|
||||
const handleValidInput = (seconds) => {
|
||||
if (seconds !== timeoutSec) {
|
||||
setTimeoutSec(seconds);
|
||||
}
|
||||
|
@ -113,17 +113,22 @@ export default function ModalBlockChannel(props: Props) {
|
|||
}
|
||||
};
|
||||
|
||||
if (!timeoutInput) {
|
||||
handleValidInput(-1); // Reset
|
||||
return;
|
||||
}
|
||||
|
||||
const ONE_HUNDRED_YEARS_IN_SECONDS = 3154000000;
|
||||
const seconds = parseDuration(timeoutInput, 's');
|
||||
|
||||
if (Number.isInteger(seconds) && seconds > 0) {
|
||||
if (seconds > ONE_HUNDRED_YEARS_IN_SECONDS) {
|
||||
setInvalid(__('Wow, banned for more than 100 years?'));
|
||||
handleInvalidInput(__('Wow, banned for more than 100 years?'));
|
||||
} else {
|
||||
setValid(seconds);
|
||||
handleValidInput(seconds);
|
||||
}
|
||||
} else {
|
||||
setInvalid(__('Invalid duration.'));
|
||||
handleInvalidInput(__('Invalid duration.'));
|
||||
}
|
||||
}, [timeoutInput, timeoutInputErr, timeoutSec]);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue