Skip to content

Commit b3cbef3

Browse files
committed
Example solution for #564
1 parent 079cb30 commit b3cbef3

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

client/src/locale/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ const en = {
316316
no: "No",
317317
ok: "OK",
318318
or: "or ",
319+
fixed: "or set a fixed date",
319320
edit: "Edit",
320321
reset: "Reset",
321322
cancel: "Cancel",

client/src/pages/RoleForm.jsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import SwitchField from "../components/SwitchField";
3030
import {dateFromEpoch, displayExpiryDate, futureDate} from "../utils/Date";
3131
import DOMPurify from "dompurify";
3232
import WarningIndicator from "../components/WarningIndicator";
33+
import DatePicker from "react-datepicker";
34+
import {MinimalDateField} from "../components/MinimalDateField";
3335

3436
const DEFAULT_EXPIRY_DAYS = 365;
3537
const CUT_OFF_DELETED_USER = 5;
@@ -446,18 +448,39 @@ export const RoleForm = () => {
446448
})}
447449
last={customRoleExpiryDate}
448450
/>
449-
{customRoleExpiryDate && <InputField name={I18n.t("roles.defaultExpiryDays")}
450-
value={role.defaultExpiryDays || 0}
451-
isInteger={true}
452-
onChange={e => {
453-
const val = parseInt(e.target.value);
454-
const defaultExpiryDays = Number.isInteger(val) && val > 0 ? val : 0;
455-
setRole(
456-
{...role, defaultExpiryDays: defaultExpiryDays})
457-
}}
458-
toolTip={I18n.t("tooltips.defaultExpiryDays")}
459-
customClassName="inner-switch"
460-
/>}
451+
{customRoleExpiryDate &&
452+
<div className="role-expiry-date">
453+
<InputField name={I18n.t("roles.defaultExpiryDays")}
454+
value={role.defaultExpiryDays || 0}
455+
isInteger={true}
456+
onChange={e => {
457+
const val = parseInt(e.target.value);
458+
const defaultExpiryDays = Number.isInteger(val) && val > 0 ? val : 0;
459+
setRole(
460+
{...role, defaultExpiryDays: defaultExpiryDays})
461+
}}
462+
toolTip={I18n.t("tooltips.defaultExpiryDays")}
463+
customClassName="inner-switch"/>
464+
<span className="separator">{I18n.t("forms.fixed")}</span>
465+
<DatePicker
466+
name={"custom-expiry-date"}
467+
id={"custom-expiry-date"}
468+
selected={null}
469+
dateFormat={"dd/MM/yyyy"}
470+
onChange={() => true}
471+
showWeekNumbers
472+
isClearable={true}
473+
showIcon={true}
474+
showYearDropdown={true}
475+
weekLabel="Week"
476+
disabled={false}
477+
todayButton={null}
478+
maxDate={null}
479+
minDate={new Date()}
480+
/>
481+
</div>
482+
483+
}
461484

462485
{(!initial && (isEmpty(role.defaultExpiryDays) || role.defaultExpiryDays < 1)) &&
463486
<ErrorIndicator msg={I18n.t("forms.required", {

client/src/pages/RoleForm.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@
9898
margin-top: 32px;
9999
}
100100

101+
.role-expiry-date {
102+
grid-column-start: first;
103+
display: flex;
104+
align-items: flex-end;
105+
justify-content: space-between;
106+
padding-bottom: 15px;
107+
border-bottom: 1px solid var(--sds--color--gray--200);
108+
109+
span.separator {
110+
margin-bottom: 15px;
111+
}
112+
113+
div.input-field.inner-switch {
114+
padding-bottom: 0;
115+
border-bottom: none;
116+
}
117+
}
118+
101119
}
102120

103121
}

0 commit comments

Comments
 (0)