Skip to content

Commit 29ed720

Browse files
Introduce FoldableDiv
1 parent e85f1b7 commit 29ed720

File tree

4 files changed

+86
-27
lines changed

4 files changed

+86
-27
lines changed

portal/src/FoldableDiv.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useCallback } from "react";
2+
import ActionButton from "./ActionButton";
3+
import { useSystemConfig } from "./context/SystemConfigContext";
4+
5+
export interface FoldableDivProps {
6+
folded: boolean;
7+
label: React.ReactElement;
8+
setFolded: (folded: boolean) => void;
9+
className?: string;
10+
children?: React.ReactNode;
11+
}
12+
13+
export default function FoldableDiv(
14+
props: FoldableDivProps
15+
): React.ReactElement {
16+
const { folded, setFolded, label, className, children } = props;
17+
const { themes } = useSystemConfig();
18+
const onClick = useCallback(() => {
19+
setFolded(!folded);
20+
}, [folded, setFolded]);
21+
22+
return (
23+
<div className={className}>
24+
<ActionButton
25+
text={label}
26+
iconProps={{
27+
iconName: folded ? "ChevronDown" : "ChevronUp",
28+
}}
29+
styles={{
30+
root: {
31+
padding: "0",
32+
},
33+
flexContainer: {
34+
flexDirection: "row-reverse",
35+
gap: "8px",
36+
},
37+
label: {
38+
color: themes.main.palette.themePrimary,
39+
margin: "0",
40+
},
41+
}}
42+
onClick={onClick}
43+
/>
44+
{folded ? null : children}
45+
</div>
46+
);
47+
}

portal/src/graphql/adminapi/AddUserScreen.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929

3030
.accountValidPeriodSection {
31-
@apply flex flex-col gap-2;
31+
@apply flex flex-col gap-2 py-2;
3232
}
3333

3434
.accountValidPeriodForm {

portal/src/graphql/adminapi/AddUserScreen.tsx

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useCallback, useContext, useEffect, useMemo } from "react";
1+
import React, {
2+
useCallback,
3+
useContext,
4+
useEffect,
5+
useMemo,
6+
useState,
7+
} from "react";
28
import cn from "classnames";
39
import { useNavigate, useParams } from "react-router-dom";
410
import { Context, FormattedMessage } from "@oursky/react-messageformat";
@@ -44,6 +50,7 @@ import { AccountValidPeriodForm } from "./UserDetailsAccountStatus";
4450
import WidgetTitle from "../../WidgetTitle";
4551
import WidgetDescription from "../../WidgetDescription";
4652
import { useSystemConfig } from "../../context/SystemConfigContext";
53+
import FoldableDiv from "../../FoldableDiv";
4754

4855
enum PasswordCreationType {
4956
ManualEntry = "manual_entry",
@@ -250,6 +257,8 @@ const AddUserContent: React.VFC<AddUserContentProps> = function AddUserContent(
250257
} = props;
251258
const { renderToString } = useContext(Context);
252259

260+
const [advancedFolded, setAdvancedFolded] = useState(true);
261+
253262
const { themes } = useSystemConfig();
254263

255264
const {
@@ -614,32 +623,34 @@ const AddUserContent: React.VFC<AddUserContentProps> = function AddUserContent(
614623
}
615624
/>
616625
</div>
617-
<div
618-
className={cn(
619-
styles.widget,
620-
styles.accountValidPeriodSection
621-
)}
626+
<FoldableDiv
627+
className={cn(styles.widget)}
628+
label={<FormattedMessage id="AdduserScreen.advanced" />}
629+
folded={advancedFolded}
630+
setFolded={setAdvancedFolded}
622631
>
623-
<WidgetTitle>
624-
<FormattedMessage id="AddUserScreen.valid-period.title" />
625-
</WidgetTitle>
626-
<WidgetDescription
627-
styles={{
628-
root: {
629-
color: themes.main.semanticColors.bodySubtext,
630-
},
631-
}}
632-
>
633-
<FormattedMessage id="AddUserScreen.valid-period.description" />
634-
</WidgetDescription>
635-
<AccountValidPeriodForm
636-
className={styles.accountValidPeriodForm}
637-
accountValidFrom={state.accountValidFrom}
638-
accountValidUntil={state.accountValidUntil}
639-
onPickAccountValidFrom={onPickAccountValidFrom}
640-
onPickAccountValidUntil={onPickAccountValidUntil}
641-
/>
642-
</div>
632+
<div className={styles.accountValidPeriodSection}>
633+
<WidgetTitle>
634+
<FormattedMessage id="AddUserScreen.valid-period.title" />
635+
</WidgetTitle>
636+
<WidgetDescription
637+
styles={{
638+
root: {
639+
color: themes.main.semanticColors.bodySubtext,
640+
},
641+
}}
642+
>
643+
<FormattedMessage id="AddUserScreen.valid-period.description" />
644+
</WidgetDescription>
645+
<AccountValidPeriodForm
646+
className={styles.accountValidPeriodForm}
647+
accountValidFrom={state.accountValidFrom}
648+
accountValidUntil={state.accountValidUntil}
649+
onPickAccountValidFrom={onPickAccountValidFrom}
650+
onPickAccountValidUntil={onPickAccountValidUntil}
651+
/>
652+
</div>
653+
</FoldableDiv>
643654
</>
644655
) : null}
645656
</>

portal/src/locale-data/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@
344344
"AddUserScreen.send-password": "Send the password to user's email",
345345
"AddUserScreen.password-setup.label": "Password setup",
346346
"AddUserScreen.additional-option.label": "Additional option",
347+
"AdduserScreen.advanced": "Advanced",
347348
"AddUserScreen.valid-period.title": "Valid Period",
348349
"AddUserScreen.valid-period.description": "Set a valid period during which this account can log in. Outside this period, the user cannot log in. Useful for temporary access, such as contractors or external partners.",
349350

0 commit comments

Comments
 (0)