Skip to content

Commit 2dadd69

Browse files
authored
Fix update password form (#670)
* fix: update form layout to avoid nested forms * style: update order of fields and tweak box styles * style: tweak layout
1 parent 9181362 commit 2dadd69

4 files changed

Lines changed: 27 additions & 20 deletions

File tree

ui/src/components/header/user-info-dialog/user-info-form/user-info-form.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.miniForm {
55
border-radius: 8px;
66
border: 1px solid $color-neutral-100;
7+
overflow: hidden;
78
}
89

910
.miniFormContent {

ui/src/components/header/user-info-dialog/user-info-form/user-info-form.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useUpdateUserInfo } from 'data-services/hooks/auth/useUpdateUserInfo'
1111
import { Button, ButtonTheme } from 'design-system/components/button/button'
1212
import { IconType } from 'design-system/components/icon/icon'
1313
import { InputContent } from 'design-system/components/input/input'
14+
import { useRef } from 'react'
1415
import { useForm } from 'react-hook-form'
1516
import { API_MAX_UPLOAD_SIZE } from 'utils/constants'
1617
import { STRING, translate } from 'utils/language'
@@ -55,6 +56,7 @@ const config: FormConfig = {
5556
}
5657

5758
export const UserInfoForm = ({ userInfo }: { userInfo: UserInfo }) => {
59+
const formRef = useRef<HTMLFormElement>(null)
5860
const {
5961
control,
6062
handleSubmit,
@@ -68,29 +70,29 @@ export const UserInfoForm = ({ userInfo }: { userInfo: UserInfo }) => {
6870
const errorMessage = useFormError({ error, setFieldError })
6971

7072
return (
71-
<form onSubmit={handleSubmit((values) => updateUserInfo(values))}>
72-
{errorMessage && (
73-
<FormError
74-
inDialog
75-
intro={translate(STRING.MESSAGE_COULD_NOT_SAVE)}
76-
message={errorMessage}
77-
/>
78-
)}
73+
<>
7974
<FormSection>
75+
{errorMessage && (
76+
<FormError
77+
inDialog
78+
intro={translate(STRING.MESSAGE_COULD_NOT_SAVE)}
79+
message={errorMessage}
80+
/>
81+
)}
8082
<FormRow>
8183
<UserEmailField value={userInfo.email} />
8284
<UserPasswordField value="************" />
83-
</FormRow>
84-
<>
85-
<FormRow>
85+
<form
86+
ref={formRef}
87+
onSubmit={handleSubmit((values) => updateUserInfo(values))}
88+
className="grid gap-8"
89+
>
8690
<FormField
8791
name="name"
8892
type="text"
8993
config={config}
9094
control={control}
9195
/>
92-
</FormRow>
93-
<FormRow>
9496
<FormController
9597
name="image"
9698
control={control}
@@ -109,18 +111,22 @@ export const UserInfoForm = ({ userInfo }: { userInfo: UserInfo }) => {
109111
</InputContent>
110112
)}
111113
/>
112-
</FormRow>
113-
</>
114+
</form>
115+
</FormRow>
114116
</FormSection>
115117
<FormActions>
116118
<Button
117119
label={isSuccess ? translate(STRING.SAVED) : translate(STRING.SAVE)}
118120
icon={isSuccess ? IconType.RadixCheck : undefined}
119-
type="submit"
121+
onClick={() => {
122+
formRef.current?.dispatchEvent(
123+
new Event('submit', { cancelable: true, bubbles: true })
124+
)
125+
}}
120126
theme={ButtonTheme.Success}
121127
loading={isLoading}
122128
/>
123129
</FormActions>
124-
</form>
130+
</>
125131
)
126132
}

ui/src/components/header/user-info-dialog/user-info-form/user-password-field.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ const UpdatePasswordForm = ({ onCancel }: { onCancel: () => void }) => {
8787
)}
8888
<div className={styles.miniFormContent}>
8989
<FormField
90-
name="new_password"
90+
name="current_password"
9191
type="password"
9292
config={config}
9393
control={control}
9494
/>
9595
<FormField
96-
name="current_password"
96+
name="new_password"
9797
type="password"
9898
config={config}
9999
control={control}

ui/src/utils/language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ const ENGLISH_STRINGS: { [key in STRING]: string } = {
290290
[STRING.FIELD_LABEL_DESCRIPTION]: 'Description',
291291
[STRING.FIELD_LABEL_DURATION]: 'Duration',
292292
[STRING.FIELD_LABEL_EMAIL]: 'Email',
293-
[STRING.FIELD_LABEL_EMAIL_NEW]: 'Email new',
293+
[STRING.FIELD_LABEL_EMAIL_NEW]: 'New email',
294294
[STRING.FIELD_LABEL_ERRORS]: 'Errors',
295295
[STRING.FIELD_LABEL_FINISHED_AT]: 'Finished at',
296296
[STRING.FIELD_LABEL_GENERAL]: 'General configuration',

0 commit comments

Comments
 (0)