Skip to content

Commit 1a2e0ab

Browse files
committed
lint issues in src-ts/util
1 parent b329c34 commit 1a2e0ab

File tree

5 files changed

+64
-46
lines changed

5 files changed

+64
-46
lines changed

src-ts/lib/contact-support-form/ContactSupportForm.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, SetStateAction, useContext, useEffect, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useCallback, useContext, useEffect, useState } from 'react'
22

33
import { Form, FormDefinition, formGetInputModel, FormInputModel } from '../form'
44
import { LoadingSpinner } from '../loading-spinner'
@@ -19,20 +19,28 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
1919

2020
const { profile }: ProfileContextData = useContext(profileContext)
2121

22-
const [loading, setLoading]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
23-
const [saveOnSuccess, setSaveOnSuccess]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
22+
const [loading, setLoading]: [boolean, Dispatch<SetStateAction<boolean>>]
23+
= useState<boolean>(false)
24+
const [saveOnSuccess, setSaveOnSuccess]: [boolean, Dispatch<SetStateAction<boolean>>]
25+
= useState<boolean>(false)
2426

2527
useEffect(() => {
2628
if (!loading && saveOnSuccess) {
2729
props.onSave()
2830
}
29-
}, [loading, saveOnSuccess])
31+
}, [loading, saveOnSuccess, props.onSave])
3032

31-
function generateRequest(inputs: ReadonlyArray<FormInputModel>): ContactSupportRequest {
32-
const firstName: string = formGetInputModel(inputs, ContactSupportFormField.first).value as string
33-
const lastName: string = formGetInputModel(inputs, ContactSupportFormField.last).value as string
34-
const email: string = formGetInputModel(inputs, ContactSupportFormField.email).value as string
35-
const question: string = formGetInputModel(inputs, ContactSupportFormField.question).value as string
33+
const generateRequest = useCallback((
34+
inputs: ReadonlyArray<FormInputModel>,
35+
): ContactSupportRequest => {
36+
const firstName: string
37+
= formGetInputModel(inputs, ContactSupportFormField.first).value as string
38+
const lastName: string
39+
= formGetInputModel(inputs, ContactSupportFormField.last).value as string
40+
const email: string
41+
= formGetInputModel(inputs, ContactSupportFormField.email).value as string
42+
const question: string
43+
= formGetInputModel(inputs, ContactSupportFormField.question).value as string
3644
return {
3745
challengeId: props.workId,
3846
email,
@@ -41,15 +49,15 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
4149
lastName,
4250
question,
4351
}
44-
}
52+
}, [props.workId])
4553

46-
async function saveAsync(request: ContactSupportRequest): Promise<void> {
54+
const saveAsync = useCallback(async (request: ContactSupportRequest): Promise<void> => {
4755
setLoading(true)
4856
return contactSupportSubmitRequestAsync(request)
4957
.then(() => {
5058
setSaveOnSuccess(true)
5159
}).finally(() => setLoading(false))
52-
}
60+
}, [])
5361

5462
const emailElement: JSX.Element | undefined = !!profile?.email
5563
? (
@@ -69,10 +77,10 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
6977
Hi
7078
{' '}
7179
{profile?.firstName || 'there'}
72-
, we're here to help.
80+
, we&apos;re here to help.
7381
</p>
7482
<p>
75-
Please describe what you'd like to discuss, and a
83+
Please describe what you&apos;d like to discuss, and a
7684
Topcoder Solutions Expert will email you back
7785
{emailElement}
7886
&nbsp;within one business day.

src-ts/utils/contact-support/ContactSupport.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, SetStateAction, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useCallback, useState } from 'react'
22

33
import {
44
ContactSupportForm,
@@ -16,11 +16,11 @@ const ContactSupport: FC<{}> = () => {
1616
const [formDef, setFormDef]: [FormDefinition, Dispatch<SetStateAction<FormDefinition>>]
1717
= useState<FormDefinition>({ ...contactSupportFormDef })
1818

19-
function onSave(): void {
19+
const onSave = useCallback((): void => {
2020
const updatedForm: FormDefinition = { ...formDef }
2121
formOnReset(formGetInputFields(updatedForm.groups || []))
2222
setFormDef(updatedForm)
23-
}
23+
}, [formDef])
2424

2525
return (
2626
<ContentLayout title={toolTitle}>

src-ts/utils/settings/account/Account.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useCallback, useContext, useState } from 'react'
22
import Modal from 'react-responsive-modal'
33

44
import {
@@ -20,24 +20,26 @@ const Account: FC<{}> = () => {
2020
const profileContextData: ProfileContextData = useContext(profileContext)
2121
const { profile }: ProfileContextData = profileContextData
2222

23-
const [editProfileOpen, setEditNameOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
24-
const [changePasswordOpen, setChangePasswordOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
23+
const [editProfileOpen, setEditNameOpen]: [boolean, Dispatch<SetStateAction<boolean>>]
24+
= useState<boolean>(false)
25+
const [changePasswordOpen, setChangePasswordOpen]: [boolean, Dispatch<SetStateAction<boolean>>]
26+
= useState<boolean>(false)
2527

26-
// if we don't have a profile, don't show the page
27-
if (!profile) {
28-
return <></>
29-
}
30-
31-
function toggleEditName(): void {
28+
const toggleEditName = useCallback((): void => {
3229
const inputs: Array<FormInputModel> = formGetInputFields(editNameFormDef.groups || [])
3330
formOnReset(inputs)
3431
setEditNameOpen(!editProfileOpen)
35-
}
32+
}, [editProfileOpen])
3633

37-
function toggleChangePassword(): void {
34+
const toggleChangePassword = useCallback((): void => {
3835
const inputs: Array<FormInputModel> = formGetInputFields(editNameFormDef.groups || [])
3936
formOnReset(inputs)
4037
setChangePasswordOpen(!changePasswordOpen)
38+
}, [changePasswordOpen])
39+
40+
// if we don't have a profile, don't show the page
41+
if (!profile) {
42+
return <></>
4143
}
4244

4345
return (
@@ -68,7 +70,7 @@ const Account: FC<{}> = () => {
6870
<Button
6971
label='edit name'
7072
onClick={toggleEditName}
71-
tabIndex={1}
73+
tabIndex={-1}
7274
buttonStyle='secondary'
7375
/>
7476
</Card>
@@ -91,7 +93,7 @@ const Account: FC<{}> = () => {
9193
<Button
9294
label='change password'
9395
onClick={toggleChangePassword}
94-
tabIndex={2}
96+
tabIndex={-1}
9597
buttonStyle='secondary'
9698
/>
9799
</Card>

src-ts/utils/settings/account/change-password/ChangePassword.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useCallback, useContext, useState } from 'react'
22

33
import {
44
ChangePasswordRequest,
@@ -25,21 +25,25 @@ const ChangePassword: FC<ChangePasswordProps> = (props: ChangePasswordProps) =>
2525
const [passwordForm]: [FormDefinition, Dispatch<SetStateAction<FormDefinition>>]
2626
= useState<FormDefinition>(changePasswordFormDef)
2727

28-
function requestGenerator(inputs: ReadonlyArray<FormInputModel>): ChangePasswordRequest {
29-
const password: string = formGetInputModel(inputs, ChangePasswordFieldName.currentPassword).value as string
30-
const newPassword: string = formGetInputModel(inputs, ChangePasswordFieldName.newPassword).value as string
28+
const requestGenerator = useCallback((
29+
inputs: ReadonlyArray<FormInputModel>,
30+
): ChangePasswordRequest => {
31+
const password: string
32+
= formGetInputModel(inputs, ChangePasswordFieldName.currentPassword).value as string
33+
const newPassword: string
34+
= formGetInputModel(inputs, ChangePasswordFieldName.newPassword).value as string
3135
return {
3236
newPassword,
3337
password,
3438
}
35-
}
39+
}, [])
3640

37-
function save(updatedPassword: ChangePasswordRequest): Promise<void> {
38-
return changePassword((profile as UserProfile).userId, updatedPassword)
41+
const save = useCallback((updatedPassword: ChangePasswordRequest): Promise<void> => (
42+
changePassword((profile as UserProfile).userId, updatedPassword)
3943
.then(() => {
4044
props.onClose()
4145
})
42-
}
46+
), [changePassword, profile, props.onClose])
4347

4448
return (
4549
<Form

src-ts/utils/settings/account/edit-name/EditName.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
1+
import { Dispatch, FC, SetStateAction, useCallback, useContext, useState } from 'react'
22

33
import {
44
EditNameRequest,
@@ -26,17 +26,21 @@ const EditName: FC<EditNameProps> = (props: EditNameProps) => {
2626
const [profileForm]: [FormDefinition, Dispatch<SetStateAction<FormDefinition>>]
2727
= useState<FormDefinition>(editNameFormDef)
2828

29-
function requestGenerator(inputs: ReadonlyArray<FormInputModel>): EditNameRequest {
30-
const firstName: string = formGetInputModel(inputs, EditNameFieldName.firstName).value as string
31-
const lastName: string = formGetInputModel(inputs, EditNameFieldName.lastName).value as string
29+
const requestGenerator = useCallback((
30+
inputs: ReadonlyArray<FormInputModel>,
31+
): EditNameRequest => {
32+
const firstName: string
33+
= formGetInputModel(inputs, EditNameFieldName.firstName).value as string
34+
const lastName: string
35+
= formGetInputModel(inputs, EditNameFieldName.lastName).value as string
3236
return {
3337
firstName,
3438
lastName,
3539
}
36-
}
40+
}, [])
3741

38-
function saveProfile(updatedProfile: EditNameRequest): Promise<void> {
39-
return updateProfile({
42+
const saveProfile = useCallback((updatedProfile: EditNameRequest): Promise<void> => (
43+
updateProfile({
4044
...profileContextData,
4145
profile: {
4246
...profileContextData.profile as UserProfile,
@@ -47,7 +51,7 @@ const EditName: FC<EditNameProps> = (props: EditNameProps) => {
4751
.then(() => {
4852
props.onClose()
4953
})
50-
}
54+
), [profileContextData, props.onClose, updateProfile])
5155

5256
return (
5357
<Form

0 commit comments

Comments
 (0)