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

[최건] Sprint10 #656

Open
wants to merge 5 commits into
base: Next.js-최건
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Empty file removed app/(auth)/_widgets/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions app/(auth)/signin/page.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"id": "이메일", "type": "email", "pattern": "[^@\\s]+@[^@\\s]+\\.[^@\\s]+", "required": true, "placeholder": "이메일을 입력해주세요", "autocomplete": "email"
"id": "email", "label": "이메일", "type": "email", "pattern": "[^@\\s]+@[^@\\s]+\\.[^@\\s]+", "required": true, "placeholder": "이메일을 입력해주세요", "autocomplete": "email"
},
{
"id": "비밀번호", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 입력해주세요", "autocomplete": "password"
"id": "password", "label": "비밀번호", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 입력해주세요", "autocomplete": "password"
}
]
40 changes: 26 additions & 14 deletions app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import API from "@/app/_api";

import json from "./page.json";

import Link from "next/link";
Expand All @@ -9,15 +11,27 @@ import useForm, { Cause, Trigger } from "@/app/_hooks/useForm";

export default function Page()
{
const { errors, verify, disabled } = useForm("signin",
// onSubmit
(data) =>
const signin = useForm("signin", [Trigger.BLUR, Trigger.CHANGE], (data) =>
{
console.log(data);
},
// onCheck
(input, values, causes) =>
API["auth/signIn"].POST(
{
email: data.get("이메일") as string,
password: data.get("비밀번호") as string,
})
.then((response) =>
{
document.cookie = response.accessToken;
})
.catch((error) =>
{
console.error(error);
});
});

signin.verify(({ input, trigger }) =>
{
const causes = signin.causes(input);

if (causes.has(Cause.REQUIRED))
{
return `${input.name}을(를) 입력해주세요`;
Expand All @@ -35,9 +49,7 @@ export default function Page()
return `${input.name}을(를) ${input.maxLength}자 이하 입력해주세요`;
}
return null;
},
// triggers
[Trigger.BLUR, Trigger.INPUT]);
});

return (
<>
Expand All @@ -49,11 +61,11 @@ export default function Page()
<div key={index} class="group flex flex-col mobile:gap-[8px] tablet:gap-[8px] desktop:gap-[16px]">
<label for={args.id} class="text-[#1F2937] font-[700] mobile:text-[14px] tablet:text-[18px] desktop:text-[18px]">
{
args.id
args.label
}
</label>
<div class="flex h-[56px] px-[24px] bg-[#F3F4F6] rounded-[12px] border group-has-[:valid]:border-[#3692FF] group-has-[.error]:border-[#F74747]">
<input { ...args } name={args.id} class="grow text-[#1F2937] text-[16px] font-[400] outline-none bg-transparent placeholder:text-[#9CA3AF]"/>
<input { ...args } name={args.label} class="grow text-[#1F2937] text-[16px] font-[400] outline-none bg-transparent placeholder:text-[#9CA3AF]"/>
{
args.type === "password" && <Image src="/icons/invisible.svg" alt="visibility" width={24} height={24} onClick={(event) =>
{
Expand All @@ -78,12 +90,12 @@ export default function Page()
}
</div>
{
errors[args.id] && <div class="error text-[#F74747] text-[15px] font-[600] group-[:not(:has(:invalid))]:hidden">{errors[args.id]}</div>
signin.errors[args.label] && <div class="error text-[#F74747] text-[15px] font-[600] group-[:not(:has(:invalid))]:hidden">{signin.errors[args.label]}</div>
}
</div>
))}
</div>
<button type="submit" disabled={disabled} class="button h-[56px] rounded-[40px] text-[16px] font-[600] mobile:mt-[16px] tablet:mt-[24px] desktop:mt-[24px]">
<button type="submit" disabled={signin.disabled} class="button h-[56px] rounded-[40px] text-[16px] font-[600] mobile:mt-[16px] tablet:mt-[24px] desktop:mt-[24px]">
로그인
</button>
</form>
Expand Down
8 changes: 4 additions & 4 deletions app/(auth)/signup/page.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"id": "이메일"," type": "email", "pattern": "[^@\\s]+@[^@\\s]+\\.[^@\\s]+", "required": true, "placeholder": "이메일을 입력해주세요", "autocomplete": "email"
"id": "email", "label": "이메일", "type": "email", "pattern": "[^@\\s]+@[^@\\s]+\\.[^@\\s]+", "required": true, "placeholder": "이메일을 입력해주세요", "autocomplete": "email"
},
{
"id": "닉네임", "type": "text", "minlength": 2, "maxlength": 8, "pattern": "^[a-zA-Z][a-zA-Z0-9_]*$", "required": true, "placeholder": "닉네임을 입력해주세요"
"id": "nickname", "label": "닉네임", "type": "text", "minlength": 2, "maxlength": 8, "pattern": "^[a-zA-Z][a-zA-Z0-9_]*$", "required": true, "placeholder": "닉네임을 입력해주세요"
},
{
"id": "비밀번호", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 입력해주세요", "autocomplete": "new-password"
"id": "password", "label": "비밀번호", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 입력해주세요", "autocomplete": "new-password"
},
{
"id": "비밀번호 확인", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 다시 한번 입력해주세요", "autocomplete": "new-password"
"id": "passwordConfirmation", "label": "비밀번호 확인", "type": "password", "minlength": 8, "maxlength": 16, "required": true, "placeholder": "비밀번호를 다시 한번 입력해주세요", "autocomplete": "new-password"
}
]
85 changes: 39 additions & 46 deletions app/(auth)/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import API from "@/app/_api";

import json from "./page.json";

import Link from "next/link";
Expand All @@ -9,60 +11,53 @@ import useForm, { Cause, Trigger } from "@/app/_hooks/useForm";

export default function Page()
{
const { errors, verify, disabled } = useForm("signup",
// onSubmit
(data) =>
const signup = useForm("signup", [Trigger.BLUR, Trigger.CHANGE], (data) =>
{
console.log(data);
},
// onCheck
(input, values, causes) =>
API["auth/signUp"].POST(
{
email: data.get("이메일") as string,
nickname: data.get("닉네임") as string,
password: data.get("비밀번호") as string,
passwordConfirmation: data.get("비밀번호 확인") as string,
})
.then((response) =>
{
document.cookie = response.accessToken;
})
.catch((error) =>
{
console.error(error);
});
});

signup.effect(({ input, trigger }) =>
{
switch (input.name)
{
case "비밀번호":
{
if (values["비밀번호 확인"])
if (signup.values["비밀번호 확인"])
{
//
// anti-pattern
//
if (causes.has(Cause.REQUIRED))
{
errors[input.name] = `${input.name}을(를) 입력해주세요`;
}
else if (causes.has(Cause.PATTERN))
{
errors[input.name] = `올바른 ${input.name}을(를) 입력해주세요`;
}
else if (causes.has(Cause.MINLENGTH))
{
errors[input.name] = `${input.name}을(를) ${input.minLength}자 이상 입력해주세요`;
}
else if (causes.has(Cause.MAXLENGTH))
{
errors[input.name] = `${input.name}을(를) ${input.maxLength}자 이하 입력해주세요`;
}
else
{
errors[input.name] = null;
}
//
// sync
//
verify("비밀번호 확인");

return errors[input.name] ? errors[input.name] : null;
signup.notify("비밀번호 확인");
}
break;
}
}
});

signup.verify(({ input, trigger }) =>
{
const causes = signup.causes(input);

switch (input.name)
{
case "비밀번호 확인":
{
if (errors["비밀번호"])
if (signup.errors["비밀번호"])
{
return "비밀번호를 확인해주세요";
}
if (values["비밀번호"] !== values["비밀번호 확인"])
if (signup.values["비밀번호"] !== signup.values["비밀번호 확인"])
{
return "비밀번호가 일치하지 않습니다";
}
Expand All @@ -86,9 +81,7 @@ export default function Page()
return `${input.name}을(를) ${input.maxLength}자 이하 입력해주세요`;
}
return null;
},
// triggers
[Trigger.BLUR, Trigger.INPUT]);
});

return (
<>
Expand All @@ -100,11 +93,11 @@ export default function Page()
<div key={index} class="group flex flex-col mobile:gap-[8px] tablet:gap-[8px] desktop:gap-[16px]">
<label for={args.id} class="text-[#1F2937] font-[700] mobile:text-[14px] tablet:text-[18px] desktop:text-[18px]">
{
args.id
args.label
}
</label>
<div class="flex h-[56px] px-[24px] bg-[#F3F4F6] rounded-[12px] border group-has-[:valid]:border-[#3692FF] group-has-[.error]:border-[#F74747]">
<input { ...args } name={args.id} class="grow text-[#1F2937] text-[16px] font-[400] outline-none bg-transparent placeholder:text-[#9CA3AF]"/>
<input { ...args } name={args.label} class="grow text-[#1F2937] text-[16px] font-[400] outline-none bg-transparent placeholder:text-[#9CA3AF]"/>
{
args.type === "password" && <Image src="/icons/invisible.svg" alt="visibility" width={24} height={24} onClick={(event) =>
{
Expand All @@ -129,12 +122,12 @@ export default function Page()
}
</div>
{
errors[args.id] && <div class="error text-[#F74747] text-[15px] font-[600] group-[:not(:has(:invalid))]:hidden">{errors[args.id]}</div>
signup.errors[args.label] && <div class="error text-[#F74747] text-[15px] font-[600] group-[:not(:has(:invalid))]:hidden">{signup.errors[args.label]}</div>
}
</div>
))}
</div>
<button type="submit" disabled={disabled} class="button h-[56px] rounded-[40px] text-[16px] font-[600] mobile:mt-[16px] tablet:mt-[24px] desktop:mt-[24px]">
<button type="submit" disabled={signup.disabled} class="button h-[56px] rounded-[40px] text-[16px] font-[600] mobile:mt-[16px] tablet:mt-[24px] desktop:mt-[24px]">
회원가입
</button>
</form>
Expand Down
Loading