- Add select dropdown for jwt ttl units
This commit is contained in:
1 parent
6425113766
commit
a4344b89a2
2 files changed
+43
-20
No files matched your search
@@ -36,6 +36,7 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
systemEmailAddress: "",
|
systemEmailAddress: "",
|
||||||
systemEmailPassword: "",
|
systemEmailPassword: "",
|
||||||
jwtTTL: "",
|
jwtTTL: "",
|
||||||
|
jwtTTLUnits: "days",
|
||||||
dbType: "",
|
dbType: "",
|
||||||
redisHost: "",
|
redisHost: "",
|
||||||
redisPort: "",
|
redisPort: "",
|
||||||
@@ -68,12 +69,30 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
warn: 4,
|
warn: 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const unitItems = [
|
||||||
|
{ _id: 1, name: "days" },
|
||||||
|
{ _id: 2, name: "weeks" },
|
||||||
|
{ _id: 3, name: "months" }
|
||||||
|
];
|
||||||
|
|
||||||
|
const unitItemLookup = {
|
||||||
|
days: 1,
|
||||||
|
weeks: 2,
|
||||||
|
months: 3,
|
||||||
|
};
|
||||||
|
|
||||||
const handleLogLevel = (e) => {
|
const handleLogLevel = (e) => {
|
||||||
const id = e.target.value;
|
const id = e.target.value;
|
||||||
const newLogLevel = logItems.find((item) => item._id === id).name;
|
const newLogLevel = logItems.find((item) => item._id === id).name;
|
||||||
setLocalSettings({ ...localSettings, logLevel: newLogLevel });
|
setLocalSettings({ ...localSettings, logLevel: newLogLevel });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleJWTTTLUnits = (e) => {
|
||||||
|
const id = e.target.value;
|
||||||
|
const newUnits = unitItems.find((item) => item._id === id).name;
|
||||||
|
setLocalSettings({ ...localSettings, jwtTTLUnits: newUnits });
|
||||||
|
};
|
||||||
|
|
||||||
const handleBlur = (event) => {
|
const handleBlur = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
const { error } = advancedSettingsValidation.validate(
|
const { error } = advancedSettingsValidation.validate(
|
||||||
@@ -82,11 +101,9 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
abortEarly: false,
|
abortEarly: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (error) {
|
setErrors((prev) => {
|
||||||
setErrors((prev) => {
|
return buildErrors(prev, id, error);
|
||||||
return buildErrors(prev, id, error);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
@@ -209,8 +226,8 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Stack gap={theme.spacing(20)}>
|
||||||
<Field
|
<Stack direction="row" gap={theme.spacing(10)} ><Field
|
||||||
type="text"
|
type="number"
|
||||||
id="jwtTTL"
|
id="jwtTTL"
|
||||||
label="JWT time to live"
|
label="JWT time to live"
|
||||||
name="jwtTTL"
|
name="jwtTTL"
|
||||||
@@ -219,6 +236,18 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
error={errors.jwtTTL}
|
error={errors.jwtTTL}
|
||||||
/>
|
/>
|
||||||
|
<Select
|
||||||
|
id="jwtTTLUnits"
|
||||||
|
label="JWT TTL Units"
|
||||||
|
name="jwtTTLUnits"
|
||||||
|
placeholder="Select time"
|
||||||
|
isHidden={true}
|
||||||
|
items={unitItems}
|
||||||
|
value={unitItemLookup[localSettings.jwtTTLUnits]}
|
||||||
|
onChange={handleJWTTTLUnits}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
error={errors.jwtttlUnits}
|
||||||
|
/></Stack>
|
||||||
<Field
|
<Field
|
||||||
type="text"
|
type="text"
|
||||||
id="dbType"
|
id="dbType"
|
||||||
|
|||||||
@@ -138,24 +138,18 @@ const advancedSettingsValidation = joi.object({
|
|||||||
systemEmailPort: joi.string().allow(""),
|
systemEmailPort: joi.string().allow(""),
|
||||||
systemEmailAddress: joi.string().allow(""),
|
systemEmailAddress: joi.string().allow(""),
|
||||||
systemEmailPassword: joi.string().allow(""),
|
systemEmailPassword: joi.string().allow(""),
|
||||||
jwtTTL: joi
|
jwtTTL: joi.string().trim().messages({
|
||||||
|
"string.empty": "JWT TTL is required.",
|
||||||
|
}),
|
||||||
|
jwtTTLUnits: joi
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.messages({
|
|
||||||
"string.empty": "JWT TTL is required.",
|
|
||||||
})
|
|
||||||
.custom((value, helpers) => {
|
.custom((value, helpers) => {
|
||||||
// test against regx start with a number followed by number or .,
|
if (value == 0) {
|
||||||
//ends with d or h
|
return helpers.message("JWT TTL unit is required.");
|
||||||
const regex = /^[1-9]+\d*(d|h)$/;
|
|
||||||
const found = value.match(regex);
|
|
||||||
if (!found) {
|
|
||||||
return helpers.message(
|
|
||||||
"JWT TTL should start with a non zero number and ends with 'd' or 'h'."
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}),
|
}),
|
||||||
dbType: joi.string().trim().messages({
|
dbType: joi.string().trim().messages({
|
||||||
"string.empty": "DB type is required.",
|
"string.empty": "DB type is required.",
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in new issue
Block a user