Skip to content

Commit

Permalink
renamed editModeAndTypeUpdate function to resetEditModeTypeStates and…
Browse files Browse the repository at this point in the history
… moved some of its functionality to a new function called validateUpdateEmailErrorStates on the AccountSettings page
  • Loading branch information
corypride committed May 17, 2024
1 parent 77f6d78 commit 3bcc6cc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions publisher/src/components/Settings/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,34 @@ export const AccountSettings = () => {
const [name, setName] = React.useState<string>(userStore?.name || "");
const [isSettingInEditMode, setIsSettingInEditMode] =
React.useState<boolean>(false);
const [editType, setEditType] = React.useState<string>("");
const [editType, setEditType] = React.useState<string | undefined>(undefined);
const [isEmailValid, setIsEmailValid] = React.useState(true);
const [errorMsg, setErrorMsg] = React.useState<
{ message: string } | undefined
>(undefined);
const onClickClose = () => {
setEmail(userStore?.email || "");
editModeAndTypeUpdate();
resetEditModeTypeStates();
setName(userStore?.name || "");
setIsSettingInEditMode(false);
};
const editModeAndTypeUpdate = () => {
setIsSettingInEditMode(!isSettingInEditMode);
if (editType === EditType.Email_edit) {
setIsEmailValid(true);
setErrorMsg(undefined);
}
setEditType("");
const resetEditModeTypeStates = () => {
setIsSettingInEditMode(false);
setEditType(undefined);
};
const validateUpdateEmailErrorStates = () => {
setIsEmailValid(true);
setErrorMsg(undefined);
};
const saveNameEmailChange = (nameUpdate?: string, emailUpdate?: string) => {
if (nameUpdate) {
editModeAndTypeUpdate();
resetEditModeTypeStates();
return userStore.updateUserNameAndEmail(nameUpdate, email);
}
if (emailUpdate) {
if (validateEmail(emailUpdate)) {
editModeAndTypeUpdate();
validateUpdateEmailErrorStates();
resetEditModeTypeStates();
return userStore.updateUserNameAndEmail(name, emailUpdate);
}
setErrorMsg({ message: "Invalid Email" });
Expand Down

0 comments on commit 3bcc6cc

Please sign in to comment.