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

Fix: Switch to shadcn form in userResetPassword #9708

Open
wants to merge 101 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
a3fd192
update to shadcn form in userresetpassword
AdityaJ2305 Jan 3, 2025
553e6da
deleted old form
AdityaJ2305 Jan 3, 2025
866e702
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 3, 2025
d2cfca6
fix linting error
AdityaJ2305 Jan 3, 2025
c170f70
update to mutate
AdityaJ2305 Jan 3, 2025
7cd3287
update to old_password
AdityaJ2305 Jan 3, 2025
935bc5b
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 3, 2025
5b60da4
ispending
AdityaJ2305 Jan 3, 2025
9396763
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 3, 2025
ee0f76f
update the error
AdityaJ2305 Jan 3, 2025
0da92f6
fix the usemutate
AdityaJ2305 Jan 3, 2025
d56f6d3
fix the usemutate
AdityaJ2305 Jan 3, 2025
fb93eca
use of toast and update to use translation
AdityaJ2305 Jan 3, 2025
ea545c4
deleted formcontext
AdityaJ2305 Jan 3, 2025
ce9f885
update global error handler
AdityaJ2305 Jan 3, 2025
5582897
update global error handler
AdityaJ2305 Jan 3, 2025
92186e2
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 3, 2025
1b6279a
fix bracket
AdityaJ2305 Jan 3, 2025
4008161
fix bracket
AdityaJ2305 Jan 3, 2025
cea1205
Update src/Utils/request/errorHandler.ts
AdityaJ2305 Jan 3, 2025
499ec49
move to seperate func
AdityaJ2305 Jan 3, 2025
812d341
lint fixed
AdityaJ2305 Jan 3, 2025
198b220
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 4, 2025
8302ab5
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 4, 2025
5f9432e
fix the types and typo changes and strucutured code
AdityaJ2305 Jan 5, 2025
8eaa25e
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 5, 2025
91ed1d8
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 5, 2025
9728bbe
fix the string error hadler
AdityaJ2305 Jan 5, 2025
b9e32bc
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 5, 2025
d2250a6
fix the structure of handlers
AdityaJ2305 Jan 5, 2025
3b4edfe
Empty-Commit
AdityaJ2305 Jan 5, 2025
86a97b0
fix merge conflicts
AdityaJ2305 Jan 5, 2025
fa1780c
fix merge conflicts
AdityaJ2305 Jan 5, 2025
2e5be57
keep things simpler
rithviknishad Jan 5, 2025
4f31010
update to shadcn form in userresetpassword
AdityaJ2305 Jan 3, 2025
b780559
deleted old form
AdityaJ2305 Jan 3, 2025
9ca5d7d
fix linting error
AdityaJ2305 Jan 3, 2025
685e3a9
update to mutate
AdityaJ2305 Jan 3, 2025
d958bd7
update to old_password
AdityaJ2305 Jan 3, 2025
b703a50
ispending
AdityaJ2305 Jan 3, 2025
54defa1
update the error
AdityaJ2305 Jan 3, 2025
74c445e
fix the usemutate
AdityaJ2305 Jan 3, 2025
c3aa9c6
fix the usemutate
AdityaJ2305 Jan 3, 2025
96e5c26
use of toast and update to use translation
AdityaJ2305 Jan 3, 2025
a84c44c
deleted formcontext
AdityaJ2305 Jan 3, 2025
da22f88
update global error handler
AdityaJ2305 Jan 3, 2025
eb68ff7
update global error handler
AdityaJ2305 Jan 3, 2025
1aa1eb8
fix bracket
AdityaJ2305 Jan 3, 2025
7be24cd
fix bracket
AdityaJ2305 Jan 3, 2025
c4b37e0
Update src/Utils/request/errorHandler.ts
AdityaJ2305 Jan 3, 2025
34321e7
move to seperate func
AdityaJ2305 Jan 3, 2025
0546626
lint fixed
AdityaJ2305 Jan 3, 2025
0f1bce7
Added no user assingned message (#9666)
AnveshNalimela Jan 4, 2025
00f1150
Remove facility name from facility users page (#9746)
Mahendar0701 Jan 4, 2025
8708f27
fix the types and typo changes and strucutured code
AdityaJ2305 Jan 5, 2025
636f423
fix the string error hadler
AdityaJ2305 Jan 5, 2025
e558872
Enhance organization management by adding new organization types and …
bodhish Jan 5, 2025
15790e9
Cancel button fix in Book Appointment screen (#9757)
arhamathar Jan 5, 2025
dd7109a
Add public flag to facility (#9759)
bodhish Jan 5, 2025
81f4591
Auto-Hide Sidebar on mobile (#9758)
abhimanyurajeesh Jan 5, 2025
d4a3946
Implement Permission Context and Update User Permissions Handling
bodhish Jan 5, 2025
27fa3f2
fix the structure of handlers
AdityaJ2305 Jan 5, 2025
8f46160
Empty-Commit
AdityaJ2305 Jan 5, 2025
7ba4b5a
fix merge conflicts
AdityaJ2305 Jan 5, 2025
ca6214c
fix merge conflicts
AdityaJ2305 Jan 5, 2025
a78ae3c
keep things simpler
rithviknishad Jan 5, 2025
020d1b4
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 5, 2025
1fd7b0f
fix merge conflicts
AdityaJ2305 Jan 5, 2025
2464dca
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 5, 2025
07a1d09
fix lint sfter merge
AdityaJ2305 Jan 5, 2025
a5224e8
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 5, 2025
573d2f5
fix lint sfter merge
AdityaJ2305 Jan 5, 2025
9b6359b
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 5, 2025
e4426ff
shift to shadcn input and add the eye toggle
AdityaJ2305 Jan 5, 2025
fb72841
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 5, 2025
0a6d437
same password validation check
AdityaJ2305 Jan 6, 2025
5055633
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 6, 2025
26124ea
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 6, 2025
a92ccce
reset input field
AdityaJ2305 Jan 6, 2025
781799e
create passport input
AdityaJ2305 Jan 6, 2025
ae8ea3a
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 6, 2025
9fcda51
create passport input
AdityaJ2305 Jan 6, 2025
e944de4
update to passwordinput
AdityaJ2305 Jan 6, 2025
432b7e9
update ResetPassword.tsx
AdityaJ2305 Jan 6, 2025
0aa7483
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 6, 2025
ae7bcbe
update ResetPassword.tsx
AdityaJ2305 Jan 6, 2025
333cf29
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 6, 2025
0129ee2
lint error
AdityaJ2305 Jan 6, 2025
61b6760
update the design and fix zod issue
AdityaJ2305 Jan 6, 2025
6a21bca
update the design and fix zod issue
AdityaJ2305 Jan 6, 2025
013faa8
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 6, 2025
69b1397
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 7, 2025
939d70f
remove unnecessary code
AdityaJ2305 Jan 7, 2025
4e5cf4a
Update src/components/ui/input.tsx
rithviknishad Jan 7, 2025
4cc2c24
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 7, 2025
bcb806b
added code changes from rithvik pr
AdityaJ2305 Jan 7, 2025
f8fe6a2
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 7, 2025
576e356
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 7, 2025
751dad1
handle msg object string
AdityaJ2305 Jan 7, 2025
f538569
Merge branch 'issue/9683/userResetPassword_form_switch' of https://gi…
AdityaJ2305 Jan 7, 2025
e182787
Merge branch 'develop' into issue/9683/userResetPassword_form_switch
AdityaJ2305 Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@
"created_on": "Created On",
"csv_file_in_the_specified_format": "Select a CSV file in the specified format",
"current_address": "Current Address",
"current_password": "Current Password",
"current_status": "Current Status",
"customer_support_email": "Customer Support Email",
"customer_support_name": "Customer Support Name",
Expand Down Expand Up @@ -1283,6 +1282,7 @@
"occupancy": "Occupancy",
"occupation": "Occupation",
"occupied": "Occupied",
"old_password": "Current Password",
"on": "on",
"on_emergency_basis": " on emergency basis",
"ongoing_medications": "Ongoing Medications",
Expand Down Expand Up @@ -1318,6 +1318,7 @@
"password_reset_success": "Password Reset successfully",
"password_sent": "Password Reset Email Sent",
"password_update_error": "Error while updating password. Try again later.",
"password_updated": "Password updated successfully",
"password_uppercase_validation": "Password must contain at least one uppercase letter (A-Z)",
"password_validation": "Password must contain at least: 8 characters, 1 uppercase letter (A-Z), 1 lowercase letter (a-z), and 1 number (0-9)",
"patient": "Patient",
Expand Down Expand Up @@ -1393,6 +1394,7 @@
"please_check_your_messages": "Please check your messages",
"please_confirm_password": "Please confirm your new password.",
"please_enter_a_reason_for_the_shift": "Please enter a reason for the shift.",
"please_enter_confirm_password": "Please confirm your new password",
"please_enter_current_password": "Please enter your current password.",
"please_enter_new_password": "Please enter your new password.",
"please_enter_username": "Please enter the username",
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/request/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const routes = {
updatePassword: {
path: "/api/v1/password_change/",
method: "PUT",
TRes: Type<Record<string, string | string[]>>(),
TRes: Type<{ message: string }>(),
TBody: Type<UpdatePasswordForm>(),
},
// User Endpoints
Expand Down
25 changes: 24 additions & 1 deletion src/Utils/request/errorHandler.ts
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { navigate } from "raviger";
import { toast } from "sonner";

import * as Notifications from "@/Utils/Notifications";
import { HTTPError } from "@/Utils/request/types";
import { HTTPError, StructuredError } from "@/Utils/request/types";

export function handleHttpError(error: Error) {
if (error.name === "AbortError") {
Expand Down Expand Up @@ -36,6 +36,12 @@ export function handleHttpError(error: Error) {
handlePydanticErrors(errs);
Copy link
Contributor

@Jacobjeevan Jacobjeevan Jan 7, 2025

Choose a reason for hiding this comment

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

You will need to modify handlePydanticErrors to get this working; it will fail when loc is undefined.

const location = loc?.join(".") ? `: '${loc.join(".")}'` : "";
const message = typeof msg === "object" ? (Object.values(msg)[0] as string) : msg;
toast.error(`${title}${location}`, {
      description: message,
      duration: 8000,
    });
image

We might need to modify the handleHttpError to be a functional component (to add support for translations?).
Though that might be unnecessary given we would have FE validations anyways.

cc: @rithviknishad

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@AdityaJ2305 maybe cherrypick that file changes from my PR alone here.

Copy link
Contributor

@Jacobjeevan Jacobjeevan Jan 7, 2025

Choose a reason for hiding this comment

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

Following up, just talked to Rithvik as well - msg can be an object, so you need to handle accordingly, so get the first value (there should only be one anyways).

To clarify, you will have cases where loc is undefined and msg is an object (off the top of my head, I don't recall if there are cases in the new BE where msg is a string, but let's handle that to be safe).

Copy link
Member

@rithviknishad rithviknishad Jan 7, 2025

Choose a reason for hiding this comment

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

yup, there are cases where msg is string too, when non field errors are there. I made that change coz scheduling had it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Jacobjeevan, just a quick doubt—based on the screenshot you shared, I’m assuming you’re on the UserCreateForm . Since it already has frontend validations, did you try removing them to test? Or is it from a different form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-01-07 at 4 00 48 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jacobjeevan, just a quick doubt—based on the screenshot you shared, I’m assuming you’re on the UserCreateForm . Since it already has frontend validations, did you try removing them to test? Or is it from a different form?

yep

Copy link
Contributor

@Jacobjeevan Jacobjeevan Jan 7, 2025

Choose a reason for hiding this comment

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

Following up, just talked to Rithvik as well - msg can be an object, so you need to handle accordingly, so get the first value (there should only be one anyways).

To clarify, you will have cases where loc is undefined and msg is an object (off the top of my head, I don't recall if there are cases in the new BE where msg is a string, but let's handle that to be safe).

☝️

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to handle both

(1) Loc is undefined
(2) Msg is object or string.

return;
}

if (isStructuredError(cause)) {
handleStructuredErrors(cause);
return;
}

Notifications.BadRequest({ errs });
return;
}
Expand Down Expand Up @@ -76,6 +82,23 @@ type PydanticError = {
url: string;
};

function isStructuredError(err: HTTPError["cause"]): err is StructuredError {
return typeof err === "object" && !Array.isArray(err);
}

function handleStructuredErrors(cause: StructuredError) {
for (const value of Object.values(cause)) {
if (Array.isArray(value)) {
value.forEach((err) => toast.error(err));
return;
}
if (typeof value === "string") {
toast.error(value);
return;
}
}
}
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved

function isPydanticError(errors: unknown): errors is PydanticError[] {
return (
Array.isArray(errors) &&
Expand Down
4 changes: 3 additions & 1 deletion src/Utils/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export interface APICallOptions<TBody = unknown> {
headers?: HeadersInit;
}

type HTTPErrorCause = Record<string, unknown> | undefined;
export type StructuredError = Record<string, string | string[]>;

type HTTPErrorCause = StructuredError | Record<string, unknown> | undefined;

export class HTTPError extends Error {
status: number;
Expand Down
1 change: 1 addition & 0 deletions src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {
FormContextValue,
createFormContext,
} from "@/components/Form/FormContext";

Check failure on line 9 in src/components/Form/Form.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (1)

Cannot find module '@/components/Form/FormContext' or its corresponding type declarations.
import { FieldChangeEvent } from "@/components/Form/FormFields/Utils";
import {
FormDetails,
Expand Down Expand Up @@ -167,3 +167,4 @@
};

export default Form;

Check failure on line 170 in src/components/Form/Form.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
19 changes: 0 additions & 19 deletions src/components/Form/FormContext.ts

This file was deleted.

Loading
Loading