From 1a2e0abc21fd3b1c7f7d6e979009c5d6f4d88cb8 Mon Sep 17 00:00:00 2001
From: Vasilica Olariu
Date: Thu, 10 Nov 2022 16:29:45 +0200
Subject: [PATCH 1/8] lint issues in src-ts/util
---
.../ContactSupportForm.tsx | 36 +++++++++++--------
.../utils/contact-support/ContactSupport.tsx | 6 ++--
src-ts/utils/settings/account/Account.tsx | 28 ++++++++-------
.../change-password/ChangePassword.tsx | 20 ++++++-----
.../settings/account/edit-name/EditName.tsx | 20 ++++++-----
5 files changed, 64 insertions(+), 46 deletions(-)
diff --git a/src-ts/lib/contact-support-form/ContactSupportForm.tsx b/src-ts/lib/contact-support-form/ContactSupportForm.tsx
index 6a4c92470..7f63a0625 100644
--- a/src-ts/lib/contact-support-form/ContactSupportForm.tsx
+++ b/src-ts/lib/contact-support-form/ContactSupportForm.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, FC, SetStateAction, useContext, useEffect, useState } from 'react'
+import { Dispatch, FC, SetStateAction, useCallback, useContext, useEffect, useState } from 'react'
import { Form, FormDefinition, formGetInputModel, FormInputModel } from '../form'
import { LoadingSpinner } from '../loading-spinner'
@@ -19,20 +19,28 @@ const ContactSupportForm: FC = (props: ContactSupportFo
const { profile }: ProfileContextData = useContext(profileContext)
- const [loading, setLoading]: [boolean, Dispatch>] = useState(false)
- const [saveOnSuccess, setSaveOnSuccess]: [boolean, Dispatch>] = useState(false)
+ const [loading, setLoading]: [boolean, Dispatch>]
+ = useState(false)
+ const [saveOnSuccess, setSaveOnSuccess]: [boolean, Dispatch>]
+ = useState(false)
useEffect(() => {
if (!loading && saveOnSuccess) {
props.onSave()
}
- }, [loading, saveOnSuccess])
+ }, [loading, saveOnSuccess, props.onSave])
- function generateRequest(inputs: ReadonlyArray): ContactSupportRequest {
- const firstName: string = formGetInputModel(inputs, ContactSupportFormField.first).value as string
- const lastName: string = formGetInputModel(inputs, ContactSupportFormField.last).value as string
- const email: string = formGetInputModel(inputs, ContactSupportFormField.email).value as string
- const question: string = formGetInputModel(inputs, ContactSupportFormField.question).value as string
+ const generateRequest = useCallback((
+ inputs: ReadonlyArray,
+ ): ContactSupportRequest => {
+ const firstName: string
+ = formGetInputModel(inputs, ContactSupportFormField.first).value as string
+ const lastName: string
+ = formGetInputModel(inputs, ContactSupportFormField.last).value as string
+ const email: string
+ = formGetInputModel(inputs, ContactSupportFormField.email).value as string
+ const question: string
+ = formGetInputModel(inputs, ContactSupportFormField.question).value as string
return {
challengeId: props.workId,
email,
@@ -41,15 +49,15 @@ const ContactSupportForm: FC = (props: ContactSupportFo
lastName,
question,
}
- }
+ }, [props.workId])
- async function saveAsync(request: ContactSupportRequest): Promise {
+ const saveAsync = useCallback(async (request: ContactSupportRequest): Promise => {
setLoading(true)
return contactSupportSubmitRequestAsync(request)
.then(() => {
setSaveOnSuccess(true)
}).finally(() => setLoading(false))
- }
+ }, [])
const emailElement: JSX.Element | undefined = !!profile?.email
? (
@@ -69,10 +77,10 @@ const ContactSupportForm: FC = (props: ContactSupportFo
Hi
{' '}
{profile?.firstName || 'there'}
- , we're here to help.
+ , we're here to help.
- Please describe what you'd like to discuss, and a
+ Please describe what you'd like to discuss, and a
Topcoder Solutions Expert will email you back
{emailElement}
within one business day.
diff --git a/src-ts/utils/contact-support/ContactSupport.tsx b/src-ts/utils/contact-support/ContactSupport.tsx
index 2bd846335..65938aae6 100644
--- a/src-ts/utils/contact-support/ContactSupport.tsx
+++ b/src-ts/utils/contact-support/ContactSupport.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, FC, SetStateAction, useState } from 'react'
+import { Dispatch, FC, SetStateAction, useCallback, useState } from 'react'
import {
ContactSupportForm,
@@ -16,11 +16,11 @@ const ContactSupport: FC<{}> = () => {
const [formDef, setFormDef]: [FormDefinition, Dispatch>]
= useState({ ...contactSupportFormDef })
- function onSave(): void {
+ const onSave = useCallback((): void => {
const updatedForm: FormDefinition = { ...formDef }
formOnReset(formGetInputFields(updatedForm.groups || []))
setFormDef(updatedForm)
- }
+ }, [formDef])
return (
diff --git a/src-ts/utils/settings/account/Account.tsx b/src-ts/utils/settings/account/Account.tsx
index 326c8ba19..248731e5e 100644
--- a/src-ts/utils/settings/account/Account.tsx
+++ b/src-ts/utils/settings/account/Account.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
+import { Dispatch, FC, SetStateAction, useCallback, useContext, useState } from 'react'
import Modal from 'react-responsive-modal'
import {
@@ -20,24 +20,26 @@ const Account: FC<{}> = () => {
const profileContextData: ProfileContextData = useContext(profileContext)
const { profile }: ProfileContextData = profileContextData
- const [editProfileOpen, setEditNameOpen]: [boolean, Dispatch>] = useState(false)
- const [changePasswordOpen, setChangePasswordOpen]: [boolean, Dispatch>] = useState(false)
+ const [editProfileOpen, setEditNameOpen]: [boolean, Dispatch>]
+ = useState(false)
+ const [changePasswordOpen, setChangePasswordOpen]: [boolean, Dispatch>]
+ = useState(false)
- // if we don't have a profile, don't show the page
- if (!profile) {
- return <>>
- }
-
- function toggleEditName(): void {
+ const toggleEditName = useCallback((): void => {
const inputs: Array = formGetInputFields(editNameFormDef.groups || [])
formOnReset(inputs)
setEditNameOpen(!editProfileOpen)
- }
+ }, [editProfileOpen])
- function toggleChangePassword(): void {
+ const toggleChangePassword = useCallback((): void => {
const inputs: Array = formGetInputFields(editNameFormDef.groups || [])
formOnReset(inputs)
setChangePasswordOpen(!changePasswordOpen)
+ }, [changePasswordOpen])
+
+ // if we don't have a profile, don't show the page
+ if (!profile) {
+ return <>>
}
return (
@@ -68,7 +70,7 @@ const Account: FC<{}> = () => {
@@ -91,7 +93,7 @@ const Account: FC<{}> = () => {
diff --git a/src-ts/utils/settings/account/change-password/ChangePassword.tsx b/src-ts/utils/settings/account/change-password/ChangePassword.tsx
index 9857dcfdd..37f967151 100644
--- a/src-ts/utils/settings/account/change-password/ChangePassword.tsx
+++ b/src-ts/utils/settings/account/change-password/ChangePassword.tsx
@@ -1,4 +1,4 @@
-import { Dispatch, FC, SetStateAction, useContext, useState } from 'react'
+import { Dispatch, FC, SetStateAction, useCallback, useContext, useState } from 'react'
import {
ChangePasswordRequest,
@@ -25,21 +25,25 @@ const ChangePassword: FC = (props: ChangePasswordProps) =>
const [passwordForm]: [FormDefinition, Dispatch>]
= useState(changePasswordFormDef)
- function requestGenerator(inputs: ReadonlyArray): ChangePasswordRequest {
- const password: string = formGetInputModel(inputs, ChangePasswordFieldName.currentPassword).value as string
- const newPassword: string = formGetInputModel(inputs, ChangePasswordFieldName.newPassword).value as string
+ const requestGenerator = useCallback((
+ inputs: ReadonlyArray,
+ ): ChangePasswordRequest => {
+ const password: string
+ = formGetInputModel(inputs, ChangePasswordFieldName.currentPassword).value as string
+ const newPassword: string
+ = formGetInputModel(inputs, ChangePasswordFieldName.newPassword).value as string
return {
newPassword,
password,
}
- }
+ }, [])
- function save(updatedPassword: ChangePasswordRequest): Promise {
- return changePassword((profile as UserProfile).userId, updatedPassword)
+ const save = useCallback((updatedPassword: ChangePasswordRequest): Promise => (
+ changePassword((profile as UserProfile).userId, updatedPassword)
.then(() => {
props.onClose()
})
- }
+ ), [changePassword, profile, props.onClose])
return (