Skip to content

Commit 0a5c7d3

Browse files
committed
refactor to a map
1 parent 618a3a7 commit 0a5c7d3

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

site/src/components/CreateUserForm/CreateUserForm.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,13 @@ export const CreateUserForm: FC<
105105
)
106106

107107
const styles = useStyles()
108-
// This, unfortunately, cannot be an actual component because mui requires
109-
// that all `MenuItem`s must be direct children of the `Select` they belong to
110-
const authMethodSelect = (value: keyof typeof authMethodLanguage) => {
111-
const language = authMethodLanguage[value]
112-
return (
113-
<MenuItem key={value} id={"item-" + value} value={value}>
114-
<Stack spacing={0} maxWidth={400}>
115-
{language.displayName}
116-
<span className={styles.labelDescription}>
117-
{language.description}
118-
</span>
119-
</Stack>
120-
</MenuItem>
121-
)
122-
}
123108

124-
const methods = []
125-
if (authMethods?.password.enabled) {
126-
methods.push(authMethodSelect("password"))
127-
}
128-
if (authMethods?.oidc.enabled) {
129-
methods.push(authMethodSelect("oidc"))
130-
}
131-
if (authMethods?.github.enabled) {
132-
methods.push(authMethodSelect("github"))
133-
}
134-
methods.push(authMethodSelect("none"))
109+
const methods = [
110+
authMethods?.password.enabled && "password",
111+
authMethods?.oidc.enabled && "oidc",
112+
authMethods?.github.enabled && "github",
113+
"none",
114+
].filter(Boolean) as Array<keyof typeof authMethodLanguage>
135115

136116
return (
137117
<FullPageForm title="Create user">
@@ -177,7 +157,19 @@ export const CreateUserForm: FC<
177157
?.displayName ?? "",
178158
}}
179159
>
180-
{methods}
160+
{methods.map((value) => {
161+
const language = authMethodLanguage[value]
162+
return (
163+
<MenuItem key={value} id={"item-" + value} value={value}>
164+
<Stack spacing={0} maxWidth={400}>
165+
{language.displayName}
166+
<span className={styles.labelDescription}>
167+
{language.description}
168+
</span>
169+
</Stack>
170+
</MenuItem>
171+
)
172+
})}
181173
</TextField>
182174
<TextField
183175
{...getFieldHelpers(

0 commit comments

Comments
 (0)