Skip to content

fix: updating password ui bug #7775#7815

Merged
emrysal merged 5 commits intocalcom:mainfrom
joe-shajan:updating_password_ui_bug
Mar 27, 2023
Merged

fix: updating password ui bug #7775#7815
emrysal merged 5 commits intocalcom:mainfrom
joe-shajan:updating_password_ui_bug

Conversation

@joe-shajan
Copy link
Copy Markdown
Contributor

@joe-shajan joe-shajan commented Mar 18, 2023

What does this PR do?

Fixes #7775

Currently, when the old password and new password are the same or the old password is incorrect, the server returns an error. We use the setError method from the useForm hook to set an apiError. However, since this apiError is not linked to any of the input fields, it will not trigger validation again when the user types. As a result, the handleSubmit function will not be triggered by React Hook Form because the error is set to true.

To solve this issue, we can check if apiError is true when we submit the form. If it's true, we can clear it before submitting it. This approach is working well.

Recording: Link to loom video of the screen recording

Environment: Staging(main branch) / Production

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

@joe-shajan joe-shajan requested a review from a team March 18, 2023 08:01
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
ui ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 23, 2023 at 5:13PM (UTC)

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 18, 2023

@joeshajan is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

>;

const PlainForm = <T extends FieldValues>(props: FormProps<T>, ref: Ref<HTMLFormElement>) => {
const PlainForm = (props: FormProps<{ apiError: string }>, ref: Ref<HTMLFormElement>) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated this FormProps<T> to FormProps<{ apiError: string }> if I don't do this the typescript will show a warning here form.clearErrors("apiError"); in line 343. So my doubt is will this cause any other issues?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it will, this isn't the right fix unfortunately - we can look at creating a "globalError" utility in the future but by not forwarding the T extends FieldValues it will disable/cause type errors elsewhere. This should be handled in the change password form. 🙏

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2023

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 210.9 KB (🟡 +1 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Sixty-eight Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/404 8.37 KB 219.26 KB 62.65% (+/- <0.01%)
/[user] 78.09 KB 288.99 KB 82.57% (+/- <0.01%)
/[user]/[type] 99.83 KB 310.73 KB 88.78% (+/- <0.01%)
/[user]/[type]/embed 99.86 KB 310.75 KB 88.79% (+/- <0.01%)
/[user]/book 191.29 KB 402.19 KB 114.91% (🟡 +0.01%)
/[user]/embed 78.16 KB 289.06 KB 82.59% (+/- <0.01%)
/apps 171.36 KB 382.26 KB 109.22% (🟡 +0.01%)
/apps/[slug] 195.08 KB 405.98 KB 115.99% (🟡 +0.02%)
/apps/[slug]/[...pages] 396.68 KB 607.58 KB 173.59% (🟡 +0.01%)
/apps/categories 156.26 KB 367.16 KB 104.90% (🟡 +0.02%)
/apps/categories/[category] 160.12 KB 371.02 KB 106.01% (🟡 +0.01%)
/apps/installed/[category] 201.27 KB 412.17 KB 117.76% (🟡 +0.02%)
/auth/error 19.24 KB 230.14 KB 65.75% (🟡 +0.01%)
/auth/forgot-password 25.63 KB 236.53 KB 67.58% (🟡 +0.01%)
/auth/forgot-password/[id] 40.95 KB 251.85 KB 71.96% (🟡 +0.01%)
/auth/login 40.1 KB 251 KB 71.71% (🟡 +0.02%)
/auth/logout 7.56 KB 218.46 KB 62.42% (+/- <0.01%)
/auth/setup 103.52 KB 314.42 KB 89.84% (🟡 +0.01%)
/availability 159.47 KB 370.37 KB 105.82% (🟡 +0.01%)
/availability/[schedule] 276.27 KB 487.17 KB 139.19% (🟡 +0.01%)
/availability/troubleshoot 156.94 KB 367.84 KB 105.10% (🟡 +0.01%)
/booking/[uid] 131.49 KB 342.38 KB 97.82% (🟡 +0.02%)
/bookings/[status] 269.14 KB 480.04 KB 137.15% (🟡 +0.02%)
/d/[link]/[slug] 99.48 KB 310.38 KB 88.68% (+/- <0.01%)
/d/[link]/[slug]/embed 99.51 KB 310.41 KB 88.69% (+/- <0.01%)
/d/[link]/book 190.94 KB 401.84 KB 114.81% (🟡 +0.01%)
/event-types 354.18 KB 565.08 KB 161.45% (🟡 +0.02%)
/event-types/[type] 386.72 KB 597.62 KB 170.75% (🟡 +0.01%)
/getting-started/[[...step]] 334.19 KB 545.09 KB 155.74% (🟡 +0.01%)
/more 155.88 KB 366.78 KB 104.79% (🟡 +0.02%)
/settings/admin 161.32 KB 372.22 KB 106.35% (🟡 +0.01%)
/settings/admin/apps 194.22 KB 405.12 KB 115.75% (🟡 +0.01%)
/settings/admin/apps/[category] 194.21 KB 405.11 KB 115.74% (🟡 +0.02%)
/settings/admin/impersonation 161.6 KB 372.5 KB 106.43% (🟡 +0.01%)
/settings/billing 161.44 KB 372.33 KB 106.38% (🟡 +0.01%)
/settings/developer/api-keys 190.59 KB 401.49 KB 114.71% (🟡 +0.01%)
/settings/developer/webhooks 163.93 KB 374.83 KB 107.09% (🟡 +0.02%)
/settings/developer/webhooks/[id] 194.77 KB 405.67 KB 115.91% (🟡 +0.01%)
/settings/developer/webhooks/new 194.64 KB 405.54 KB 115.87% (🟡 +0.01%)
/settings/my-account/appearance 175.4 KB 386.3 KB 110.37% (🟡 +0.01%)
/settings/my-account/calendars 195.62 KB 406.52 KB 116.15% (🟡 +0.01%)
/settings/my-account/conferencing 167.2 KB 378.1 KB 108.03% (🟡 +0.01%)
/settings/my-account/general 270.5 KB 481.4 KB 137.54% (🟡 +0.01%)
/settings/my-account/profile 429.1 KB 640 KB 182.86% (🟡 +0.01%)
/settings/security/impersonation 163.48 KB 374.38 KB 106.96% (🟡 +0.02%)
/settings/security/password 196.77 KB 407.67 KB 116.48% (🟡 +0.01%)
/settings/security/sso 171.17 KB 382.07 KB 109.16% (🟡 +0.02%)
/settings/security/two-factor-auth 165.93 KB 376.83 KB 107.66% (🟡 +0.02%)
/settings/teams 161.07 KB 371.97 KB 106.28% (🟡 +0.01%)
/settings/teams/[id]/appearance 175.42 KB 386.32 KB 110.38% (🟡 +0.01%)
/settings/teams/[id]/billing 161.3 KB 372.2 KB 106.34% (🟡 +0.02%)
/settings/teams/[id]/members 301.96 KB 512.86 KB 146.53% (🟡 +0.01%)
/settings/teams/[id]/onboard-members 74.16 KB 285.06 KB 81.45% (🟡 +0.01%)
/settings/teams/[id]/profile 273.8 KB 484.7 KB 138.48% (🟡 +0.02%)
/settings/teams/[id]/sso 171.26 KB 382.16 KB 109.19% (🟡 +0.01%)
/settings/teams/new 113.45 KB 324.35 KB 92.67% (🟡 +0.01%)
/signup 25.5 KB 236.4 KB 67.54% (🟡 +0.01%)
/team/[slug] 80.63 KB 291.53 KB 83.29% (+/- <0.01%)
/team/[slug]/[type] 99.48 KB 310.38 KB 88.68% (+/- <0.01%)
/team/[slug]/[type]/embed 99.51 KB 310.41 KB 88.69% (+/- <0.01%)
/team/[slug]/book 190.94 KB 401.84 KB 114.81% (🟡 +0.01%)
/team/[slug]/embed 80.69 KB 291.59 KB 83.31% (+/- <0.01%)
/teams 156.1 KB 367 KB 104.86% (🟡 +0.01%)
/video/meeting-ended/[uid] 22.77 KB 233.67 KB 66.76% (+/- <0.01%)
/video/meeting-not-started/[uid] 22.41 KB 233.31 KB 66.66% (+/- <0.01%)
/video/no-meeting-found 6.6 KB 217.5 KB 62.14% (+/- <0.01%)
/workflows 169 KB 379.9 KB 108.54% (🟡 +0.01%)
/workflows/[workflow] 298.85 KB 509.75 KB 145.64% (🟡 +0.02%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

>;

const PlainForm = <T extends FieldValues>(props: FormProps<T>, ref: Ref<HTMLFormElement>) => {
const PlainForm = (props: FormProps<{ apiError: string }>, ref: Ref<HTMLFormElement>) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it will, this isn't the right fix unfortunately - we can look at creating a "globalError" utility in the future but by not forwarding the T extends FieldValues it will disable/cause type errors elsewhere. This should be handled in the change password form. 🙏

@joe-shajan
Copy link
Copy Markdown
Contributor Author

By changing form.clearErrors("apiError") to form.clearErrors("root"), the issue was resolved. The form.clearErrors("root") function clears all errors prior to form submission. Therefore, I checked for the presence of apiError before proceeding.

@joe-shajan
Copy link
Copy Markdown
Contributor Author

Hey @emrysal what do you think about this solution?

@emrysal
Copy link
Copy Markdown
Contributor

emrysal commented Mar 27, 2023

A lot better! I wonder what happens when; on successful submission, the reset() function is used. Thinking about it that behaviour may feel very natural in all forms

form.reset();

@joe-shajan
Copy link
Copy Markdown
Contributor Author

A lot better! I wonder what happens when; on successful submission, the reset() function is used. Thinking about it that behaviour may feel very natural in all forms

form.reset();

Really sorry @emrysal I don't get what you meant. Are you asking me to change something?

@emrysal
Copy link
Copy Markdown
Contributor

emrysal commented Mar 27, 2023

@joeshajan Well it was more a thought from my end, if you remove the if clause and then add just a reset() - I wonder if that works "better" or similar behaviour.

@joe-shajan
Copy link
Copy Markdown
Contributor Author

joe-shajan commented Mar 27, 2023

@joeshajan Well it was more a thought from my end, if you remove the if clause and then add just a reset() - I wonder if that works "better" or similar behaviour.

Ok got it @emrysal. but if we reset the form before submitting I assume that values inside the fields will be removed and then there is nothing to submit.

So I think form.reset(); function will remove all the values inside the text field along with errors right?

Copy link
Copy Markdown
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

Yeah you're right, probably not the right fix for now. Merging this 🙇 Thank you!

@emrysal emrysal merged commit 78da570 into calcom:main Mar 27, 2023
@joe-shajan
Copy link
Copy Markdown
Contributor Author

Thanks @emrysal 🙂

@joe-shajan joe-shajan deleted the updating_password_ui_bug branch March 31, 2023 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CAL-1272] updating password ui bug

2 participants