- add OnBlur to Field and Select

- update regex to remove dot for jwtttl
This commit is contained in:
Shemy Gan committed 2024-10-23 13:18:00 -04:00
1 parent f707965155
commit 6425113766
4 files changed
+27 -6

No files matched your search

@@ -41,6 +41,7 @@ const Field = forwardRef(
placeholder,
value,
onChange,
onBlur,
onInput,
error,
disabled,
@@ -115,6 +116,7 @@ const Field = forwardRef(
value={value}
onInput={onInput}
onChange={onChange}
onBlur={onBlur}
disabled={disabled}
inputRef={ref}
inputProps={{
@@ -216,6 +218,7 @@ Field.propTypes = {
placeholder: PropTypes.string,
value: PropTypes.string.isRequired,
onChange: PropTypes.func,
onBlur: PropTypes.func,
onInput: PropTypes.func,
error: PropTypes.string,
disabled: PropTypes.bool,
@@ -46,6 +46,7 @@ const Select = ({
value,
items,
onChange,
onBlur,
sx,
name = "",
}) => {
@@ -76,6 +77,7 @@ const Select = ({
className="select-component"
value={value}
onChange={onChange}
onBlur={onBlur}
displayEmpty
name={name}
inputProps={{ id: id }}
@@ -140,6 +142,7 @@ Select.propTypes = {
})
).isRequired,
onChange: PropTypes.func.isRequired,
onBlur: PropTypes.func,
sx: PropTypes.object,
};
+20 -5
View File
@@ -74,18 +74,23 @@ const AdvancedSettings = ({ isAdmin }) => {
setLocalSettings({ ...localSettings, logLevel: newLogLevel });
};
const handleChange = (event) => {
const handleBlur = (event) => {
const { value, id } = event.target;
setLocalSettings({ ...localSettings, [id]: value });
const { error } = advancedSettingsValidation.validate(
{ [id]: value },
{
abortEarly: false,
}
);
setErrors((prev) => {
return buildErrors(prev, id, error);
});
if (error) {
setErrors((prev) => {
return buildErrors(prev, id, error);
});
}
};
const handleChange = (event) => {
const { value, id } = event.target;
setLocalSettings({ ...localSettings, [id]: value });
};
const handleSave = async () => {
@@ -131,6 +136,7 @@ const AdvancedSettings = ({ isAdmin }) => {
label="API URL Host"
value={localSettings.apiBaseUrl}
onChange={handleChange}
onBlur={handleBlur}
error={errors.apiBaseUrl}
/>
<Select
@@ -140,6 +146,7 @@ const AdvancedSettings = ({ isAdmin }) => {
items={logItems}
value={logItemLookup[localSettings.logLevel]}
onChange={handleLogLevel}
onBlur={handleBlur}
error={errors.logLevel}
/>
</Stack>
@@ -160,6 +167,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="systemEmailHost"
value={localSettings.systemEmailHost}
onChange={handleChange}
onBlur={handleBlur}
error={errors.systemEmailHost}
/>
<Field
@@ -169,6 +177,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="systemEmailPort"
value={localSettings.systemEmailPort.toString()}
onChange={handleChange}
onBlur={handleBlur}
error={errors.systemEmailPort}
/>
<Field
@@ -187,6 +196,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="systemEmailPassword"
value={localSettings.systemEmailPassword}
onChange={handleChange}
onBlur={handleBlur}
error={errors.systemEmailPassword}
/>
</Stack>
@@ -206,6 +216,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="jwtTTL"
value={localSettings.jwtTTL}
onChange={handleChange}
onBlur={handleBlur}
error={errors.jwtTTL}
/>
<Field
@@ -215,6 +226,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="dbType"
value={localSettings.dbType}
onChange={handleChange}
onBlur={handleBlur}
error={errors.dbType}
/>
<Field
@@ -224,6 +236,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="redisHost"
value={localSettings.redisHost}
onChange={handleChange}
onBlur={handleBlur}
error={errors.redisHost}
/>
<Field
@@ -233,6 +246,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="redisPort"
value={localSettings.redisPort.toString()}
onChange={handleChange}
onBlur={handleBlur}
error={errors.redisPort}
/>
<Field
@@ -242,6 +256,7 @@ const AdvancedSettings = ({ isAdmin }) => {
name="pagespeedApiKey"
value={localSettings.pagespeedApiKey}
onChange={handleChange}
onBlur={handleBlur}
error={errors.pagespeedApiKey}
/>
</Stack>
+1 -1
View File
@@ -147,7 +147,7 @@ const advancedSettingsValidation = joi.object({
.custom((value, helpers) => {
// test against regx start with a number followed by number or .,
//ends with d or h
const regex = /^[1-9]+\d*(.)*(d|h)$/;
const regex = /^[1-9]+\d*(d|h)$/;
const found = value.match(regex);
if (!found) {
return helpers.message(