|
| 1 | +import React, { useState } from "react"; |
| 2 | +import Label from "../layout/Label"; |
| 3 | +import LoginSignupInputBox from "../layout/input/LoginSignupInputBox"; |
| 4 | +import IsModal from "../modal/Modal"; |
| 5 | +import { useRef } from "react"; |
| 6 | +import { LoginApi } from "../../api/LoginApi"; |
| 7 | + |
| 8 | +const InputEmail = () => { |
| 9 | + const emailRef = useRef(); |
| 10 | + const authenticationNumberRef = useRef(); |
| 11 | + const [style, setStyle] = useState({ |
| 12 | + bgColorEmail: "bg-inputBox", |
| 13 | + shadowEmail: "", |
| 14 | + bgColorAuthenticationNumber: "bg-inputBox", |
| 15 | + shadowAuthenticationNumber: "", |
| 16 | + }); |
| 17 | + const [regulation, setRegulation] = useState(""); |
| 18 | + const [isOpen, setOpen] = useState(false); |
| 19 | + const [ModalStr, setModalStr] = useState({ |
| 20 | + modalTitle: "", |
| 21 | + modalMessage: "", |
| 22 | + }); |
| 23 | + const [isLoding, setIsLoding] = useState(false); |
| 24 | + const [InputCheck, setInputCheck] = useState(false); |
| 25 | + const onModalOpen = () => { |
| 26 | + setOpen({ isOpen: true }); |
| 27 | + }; |
| 28 | + const onMoalClose = () => { |
| 29 | + setOpen({ isOpen: false }); |
| 30 | + }; |
| 31 | + |
| 32 | + const onInputColor = (event) => { |
| 33 | + const { id, value } = event.target; |
| 34 | + if (id === "email") { |
| 35 | + console.log("email입니다"); |
| 36 | + setStyle(() => ({ |
| 37 | + ...style, |
| 38 | + bgColorEmail: "bg-inputBoxFocus", |
| 39 | + shadowEmail: "drop-shadow-inputBoxShadow", |
| 40 | + })); |
| 41 | + if (value.trim() === "") { |
| 42 | + setStyle(() => ({ |
| 43 | + ...style, |
| 44 | + bgColorEmail: "bg-inputBox", |
| 45 | + shadowEmail: "", |
| 46 | + })); |
| 47 | + } |
| 48 | + } else { |
| 49 | + setStyle(() => ({ |
| 50 | + ...style, |
| 51 | + bgColorAuthenticationNumber: "bg-inputBoxFocus", |
| 52 | + shadowAuthenticationNumber: "drop-shadow-inputBoxShadow", |
| 53 | + })); |
| 54 | + if (value.trim() === "") { |
| 55 | + setStyle(() => ({ |
| 56 | + ...style, |
| 57 | + bgColorAuthenticationNumber: "bg-inputBox", |
| 58 | + shadowAuthenticationNumber: "", |
| 59 | + })); |
| 60 | + } |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + const onSendEmail = () => { |
| 65 | + const email = emailRef.current; |
| 66 | + if (email.value.trim() === "") { |
| 67 | + setRegulation(() => "이메일을 입력해주세요"); |
| 68 | + } else { |
| 69 | + setRegulation(() => ""); |
| 70 | + } |
| 71 | + sendEmail({ email: email.value }); |
| 72 | + }; |
| 73 | + |
| 74 | + const sendEmail = async (payload) => { |
| 75 | + try { |
| 76 | + setIsLoding(() => true); |
| 77 | + onModalOpen(); |
| 78 | + const data = await LoginApi.SendEmailAuthenticationNumber(payload); |
| 79 | + setIsLoding(() => false); |
| 80 | + setModalStr({ |
| 81 | + modalTitle: "이메일함을 확인해주세요", |
| 82 | + modalMessage: "인증번호를 입력해주세요", |
| 83 | + }); |
| 84 | + setInputCheck(() => true); |
| 85 | + } catch (error) { |
| 86 | + console.log(error.response); |
| 87 | + const { data } = error.response; |
| 88 | + if (data.status === 400) { |
| 89 | + setIsLoding(() => false); |
| 90 | + setModalStr({ |
| 91 | + modalTitle: data.message, |
| 92 | + modalMessage: "이메일을 확인해주세요.", |
| 93 | + }); |
| 94 | + } |
| 95 | + } |
| 96 | + }; |
| 97 | + |
| 98 | + const onSubmitNextPage = () => { |
| 99 | + const email = emailRef.current; |
| 100 | + const authenticationNumber = authenticationNumberRef.current; |
| 101 | + |
| 102 | + if (email.value.trim() === "") { |
| 103 | + setRegulation(() => "이메일을 입력해주세요"); |
| 104 | + email.focus(); |
| 105 | + return; |
| 106 | + } else if (authenticationNumber.value.trim() === "") { |
| 107 | + setRegulation(() => "인증번호를 입력해주세요"); |
| 108 | + authenticationNumber.focus(); |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + if (InputCheck) { |
| 113 | + onSubmitNextPageAxios({ |
| 114 | + email: email.value, |
| 115 | + code: authenticationNumber.value, |
| 116 | + }); |
| 117 | + } |
| 118 | + }; |
| 119 | + |
| 120 | + const onSubmitNextPageAxios = async (payload) => { |
| 121 | + try { |
| 122 | + setIsLoding(() => true); |
| 123 | + onModalOpen(); |
| 124 | + const data = await LoginApi.SendAuthenticationNumber(payload); |
| 125 | + setIsLoding(() => false); |
| 126 | + console.log(data); |
| 127 | + } catch (error) { |
| 128 | + console.log(error.response); |
| 129 | + const { data } = error.response; |
| 130 | + if (data.status === 400) { |
| 131 | + setIsLoding(() => false); |
| 132 | + setModalStr({ |
| 133 | + modalTitle: "인증번호 실패", |
| 134 | + modalMessage: `인증번호가 잘못 입력되었습니다. \n 인증요청을 재시도 해주세요.`, |
| 135 | + }); |
| 136 | + } |
| 137 | + } |
| 138 | + }; |
| 139 | + |
| 140 | + return ( |
| 141 | + <div className="container "> |
| 142 | + <div className=" grid grid-flow-row ml-[20px] mr-[20px] mt-[55px]"> |
| 143 | + <div className="mb-[4px]"> |
| 144 | + <Label>비밀번호를 분실한 아이디를 입력해주세요</Label> |
| 145 | + </div> |
| 146 | + <div className="w-full"> |
| 147 | + <div className="flex flex-col gap-[12px]"> |
| 148 | + <div className="flex items-center gap-[20px] w-full"> |
| 149 | + <input |
| 150 | + id="email" |
| 151 | + type={"email"} |
| 152 | + ref={emailRef} |
| 153 | + onChange={onInputColor} |
| 154 | + autoComplete="off" |
| 155 | + placeholder="아이디(이메일) 입니다." |
| 156 | + className={`w-[234px] px-3 h-[50px] ${style.bgColorEmail} ${style.shadowEmail} placeholder-inputPlaceHoldText`} |
| 157 | + /> |
| 158 | + <div |
| 159 | + onClick={onSendEmail} |
| 160 | + className=" bg-[#FFFFFF] flex items-center h-[50px] p-[5px] border-solid border-2 text-[16px] font-[600] border-[#002C51] rounded-[4px] leading-[28px] cursor-pointer" |
| 161 | + > |
| 162 | + 인증 요청 |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + <div className="flex items-center h-[20px]"> |
| 166 | + <p className=" w-full font-[500] text-[16px] text-[#DE0D0D] flex items-center"> |
| 167 | + {regulation} |
| 168 | + </p> |
| 169 | + </div> |
| 170 | + <div className="h-[full]"> |
| 171 | + <LoginSignupInputBox |
| 172 | + id="AuthenticationNumber" |
| 173 | + type="text" |
| 174 | + placeholder="인증번호 입력" |
| 175 | + onChange={onInputColor} |
| 176 | + bgColor={style.bgColorAuthenticationNumber} |
| 177 | + shadow={style.shadowAuthenticationNumber} |
| 178 | + ref={authenticationNumberRef} |
| 179 | + /> |
| 180 | + </div> |
| 181 | + </div> |
| 182 | + <div> |
| 183 | + <button |
| 184 | + className="mt-[65px] w-full bg-[#002C51] h-[40px] rounded-[4px] font-[600] text-[#fff]" |
| 185 | + onClick={onSubmitNextPage} |
| 186 | + > |
| 187 | + 확인 |
| 188 | + </button> |
| 189 | + </div> |
| 190 | + </div> |
| 191 | + <IsModal |
| 192 | + isModalOpen={isOpen.isOpen} |
| 193 | + onMoalClose={onMoalClose} |
| 194 | + message={{ ModalStr }} |
| 195 | + isLoding={isLoding} |
| 196 | + /> |
| 197 | + </div> |
| 198 | + </div> |
| 199 | + ); |
| 200 | +}; |
| 201 | + |
| 202 | +export default InputEmail; |
0 commit comments