-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🪟 🎉 Add username editing #14242
Merged
Merged
🪟 🎉 Add username editing #14242
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
90c7ead
Adds editing for user name is settings tab
YatsukBogdan1 34fd3cb
Merge branch 'master' into byatsuk/feature-add-username-editing
YatsukBogdan1 6227682
Fixes eslint issues; Fixes comments from PR
YatsukBogdan1 680daaa
Merge branch 'master' into byatsuk/feature-add-username-editing
YatsukBogdan1 86afdc7
Adds validation for NameSection; Disables update button if form is no…
YatsukBogdan1 f0eedf2
Merge branch 'master' into byatsuk/feature-add-username-editing
YatsukBogdan1 0f0558d
Refactors formik validation logic from validate function to validatio…
YatsukBogdan1 a25799d
Updates submit button to be disabled while form is dirty
YatsukBogdan1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 6 additions & 43 deletions
49
airbyte-webapp/src/packages/cloud/views/users/AccountSettingsView/AccountSettingsView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,27 @@ | ||
import { Field, FieldProps, Form, Formik } from "formik"; | ||
import React from "react"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { useMutation } from "react-query"; | ||
import styled from "styled-components"; | ||
|
||
import { LabeledInput, LoadingButton } from "components"; | ||
import { LoadingButton } from "components"; | ||
|
||
import { useAuthService, useCurrentUser } from "packages/cloud/services/auth/AuthService"; | ||
import { RowFieldItem } from "packages/cloud/views/auth/components/FormComponents"; | ||
import { Content, SettingsCard } from "pages/SettingsPage/pages/SettingsComponents"; | ||
import { useAuthService } from "packages/cloud/services/auth/AuthService"; | ||
import { SettingsCard } from "pages/SettingsPage/pages/SettingsComponents"; | ||
|
||
import { EmailSection, PasswordSection } from "./components"; | ||
import { EmailSection, PasswordSection, NameSection } from "./components"; | ||
|
||
const Header = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
`; | ||
|
||
const AccountSettingsView: React.FC = () => { | ||
const { formatMessage } = useIntl(); | ||
const authService = useAuthService(); | ||
const { mutateAsync: logout, isLoading: isLoggingOut } = useMutation(() => authService.logout()); | ||
const user = useCurrentUser(); | ||
|
||
return ( | ||
<> | ||
<SettingsCard title={<FormattedMessage id="settings.account" />}> | ||
<Content> | ||
<Formik | ||
initialValues={{ | ||
name: user.name, | ||
}} | ||
onSubmit={() => { | ||
throw new Error("Not implemented"); | ||
}} | ||
> | ||
{() => ( | ||
<Form> | ||
<RowFieldItem> | ||
<Field name="name"> | ||
{({ field, meta }: FieldProps<string>) => ( | ||
<LabeledInput | ||
{...field} | ||
label={<FormattedMessage id="settings.accountSettings.fullName" />} | ||
disabled | ||
placeholder={formatMessage({ | ||
id: "settings.accountSettings.fullName.placeholder", | ||
})} | ||
type="text" | ||
error={!!meta.error && meta.touched} | ||
message={meta.touched && meta.error && formatMessage({ id: meta.error })} | ||
/> | ||
)} | ||
</Field> | ||
</RowFieldItem> | ||
</Form> | ||
)} | ||
</Formik> | ||
</Content> | ||
</SettingsCard> | ||
<NameSection /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it so much cleaner, thanks for extracting 🎉 |
||
<EmailSection /> | ||
<PasswordSection /> | ||
<SettingsCard | ||
|
67 changes: 67 additions & 0 deletions
67
...src/packages/cloud/views/users/AccountSettingsView/components/NameSection/NameSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Field, FieldProps, Form, Formik } from "formik"; | ||
import React from "react"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
import * as yup from "yup"; | ||
|
||
import { LoadingButton } from "components"; | ||
import { LabeledInput } from "components/LabeledInput"; | ||
|
||
import { useCurrentUser } from "packages/cloud/services/auth/AuthService"; | ||
import { RowFieldItem } from "packages/cloud/views/auth/components/FormComponents"; | ||
import FeedbackBlock from "pages/SettingsPage/components/FeedbackBlock"; | ||
import { Content, SettingsCard } from "pages/SettingsPage/pages/SettingsComponents"; | ||
|
||
import { useChangeName } from "./hooks"; | ||
edmundito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const nameSectionValidationSchema = yup.object({ | ||
name: yup.string().required("form.empty.error"), | ||
}); | ||
|
||
export const NameSection: React.FC = () => { | ||
const { formatMessage } = useIntl(); | ||
const user = useCurrentUser(); | ||
const { changeName, successMessage, errorMessage } = useChangeName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of a hook to keep the component clean. |
||
|
||
return ( | ||
<SettingsCard title={<FormattedMessage id="settings.account" />}> | ||
<Content> | ||
<Formik | ||
validateOnBlur | ||
validateOnChange | ||
validationSchema={nameSectionValidationSchema} | ||
initialValues={{ | ||
name: user.name, | ||
}} | ||
onSubmit={(values, formikHelpers) => | ||
changeName(values, formikHelpers).then(() => formikHelpers.resetForm({ values })) | ||
} | ||
> | ||
{({ isSubmitting, isValid, dirty }) => ( | ||
<Form> | ||
<RowFieldItem> | ||
<Field name="name"> | ||
{({ field, meta }: FieldProps<string>) => ( | ||
<LabeledInput | ||
{...field} | ||
label={<FormattedMessage id="settings.accountSettings.name" />} | ||
placeholder={formatMessage({ | ||
id: "settings.accountSettings.name.placeholder", | ||
})} | ||
type="text" | ||
error={!!meta.error && meta.touched} | ||
message={meta.touched && meta.error && formatMessage({ id: meta.error })} | ||
/> | ||
)} | ||
</Field> | ||
</RowFieldItem> | ||
<LoadingButton disabled={!isValid || !dirty} type="submit" isLoading={isSubmitting}> | ||
<FormattedMessage id="settings.accountSettings.updateName" /> | ||
</LoadingButton> | ||
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} /> | ||
</Form> | ||
)} | ||
</Formik> | ||
</Content> | ||
</SettingsCard> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
.../src/packages/cloud/views/users/AccountSettingsView/components/NameSection/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useChangeName } from "./useName"; |
47 changes: 47 additions & 0 deletions
47
...rc/packages/cloud/views/users/AccountSettingsView/components/NameSection/hooks/useName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FormikHelpers } from "formik/dist/types"; | ||
import { useState } from "react"; | ||
import { useIntl } from "react-intl"; | ||
|
||
import { useAuthService } from "packages/cloud/services/auth/AuthService"; | ||
|
||
import { FormValues } from "../types"; | ||
|
||
type UseNameHook = () => { | ||
successMessage: string; | ||
errorMessage: string; | ||
changeName: (values: FormValues, { setSubmitting, setFieldValue }: FormikHelpers<FormValues>) => Promise<void>; | ||
}; | ||
|
||
export const useChangeName: UseNameHook = () => { | ||
const { updateName } = useAuthService(); | ||
const { formatMessage } = useIntl(); | ||
const [successMessage, setSuccessMessage] = useState<string>(""); | ||
const [errorMessage, setErrorMessage] = useState<string>(""); | ||
|
||
const changeName = async (values: FormValues, { setSubmitting }: FormikHelpers<FormValues>) => { | ||
setSubmitting(true); | ||
|
||
setSuccessMessage(""); | ||
setErrorMessage(""); | ||
|
||
try { | ||
await updateName(values.name); | ||
|
||
setSuccessMessage( | ||
formatMessage({ | ||
id: "settings.accountSettings.updateNameSuccess", | ||
}) | ||
); | ||
} catch (err) { | ||
setErrorMessage( | ||
formatMessage({ | ||
id: "settings.accountSettings.updateNameError", | ||
}) + JSON.stringify(err) | ||
); | ||
} | ||
|
||
setSubmitting(false); | ||
}; | ||
|
||
return { successMessage, errorMessage, changeName }; | ||
}; |
1 change: 1 addition & 0 deletions
1
...webapp/src/packages/cloud/views/users/AccountSettingsView/components/NameSection/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { NameSection } from "./NameSection"; |
3 changes: 3 additions & 0 deletions
3
...webapp/src/packages/cloud/views/users/AccountSettingsView/components/NameSection/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface FormValues { | ||
name: string; | ||
} |
1 change: 1 addition & 0 deletions
1
airbyte-webapp/src/packages/cloud/views/users/AccountSettingsView/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./EmailSection"; | ||
export * from "./PasswordSection"; | ||
export * from "./NameSection"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in a separate comment, this should never happen if we check that the current user exists first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this error, so that was only workaround here