File tree 2 files changed +11
-2
lines changed
components/SettingsAccountForm
pages/UserSettingsPage/AccountPage
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { LoadingButton } from "../LoadingButton/LoadingButton"
8
8
import { Stack } from "../Stack/Stack"
9
9
10
10
export interface AccountFormValues {
11
+ editable : boolean
11
12
username : string
12
13
}
13
14
@@ -22,6 +23,7 @@ const validationSchema = Yup.object({
22
23
} )
23
24
24
25
export interface AccountFormProps {
26
+ editable : boolean
25
27
email : string
26
28
isLoading : boolean
27
29
initialValues : AccountFormValues
@@ -32,6 +34,7 @@ export interface AccountFormProps {
32
34
}
33
35
34
36
export const AccountForm : FC < React . PropsWithChildren < AccountFormProps > > = ( {
37
+ editable,
35
38
email,
36
39
isLoading,
37
40
onSubmit,
@@ -63,6 +66,7 @@ export const AccountForm: FC<React.PropsWithChildren<AccountFormProps>> = ({
63
66
{ ...getFieldHelpers ( "username" ) }
64
67
onChange = { onChangeTrimmed ( form ) }
65
68
autoComplete = "username"
69
+ disabled = { ! editable }
66
70
fullWidth
67
71
label = { Language . usernameLabel }
68
72
variant = "outlined"
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ export const Language = {
11
11
export const AccountPage : React . FC = ( ) => {
12
12
const xServices = useContext ( XServiceContext )
13
13
const [ authState , authSend ] = useActor ( xServices . authXService )
14
- const { me, updateProfileError } = authState . context
14
+ const { me, permissions, updateProfileError } = authState . context
15
+ const canEditUsers = permissions && permissions . updateUsers
15
16
16
17
if ( ! me ) {
17
18
throw new Error ( "No current user found" )
@@ -23,7 +24,11 @@ export const AccountPage: React.FC = () => {
23
24
email = { me . email }
24
25
updateProfileError = { updateProfileError }
25
26
isLoading = { authState . matches ( "signedIn.profile.updatingProfile" ) }
26
- initialValues = { { username : me . username } }
27
+ initialValues = { {
28
+ username : me . username ,
29
+ // Fail-open, as the API endpoint will check again on submit
30
+ editable : canEditUsers || false ,
31
+ } }
27
32
onSubmit = { ( data ) => {
28
33
authSend ( {
29
34
type : "UPDATE_PROFILE" ,
You can’t perform that action at this time.
0 commit comments