Skip to content

Commit

Permalink
Add field validation to resolve the Update Profile Issue (#8809)
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidSumra authored Oct 23, 2024
1 parent 594c0d8 commit ed3c32a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
7 changes: 2 additions & 5 deletions cypress/e2e/users_spec/UsersCreation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ describe("User Creation", () => {
);
userCreationPage.typeIntoElementByIdPostClear("lastName", "Cypress");
userCreationPage.selectDropdownOption("gender", "Male");
userCreationPage.typeIntoElementByIdPostClear(
"phoneNumber",
"+91" + phone_number,
);
userCreationPage.typeIntoElementByIdPostClear("phoneNumber", phone_number);
userCreationPage.typeIntoElementByIdPostClear(
"altPhoneNumber",
"+91" + emergency_phone_number,
emergency_phone_number,
);
userCreationPage.typeIntoElementByIdPostClear("email", "test@test.com");
userCreationPage.typeIntoElementByIdPostClear("weekly_working_hours", "14");
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/users_spec/UsersProfile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Manage User Profile", () => {
const date_of_birth = "01011999";
const gender = "Male";
const email = "test@example.com";
const phone = "+918899887788";
const phone = "8899887788";
const workinghours = "8";
const qualification = "MBBS";
const doctorYoE = "10";
Expand Down
2 changes: 1 addition & 1 deletion cypress/pageobject/Facility/FacilityLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class FacilityLocation {
}

clickNotification() {
cy.get(".pnotify").click();
cy.get(".pnotify-container").click();
}

enterBedName(name: string) {
Expand Down
6 changes: 1 addition & 5 deletions src/components/Form/FormFields/PhoneNumberFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ export default function PhoneNumberFormField(props: Props) {
}
}, [setValue]);

useEffect(() => {
setValue(field.value || "+91");
}, []);

return (
<FormField
field={{
Expand Down Expand Up @@ -182,7 +178,7 @@ const formatPhoneNumber = (
value: string | undefined,
types: PhoneNumberType[],
) => {
if (value == null) {
if (!value) {
return "+91 ";
}

Expand Down
9 changes: 8 additions & 1 deletion src/components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default function UserProfile() {
isChecking: false,
isUpdateAvailable: false,
});
const [dirty, setDirty] = useState<boolean>(false);

const authUser = useAuthUser();

Expand Down Expand Up @@ -181,6 +182,7 @@ export default function UserProfile() {
type: "set_form",
form: formData,
});
setDirty(false);
},
});

Expand Down Expand Up @@ -333,6 +335,7 @@ export default function UserProfile() {
type: "set_form",
form: { ...states.form, [event.name]: event.value },
});
setDirty(true);
};

const getDate = (value: any) =>
Expand Down Expand Up @@ -857,7 +860,11 @@ export default function UserProfile() {
</div>
</div>
<div className="bg-secondary-50 px-4 py-3 text-right sm:px-6">
<Submit onClick={handleSubmit} label={t("update")} />
<Submit
onClick={handleSubmit}
label={t("update")}
disabled={!dirty}
/>
</div>
</div>
</form>
Expand Down

0 comments on commit ed3c32a

Please sign in to comment.