Skip to content

Commit

Permalink
Variable name updates
Browse files Browse the repository at this point in the history
  • Loading branch information
7emansell committed Nov 25, 2024
1 parent 0bcf57d commit bc4f37e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/components/MyAccount/NewSettings/UsernameForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
* Within this form, the user NOT having a username is represented by: username = null, so the
* empty string is an invalid username.
*/
const [input, setInput] = useState(
const [usernameInSierra, setusernameInSierra] = useState(
patron.username === "" ? null : patron.username
)
const [tempInput, setTempInput] = useState(input)
const currentUsernameNotDeleted = tempInput !== null
const [tempUsername, setTempUsername] = useState(usernameInSierra)
const currentUsernameNotDeleted = tempUsername !== null

const { setUsernameStatus, setUsernameStatusMessage } = usernameState

Expand All @@ -52,14 +52,14 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
}

const cancelEditing = () => {
setTempInput(input)
setTempUsername(usernameInSierra)
setIsEditing(false)
setError(false)
}

const handleInputChange = (e) => {
const { value } = e.target
setTempInput(value)
setTempUsername(value)
if (!validateUsername(value)) {
setError(true)
} else {
Expand All @@ -71,7 +71,7 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
setIsLoading(true)
setIsEditing(false)
setUsernameStatus("")
const submissionInput = tempInput === null ? "" : tempInput
const submissionInput = tempUsername === null ? "" : tempUsername
try {
const response = await fetch(
`${BASE_URL}/api/account/username/${patron.id}`,
Expand All @@ -87,16 +87,16 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
if (responseMessage !== "Username taken" && response.status === 200) {
await getMostUpdatedSierraAccountData()
setUsernameStatus("success")
setInput(submissionInput)
setTempInput(submissionInput)
setusernameInSierra(submissionInput)
setTempUsername(submissionInput)
} else {
setUsernameStatus("failure")
setUsernameStatusMessage(
responseMessage === "Username taken"
? usernameStatusMessages.USERNAME_FAILURE
: usernameStatusMessages.FAILURE
)
setTempInput(input)
setTempUsername(usernameInSierra)
}
} catch (error) {
setUsernameStatus("failure")
Expand All @@ -123,11 +123,11 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
color: error ? "ui.error.primary" : "ui.black",
},
}}
value={tempInput}
value={tempUsername}
id="username-input"
labelText="Must be 5-15 characters and use only letters (a-z) and numbers (0-9)"
showLabel
isInvalid={error && !validateUsername(tempInput)}
isInvalid={error && !validateUsername(tempUsername)}
showHelperInvalidText={false}
onChange={handleInputChange}
isClearable
Expand All @@ -138,7 +138,7 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
buttonType="text"
id="remove-username-btn"
onClick={() => {
setTempInput(null)
setTempUsername(null)
setError(false)
}}
>
Expand All @@ -156,10 +156,10 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {

const notEditingView = (
<Flex alignItems="center" marginTop={{ base: "unset", md: "-xs" }}>
{input ? (
{usernameInSierra ? (
<>
<Text size="body1" sx={{ marginBottom: 0 }}>
{input}
{usernameInSierra}
</Text>
<EditButton
buttonId="edit-username-button"
Expand All @@ -171,7 +171,7 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
label="+ Add username"
onClick={() => {
setIsEditing(true)
setTempInput("")
setTempUsername("")
setError(true)
}}
/>
Expand All @@ -192,7 +192,7 @@ const UsernameForm = ({ patron, usernameState }: UsernameFormProps) => {
<AddButton
label="+ Add username"
onClick={() => {
setTempInput("")
setTempUsername("")
setError(true)
}}
/>
Expand Down

0 comments on commit bc4f37e

Please sign in to comment.