Skip to content
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 8 commits into from
Aug 8, 2022

Conversation

YatsukBogdan1
Copy link
Contributor

What

Closes #1268

How

I refactored User Settings Account section, so Name, Email and Password sections follow the same structure

Loom

https://www.loom.com/share/e1f141488f454dc78dc1d1e35a496b92

@YatsukBogdan1 YatsukBogdan1 requested a review from a team as a code owner June 29, 2022 10:05
@github-actions github-actions bot added area/platform issues related to the platform area/frontend Related to the Airbyte webapp labels Jun 29, 2022
@@ -112,6 +114,11 @@ export const AuthenticationProvider: React.FC = ({ children }) => {
queryClient.removeQueries();
loggedOut();
},
async updateName(name: string): Promise<void> {
await userService.changeName(state.currentUser?.authUserId || "", state.currentUser?.userId || "", name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "" should never happen. One way you can prevent this is to check if the current user exits, for example:

async updateName(name: string): Promise<void> {
   if (!state.currentUser) return;
   // Now you can use `state.currentUser.authUserId` without the `?`
}

@@ -0,0 +1,3 @@
export interface FormValues {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention for the types filename is types.ts

import { useCurrentUser } from "packages/cloud/services/auth/AuthService";
import FeedbackBlock from "pages/SettingsPage/components/FeedbackBlock";

const NameSection: React.FC = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're moving away from exporting defaults, so this can be:

Suggested change
const NameSection: React.FC = () => {
export const NameSection: React.FC = () => {

The same suggestion applies for other areas of the code, then you can just export it directly on the index.ts file.

</Formik>
</Content>
</SettingsCard>
<NameSection />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it so much cleaner, thanks for extracting 🎉

Comment on lines 118 to 120
await userService.changeName(state.currentUser?.authUserId || "", state.currentUser?.userId || "", name);
updateUserName({ value: name });
return authService.updateProfile(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add safety checks here to ensure both firebase and our user service get updated, and if one of them fails, rollback and return. the userName state should be updated last when it's guaranteed that both the user service and firebse got the update.

changeName: (values: FormValues, { setSubmitting, setFieldValue }: FormikHelpers<FormValues>) => void;
};

const useName: UseNameHook = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook doesn't return the name, should probably be useChangeName

Comment on lines +63 to +65
if (!state.currentUser) {
return state;
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

TS2322: Type '{ name: string; email?: string | undefined; authUserId?: string | undefined; userId?: string | undefined;
status?: UserStatus | undefined; intercomHash?: string | undefined; }' is not assignable to type 'User'. 
Types of property 'email' are incompatible. 
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.

<LoadingButton type="submit" isLoading={isSubmitting}>
<FormattedMessage id="settings.accountSettings.updateName" />
</LoadingButton>
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} isLoading={isSubmitting} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} isLoading={isSubmitting} />
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} />

The LoadingButton already gives us a loading indicator.

Suggested change
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} isLoading={isSubmitting} />
<FeedbackBlock errorMessage={errorMessage} successMessage={successMessage} isLoading={isSubmitting} />

@edmundito edmundito changed the title Add username editing 🪟 🎉 Add username editing Jun 30, 2022
@edmundito edmundito requested a review from timroes July 19, 2022 14:18
Copy link
Contributor

@edmundito edmundito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking a lot better but needs more validation and some minor things. I tested locally and looks great. Also update with the latest master branch.

Comment on lines 36 to 37
switch (err.code) {
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch does not seem necessary

export const NameSection: React.FC = () => {
const { formatMessage } = useIntl();
const user = useCurrentUser();
const { changeName, successMessage, errorMessage } = useChangeName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of a hook to keep the component clean.

)}
</Field>
</RowFieldItem>
<LoadingButton type="submit" isLoading={isSubmitting}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be disabled if the form is not valid

setErrorMessage(
formatMessage({
id: "settings.accountSettings.updateNameError",
}) + JSON.stringify(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error may be confusing to users. It may be better to console.error this error instead of stringifying it. @timroes is there a way we can send this error to Sentry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is copied from PasswordSection. not sure, how the error should be approached here

# Conflicts:
#	airbyte-webapp/src/packages/cloud/views/users/AccountSettingsView/AccountSettingsView.tsx
@YatsukBogdan1 YatsukBogdan1 requested a review from edmundito July 20, 2022 08:57
name: user.name,
}}
onSubmit={changeName}
validate={validate}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using yup to validate the schema. Search the code for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@YatsukBogdan1 YatsukBogdan1 requested a review from edmundito July 21, 2022 09:57
)}
</Field>
</RowFieldItem>
<LoadingButton disabled={!isValid} type="submit" isLoading={isSubmitting}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested and probably we should also check if the form is dirty before we enable the button. Otherwise, the user can press the button to save the same name over and over.

@YatsukBogdan1 YatsukBogdan1 merged commit 8282a45 into master Aug 8, 2022
@YatsukBogdan1 YatsukBogdan1 deleted the byatsuk/feature-add-username-editing branch August 8, 2022 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend Related to the Airbyte webapp area/platform issues related to the platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants