From d4fb43637ae37b7495a3895cda0136597a5f43c2 Mon Sep 17 00:00:00 2001 From: kimsanglok Date: Sun, 9 Oct 2022 18:20:41 +0900 Subject: [PATCH] refactor: migrate EmailField file to typescript --- .../{EmailField.js => EmailField.tsx} | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) rename frontend/src/components/form/EmailField/{EmailField.js => EmailField.tsx} (86%) diff --git a/frontend/src/components/form/EmailField/EmailField.js b/frontend/src/components/form/EmailField/EmailField.tsx similarity index 86% rename from frontend/src/components/form/EmailField/EmailField.js rename to frontend/src/components/form/EmailField/EmailField.tsx index 61bb1953c..74dd49b57 100644 --- a/frontend/src/components/form/EmailField/EmailField.js +++ b/frontend/src/components/form/EmailField/EmailField.tsx @@ -1,37 +1,53 @@ -import classNames from "classnames"; -import PropTypes from "prop-types"; import { useEffect } from "react"; +import classNames from "classnames"; + +import Label from "../../@common/Label/Label"; +import TextInput from "../../@common/TextInput/TextInput"; +import Button, { BUTTON_VARIANT } from "../../@common/Button/Button"; + +import { SIGN_UP_FORM_NAME } from "../../../hooks/useSignUpForm"; +import useTimer from "../../../hooks/useTimer"; + import { fetchAuthenticationCode, fetchVerifyAuthenticationCode } from "../../../api"; import { FORM } from "../../../constants/form"; import { ERROR_MESSAGE } from "../../../constants/messages"; -import { SIGN_UP_FORM_NAME } from "../../../hooks/useSignUpForm"; -import useTimer from "../../../hooks/useTimer"; import { formatTimerText } from "../../../utils/format/date"; -import Button, { BUTTON_VARIANT } from "../../@common/Button/Button"; -import Label from "../../@common/Label/Label"; -import TextInput from "../../@common/TextInput/TextInput"; +import { ValueOf } from "../../../../types/utility"; import styles from "./EmailField.module.css"; export const EMAIL_STATUS = { INPUT: "input", WAITING_AUTHENTICATION: "waiting for authentication", AUTHENTICATED: "authenticated", -}; +} as const; const AUTHENTICATED_CODE_VALIDITY_SECONDS = 600; +type EmailFieldProps = { + emailValue: string; + emailErrorMessage: string; + authenticationCodeValue: string; + authenticationCodeErrorMessage: string; + emailStatus: ValueOf; + onChangeEmail: React.ChangeEventHandler; + onChangeAuthenticationCode: React.ChangeEventHandler; + resetAuthenticationCode: () => void; + setEmailStatus: React.Dispatch>>; + setErrorMessage: (name: string, errorMessage: string) => void; +}; + const EmailField = ({ emailValue, emailErrorMessage, - onChangeEmail, authenticationCodeValue, authenticationCodeErrorMessage, + emailStatus, + onChangeEmail, onChangeAuthenticationCode, resetAuthenticationCode, - emailStatus, setEmailStatus, setErrorMessage, -}) => { +}: EmailFieldProps) => { const { timerSeconds, startTimer, resetTimer } = useTimer(AUTHENTICATED_CODE_VALIDITY_SECONDS); const getEmailButton = () => { @@ -56,15 +72,11 @@ const EmailField = ({ } if (emailStatus === EMAIL_STATUS.AUTHENTICATED) { - return ( -
- ✓ -
- ); + return
; } }; - const handleChangeEmail = (event) => { + const handleChangeEmail: React.ChangeEventHandler = (event) => { setEmailStatus(EMAIL_STATUS.INPUT); resetAuthenticationCode(); onChangeEmail(event); @@ -173,16 +185,4 @@ const EmailField = ({ ); }; -EmailField.propTypes = { - emailValue: PropTypes.string.isRequired, - emailErrorMessage: PropTypes.string, - onChangeEmail: PropTypes.func.isRequired, - authenticationCodeValue: PropTypes.string.isRequired, - authenticationCodeErrorMessage: PropTypes.string, - onChangeAuthenticationCode: PropTypes.func.isRequired, - resetAuthenticationCode: PropTypes.func.isRequired, - emailStatus: PropTypes.string.isRequired, - setEmailStatus: PropTypes.func.isRequired, -}; - export default EmailField;