- Add select dropdown for jwt ttl units

This commit is contained in:
Shemy Gan committed 2024-10-23 21:03:40 -04:00
1 parent 6425113766
commit a4344b89a2
2 files changed
+43 -20

No files matched your search

+36 -7
View File
@@ -36,6 +36,7 @@ const AdvancedSettings = ({ isAdmin }) => {
systemEmailAddress: "",
systemEmailPassword: "",
jwtTTL: "",
jwtTTLUnits: "days",
dbType: "",
redisHost: "",
redisPort: "",
@@ -68,12 +69,30 @@ const AdvancedSettings = ({ isAdmin }) => {
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 id = e.target.value;
const newLogLevel = logItems.find((item) => item._id === id).name;
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 { value, id } = event.target;
const { error } = advancedSettingsValidation.validate(
@@ -82,11 +101,9 @@ const AdvancedSettings = ({ isAdmin }) => {
abortEarly: false,
}
);
if (error) {
setErrors((prev) => {
return buildErrors(prev, id, error);
});
}
setErrors((prev) => {
return buildErrors(prev, id, error);
});
};
const handleChange = (event) => {
const { value, id } = event.target;
@@ -209,8 +226,8 @@ const AdvancedSettings = ({ isAdmin }) => {
</Typography>
</Box>
<Stack gap={theme.spacing(20)}>
<Field
type="text"
<Stack direction="row" gap={theme.spacing(10)} ><Field
type="number"
id="jwtTTL"
label="JWT time to live"
name="jwtTTL"
@@ -219,6 +236,18 @@ const AdvancedSettings = ({ isAdmin }) => {
onBlur={handleBlur}
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
type="text"
id="dbType"
+7 -13
View File
@@ -138,24 +138,18 @@ const advancedSettingsValidation = joi.object({
systemEmailPort: joi.string().allow(""),
systemEmailAddress: joi.string().allow(""),
systemEmailPassword: joi.string().allow(""),
jwtTTL: joi
jwtTTL: joi.string().trim().messages({
"string.empty": "JWT TTL is required.",
}),
jwtTTLUnits: joi
.string()
.trim()
.messages({
"string.empty": "JWT TTL is required.",
})
.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 found = value.match(regex);
if (!found) {
return helpers.message(
"JWT TTL should start with a non zero number and ends with 'd' or 'h'."
);
if (value == 0) {
return helpers.message("JWT TTL unit is required.");
}
return value;
}),
}),
dbType: joi.string().trim().messages({
"string.empty": "DB type is required.",
}),