-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 프로필 등록 페이지 구현 #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9ae3696
feat: 프로필 등록 페이지 구현
almighty55555 1463663
Merge branch 'dev' of https://github.com/CodeitPart3/thejulge into PR…
almighty55555 963e5b2
feat: 프로필 등록 페이지 구현 완료
almighty55555 f82329f
Merge branch 'dev' of https://github.com/CodeitPart3/thejulge into PR…
almighty55555 5814b09
refactor: 핸드폰 번호 로직과 프로필 등록 코드 개선
almighty55555 b4a9701
refactor: 코드 가독성 개선
almighty55555 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,150 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| import { useNavigate } from "react-router-dom"; | ||
|
|
||
| import { SeoulDistrict, SeoulDistricts } from "../types"; | ||
|
|
||
| import { putUser } from "@/apis/services/userService"; | ||
| import { Close } from "@/assets/icon"; | ||
| import Button from "@/components/Button"; | ||
| import Select from "@/components/Select"; | ||
| import TextField from "@/components/TextField"; | ||
| import { ROUTES } from "@/constants/router"; | ||
| import { useUserStore } from "@/hooks/useUserStore"; | ||
| import { autoHyphenFormatter } from "@/utils/phoneNumber"; | ||
|
|
||
| type FormType = { | ||
| name: string; | ||
| phone: string; | ||
| address: SeoulDistrict | undefined; | ||
| bio: string; | ||
| }; | ||
|
|
||
| const FIELD_LABELS: Record<keyof FormType, string> = { | ||
| name: "이름", | ||
| phone: "연락처", | ||
| address: "선호 지역", | ||
| bio: "소개", | ||
| }; | ||
|
|
||
| export default function ProfileRegisterPage() { | ||
| return <div>ProfileRegisterPage</div>; | ||
| const navigate = useNavigate(); | ||
| const { user } = useUserStore(); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
|
|
||
| const [form, setForm] = useState<FormType>({ | ||
| name: "", | ||
| phone: "", | ||
| address: undefined, | ||
| bio: "", | ||
| }); | ||
|
|
||
| const handleChange = (key: keyof FormType, value: string | SeoulDistrict) => { | ||
| setForm((prev) => ({ ...prev, [key]: value })); | ||
| }; | ||
|
|
||
| const handleSubmit = async () => { | ||
| if (!user?.id) { | ||
| alert("로그인 정보가 없습니다."); | ||
| return; | ||
| } | ||
|
|
||
| if (isSubmitting) return; | ||
|
|
||
| const requiredFields: Array<keyof FormType> = ["name", "phone"]; | ||
|
|
||
| const missingField = requiredFields.find((key) => { | ||
| const value = form[key]; | ||
| return typeof value === "string" && value.trim() === ""; | ||
| }); | ||
|
|
||
| if (missingField) { | ||
| alert(`${FIELD_LABELS[missingField]}을(를) 입력해 주세요.`); | ||
| return; | ||
| } | ||
|
|
||
| setIsSubmitting(true); | ||
| const payload = { | ||
| name: form.name.trim(), | ||
| phone: form.phone, | ||
| address: form.address, | ||
| bio: form.bio.trim(), | ||
| }; | ||
|
|
||
| try { | ||
| await putUser(user.id, payload); | ||
| navigate(ROUTES.PROFILE.ROOT); | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <form | ||
| className="w-full max-w-[964px] mx-auto px-4 py-12" | ||
| onSubmit={(e) => { | ||
| e.preventDefault(); | ||
| handleSubmit(); | ||
| }} | ||
| > | ||
| <div className="flex justify-between items-center mb-8"> | ||
| <h2 className="sm:text-[1.75rem] text-[1.25rem] font-bold"> | ||
| 내 프로필 | ||
| </h2> | ||
| <button onClick={() => navigate("/profile")}> | ||
| <Close className="sm:w-8 sm:h-8 w-6 h-6 cursor-pointer" /> | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className="grid md:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 mb-6"> | ||
| <TextField.Input | ||
| label="이름*" | ||
| placeholder="입력" | ||
| fullWidth | ||
| value={form.name} | ||
| onChange={(e) => handleChange("name", e.target.value)} | ||
| maxLength={20} | ||
| /> | ||
| <TextField.Input | ||
| label="연락처*" | ||
| placeholder="입력" | ||
| fullWidth | ||
| value={form.phone} | ||
| onChange={(e) => { | ||
| const formatted = autoHyphenFormatter(e.target.value); | ||
| handleChange("phone", formatted); | ||
| }} | ||
| /> | ||
| <Select | ||
| label="선호 지역" | ||
| placeholder="선택" | ||
| fullWidth | ||
| options={SeoulDistricts.map((d) => ({ label: d, value: d }))} | ||
| value={form.address} | ||
| onValueChange={(value) => handleChange("address", value)} | ||
| /> | ||
| </div> | ||
| <div className="mb-10"> | ||
| <TextField.TextArea | ||
| label="소개" | ||
| placeholder="입력" | ||
| fullWidth | ||
| rows={4} | ||
| value={form.bio} | ||
| onChange={(e) => handleChange("bio", e.target.value)} | ||
| /> | ||
| </div> | ||
| <div className="text-center"> | ||
| <Button | ||
| variant="primary" | ||
| textSize="md" | ||
| className="sm:w-[350px] w-full px-34 py-3.5" | ||
| disabled={isSubmitting} | ||
| type="submit" | ||
| > | ||
| 등록하기 | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const autoHyphenFormatter = (value: string): string => { | ||
| return value | ||
| .replace(/[^0-9]/g, "") | ||
| .replace(/^(\d{2,3})(\d{3,4})(\d{4})$/, `$1-$2-$3`); | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.