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 field validation to resolve the Update Profile Issue #8809

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
138 changes: 3 additions & 135 deletions package-lock.json
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useReducer, FormEvent } from "react";
import { useState, useReducer, FormEvent, useEffect } from "react";
import { GENDER_TYPES } from "../../Common/constants";
import { validateEmailAddress } from "../../Common/validation";
import * as Notification from "../../Utils/Notifications.js";
Expand Down Expand Up @@ -117,6 +117,8 @@ export default function UserProfile() {
isChecking: false,
isUpdateAvailable: false,
});
const [hasChanges, setHasChanges] = useState<boolean>(false);
const [isFieldLoaded, setIsFieldLoaded] = useState<boolean>(false);

rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
const authUser = useAuthUser();

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

Expand Down Expand Up @@ -324,8 +327,18 @@ export default function UserProfile() {
type: "set_form",
form: { ...states.form, [event.name]: event.value },
});
setIsFieldLoaded(true);
};

useEffect(() => {
if (showEdit && isFieldLoaded) {
setHasChanges(true);
} else {
setIsFieldLoaded(false);
setHasChanges(false);
}
}, [handleFieldChange]);

const getDate = (value: any) =>
value && dayjs(value).isValid() && dayjs(value).toDate();

Expand Down Expand Up @@ -788,7 +801,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={!hasChanges}
/>
</div>
</div>
</form>
Expand Down
Loading