Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/signup kkm #69

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions components/signup/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LocalStorage from "../../core/localStorage";
import { IcSignupChecking } from "../../public/assets/icons";
import { UseFormDataType } from "../../types/signup";
import { errorPatterns } from "../../util/check";
import referralLinkLIst from "../../util/referralLinkList";
import { AlertLabel } from "../common";
import { DefaultButton } from "../common/styled/Button";
import { Input } from "../common/styled/Input";
Expand All @@ -25,6 +26,8 @@ interface SignupFormProps {
export default function SignupForm(props: SignupFormProps) {
const { register, errors, keyData, keyIndex, isAgree, isDirty, onToggleIsAgreeCondition } = props;

const linkOfCondition = referralLinkLIst[0].href;

const PasswordForm = (
<>
<StEmailFixed>{LocalStorage.getItem("booktez-email")}</StEmailFixed>
Expand All @@ -36,9 +39,11 @@ export default function SignupForm(props: SignupFormProps) {
);

const AgreeConditionBox = (
<StAgreeConditionBox htmlFor="signupAgree" onClick={onToggleIsAgreeCondition}>
<StIcSignupChecking isagree={isAgree} />
<p>κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 이용 약관에 λ™μ˜ν•©λ‹ˆλ‹€.</p>
<StAgreeConditionBox htmlFor="signupAgree">
<StIcSignupChecking isagree={isAgree} onClick={onToggleIsAgreeCondition} />
<a href={linkOfCondition} target="_blank" rel="noopener noreferrer">
κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 이용 약관에 λ™μ˜ν•©λ‹ˆλ‹€.
</a>
</StAgreeConditionBox>
);

Expand All @@ -51,10 +56,8 @@ export default function SignupForm(props: SignupFormProps) {
<Input {...register(keyIndex, errorPatterns[keyIndex])} placeholder={`${keyData[keyIndex]}을 μž…λ ₯ν•΄ μ£Όμ„Έμš”`} />
)}
{errors[keyIndex]?.message && <AlertLabel message={errors[keyIndex].message} />}

{keyIndex === "email" && AgreeConditionBox}

<StNextStepBtn disabled={!isDirty} type="submit">
<StNextStepBtn disabled={!isDirty || !isAgree} type="submit">
λ‹€μŒ 계단
</StNextStepBtn>
</>
Expand Down Expand Up @@ -87,6 +90,10 @@ const StAgreeConditionBox = styled.label`

margin: 1.7rem 0 0 0;

& > a {
text-decoration: underline;
}
Comment on lines +93 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ œκ°€ ν”Όκ·Έλ§ˆλ₯Ό ν™•μΈν•˜μ§€λŠ” λͺ»ν–ˆλŠ”데, ν˜Ήμ‹œ 이 ν‘œμ‹œκ°€ κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 이용 약관에 λ™μ˜ν•©λ‹ˆλ‹€. 전체가 μ•„λ‹Œ κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 이용 μ•½κ΄€μ—λ§Œ ν•΄λ‹Ήλ˜λŠ” 것은 μ•„λ‹Œκ°€μš₯?


${({ theme }) => theme.fonts.body6}
`;

Expand Down
81 changes: 49 additions & 32 deletions pages/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import styled from "@emotion/styled";
import { AnimatePresence, motion } from "framer-motion";
import { useRouter } from "next/router";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";

import { NavHeader } from "../../components/common";
Expand Down Expand Up @@ -78,13 +78,13 @@ export default function Signup() {
};

// λ‹€μŒ λ‹¨κ³„λ‘œ μ΄λ™ν•˜λŠ” ν•¨μˆ˜
const setNextStep = (key: string) => {
const setNextStep = (inputValue: string) => {
setUserData((current) => {
const formData = { ...current };
const userData = { ...current };

formData[formDataKeyIndex] = key;
userData[formDataKeyIndex] = inputValue;

return formData;
return userData;
});

setFormDataKeyIndex((current) => {
Expand All @@ -97,48 +97,59 @@ export default function Signup() {
return "submit";
});

setValue(formDataKeyIndex, "");
setValue(formDataKeyIndex, "", { shouldDirty: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ‘

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ‘πŸ‘πŸ‘

};

// 폼 제좜 μ—λŸ¬κ°€ μ—†λŠ”μ§€ 확인
const submitForm = async (loginFormData: UseFormDataType) => {
const key = loginFormData[formDataKeyIndex];
const inputValue = loginFormData[formDataKeyIndex];

// λΉ„λ°€λ²ˆν˜Έ μž…λ ₯κΉŒμ§€ 마치면 μžλ™ 둜그인
if (formDataKeyIndex === "password") {
if (loginFormData["password"] === loginFormData["password2"]) {
autoLoginAfterSignup(key);
} else {
setError("password", { type: "server", message: "λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€." });
autoLoginAfterSignup(inputValue);

return;
}
} else {
// 이메일 μž…λ ₯μ‹œ κ°œμΈμ •λ³΄ μ·¨κΈ‰ λ°©μΉ¨ λ™μ˜λ₯Ό λ¨Όμ € μœ λ„
if (formDataKeyIndex === "email" && !isAgreeCondition) {
setError(formDataKeyIndex, {
type: "agreeCondition",
message: "κ°œμΈμ •λ³΄ μˆ˜μ§‘ 및 이용 약관에 λ™μ˜ν•΄μ£Όμ‹œκΈ° λ°”λžλ‹ˆλ‹€.",
});
} else {
// μ„œλ²„λ‘œ 데이터λ₯Ό λ³΄λ‚΄μ„œ μœ νš¨μ„± 검사
// return: μœ νš¨ν•œμ§€(isValid) && μ—λŸ¬ λ©”μ‹œμ§€(message)
const { isValid, message } = await checkIsValid(formDataKeyIndex, key);

if (isValid) {
setNextStep(key);
if (formDataKeyIndex === "email") {
LocalStorage.setItem("booktez-email", loginFormData["email"]);
}
} else {
setError(formDataKeyIndex, { type: "server", message });
}
setError("password", { type: "server", message: "λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€." });

return;
}

// μ„œλ²„λ‘œ 데이터λ₯Ό λ³΄λ‚΄μ„œ μœ νš¨μ„± 검사
// return: μœ νš¨ν•œμ§€(isValid) && μ—λŸ¬ λ©”μ‹œμ§€(message)
const { isValid, message } = await checkIsValid(formDataKeyIndex, inputValue);

if (isValid) {
setNextStep(inputValue);

if (formDataKeyIndex === "email") {
LocalStorage.setItem("booktez-email", loginFormData["email"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ‘œμ»¬μŠ€ν† λ¦¬μ§€ ν‚€λ₯Ό μƒμˆ˜λ‚˜ νƒ€μž…μœΌλ‘œ μ •μ˜ν•΄λ‘λ©΄ (λ‚˜μ€‘μ— μ½”λ“œλ₯Ό κ³ μΉ  λˆ„κ΅°κ°€κ°€ νŽΈν•΄μ§ˆ 것 κ°™μ•„μ„œ)쒋을 것 κ°™λ‹€λŠ” 생각이 λ“œλŠ”λ°, ν•„μˆ˜λŠ” μ•„λ‹™λ‹ˆλ‹Ή(근데 ν•΄μ£Όλ©΄ 쒋을 것 같은 λŠλ‚Œμ •λ„)

}

return;
}
setError(formDataKeyIndex, { type: "server", message });
Comment on lines +123 to +132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μš”ν˜Έ μ΄λ ‡κ²Œ λ˜μ—ˆκ΅°μš”!!
이것도 μ’‹μ§€λ§Œ, μœ„μ—μ„œ 말 ν•œ κ²ƒμ²˜λŸΌ μ—λŸ¬ 체킹을 μœ„λ‘œ 올리면, if 의 λŽμŠ€κ°€ κΉŠμ–΄μ§€μ§€ μ•Šμ„ 수 μžˆμ„ 것 κ°™μ•„μš”

};

const handleToggleIsAgreeCondition = () => {
setIsAgreeCondition(!isAgreeCondition);
};

useEffect(() => {
if (formDataKeyIndex == "nickname" || formDataKeyIndex == "password") {
const prevFormDataKeyIndex = formDataKeyIndex == "password" ? "nickname" : "email";

history.pushState(null, "", "");
window.onpopstate = () => {
setFormDataKeyIndex(prevFormDataKeyIndex);
};
} else {
window.onpopstate = () => {
// μ΄ˆκΈ°ν™”
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switchλ¬Έ μ‚¬μš©ν•˜λŠ” 게 μ’€ 더 μ•Œμ•„λ³΄κΈ° μ‰¬μš°λ €λ‚˜ μ‹Άλ„€μš”!

Copy link
Member

@joohaem joohaem Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ꢌμž₯) if-else에, μ‚Όν•­μ—°μ‚°κΉŒμ§€ μžˆμœΌλ‹ˆ μ–΄λ–€ μ½”λ“œμΈμ§€ λͺ…ν™•νžˆ μ•ˆ μ™€λ‹ΏλŠ” 것 κ°™μ•„μš”
formDataKeyIndex κ°’μœΌλ‘œ switch λ¬Έ ν™œμš©ν•˜λ©΄ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹·

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ—¬κΈ°μ„œλŠ” μ§„μ§œ 별거 μ•„λ‹Œλ°, === κ°€ μ•„λ‹Œ == 인 μ΄μœ κ°€ μžˆλ‚˜μš€?

}, [setFormDataKeyIndex]);

return (
<>
<NavHeader logoColor={theme.colors.gray100} />
Expand All @@ -155,7 +166,13 @@ export default function Signup() {
<StFormWrapper>
<StSignupImage src={imgList[formDataKeyIndex]} alt="νšŒμ›κ°€μž… 첫 단계" />
<StSignupHeading2>λ‚˜λ§Œμ˜ μ„œμž¬λ₯Ό λ§Œλ“œλŠ” μ€‘μ΄μ—μš”!</StSignupHeading2>
<StSignupParagraph>λ‹Ήμ‹ μ˜ {formDataKeyData[formDataKeyIndex]}을 μž…λ ₯ν•΄ μ£Όμ„Έμš”.</StSignupParagraph>

{formDataKeyData[formDataKeyIndex] == "λ‹‰λ„€μž„" ? (
<StSignupParagraph>μ œκ°€ μ—¬λŸ¬λΆ„μ„ μ–΄λ–»κ²Œ λΆ€λ₯΄λ©΄ λ κΉŒμš”?</StSignupParagraph>
) : (
<StSignupParagraph>λ‹Ήμ‹ μ˜ {formDataKeyData[formDataKeyIndex]}을 μž…λ ₯ν•΄ μ£Όμ„Έμš”.</StSignupParagraph>
)}

<StForm onSubmit={handleSubmit(submitForm)}>
<SignupForm
register={register}
Expand Down
6 changes: 6 additions & 0 deletions util/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const EMAIL_REGEX =
/^(([^<>()\].,;:\s@"]+(\.[^<>()\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;

const NICKNAME_REGEX = /^(?=.*[a-z0-9κ°€-힣])[a-z0-9κ°€-힣]{2,10}$/i;

Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘πŸ‘

const INVALID_PWD_CHAR_LIST: { [key: string]: string } = {
",": "반점(,)",
'"': 'μŒλ”°μ˜΄ν‘œ(")',
Expand Down Expand Up @@ -34,6 +36,10 @@ const nicknameErrorPatterns: ErrorCondition = {
value: true,
message: "λ‹‰λ„€μž„μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”.",
},
pattern: {
value: NICKNAME_REGEX,
message: "2-10자 μ΄λ‚΄μ˜ 영문/ν•œκΈ€/숫자둜 μž…λ ₯ν•΄μ£Όμ„Έμš”.",
},
};

export const passwordErrorPatterns: ErrorCondition = {
Expand Down