From bbee01536c20f9c7a97711f9dfc25770fa093d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EC=88=98=EB=B9=88=20Subin=20OH?= Date: Wed, 7 May 2025 22:42:35 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D/=ED=8E=B8=EC=A7=91=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=B0=B0=EA=B2=BD=EC=83=89=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TextField.tsx | 4 +- src/pages/ProfileEditPage.tsx | 136 +++++++++++++++--------------- src/pages/ProfileRegisterPage.tsx | 136 +++++++++++++++--------------- 3 files changed, 140 insertions(+), 136 deletions(-) diff --git a/src/components/TextField.tsx b/src/components/TextField.tsx index 6006269..dc67479 100644 --- a/src/components/TextField.tsx +++ b/src/components/TextField.tsx @@ -82,7 +82,7 @@ const Input = forwardRef( ref: Ref, ) => { const wrapperClassNames = cn( - "flex w-fit gap-1.5 border rounded-[0.375rem] border-gray-30 focus-within:border-blue-20 placeholder:text-gray-40 ", + "flex w-fit gap-1.5 border rounded-[0.375rem] border-gray-30 focus-within:border-blue-20 placeholder:text-gray-40 bg-white", { "w-full": fullWidth, "bg-gray-20 text-gray-40": disabled, @@ -136,7 +136,7 @@ const TextArea = forwardRef( ref: Ref, ) => { const wrapperClassNames = cn( - "flex w-fit gap-1.5 border rounded-[0.375rem] border-gray-30 focus-within:border-blue-20 placeholder:text-gray-40 ", + "flex w-fit gap-1.5 border rounded-[0.375rem] border-gray-30 focus-within:border-blue-20 placeholder:text-gray-40 bg-white", { "w-full": fullWidth, "bg-gray-20 text-gray-40": disabled, diff --git a/src/pages/ProfileEditPage.tsx b/src/pages/ProfileEditPage.tsx index cf250c8..86de889 100644 --- a/src/pages/ProfileEditPage.tsx +++ b/src/pages/ProfileEditPage.tsx @@ -120,72 +120,74 @@ export default function ProfileEditPage() { }; return ( -
{ - e.preventDefault(); - handleSubmit(); - }} - > -
-

- 내 프로필 -

- -
- -
- handleChange("name", e.target.value)} - maxLength={20} - /> - { - const formatted = autoHyphenFormatter(e.target.value); - handleChange("phone", formatted); - }} - /> - ({ label: d, value: d }))} + value={form.address} + onValueChange={(value) => handleChange("address", value)} + /> +
+
+ handleChange("bio", e.target.value)} + /> +
+
+ +
+
+ ); } diff --git a/src/pages/ProfileRegisterPage.tsx b/src/pages/ProfileRegisterPage.tsx index bf5d91c..8f49ba2 100644 --- a/src/pages/ProfileRegisterPage.tsx +++ b/src/pages/ProfileRegisterPage.tsx @@ -105,72 +105,74 @@ export default function ProfileRegisterPage() { }; return ( -
{ - e.preventDefault(); - handleSubmit(); - }} - > -
-

- 내 프로필 -

- -
- -
- handleChange("name", e.target.value)} - maxLength={20} - /> - { - const formatted = autoHyphenFormatter(e.target.value); - handleChange("phone", formatted); - }} - /> - ({ label: d, value: d }))} + value={form.address} + onValueChange={(value) => handleChange("address", value)} + /> +
+
+ handleChange("bio", e.target.value)} + /> +
+
+ +
+
+ ); } From 113628b938edd4f92a342f7526c83ddf5b677104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EC=88=98=EB=B9=88=20Subin=20OH?= Date: Wed, 7 May 2025 22:58:00 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D/=ED=8E=B8=EC=A7=91=20=EC=9B=B9=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=A7=80=20=EC=A0=84=EC=97=AD=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useUserStore.tsx | 9 +++++++++ src/pages/ProfileEditPage.tsx | 3 ++- src/pages/ProfileRegisterPage.tsx | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hooks/useUserStore.tsx b/src/hooks/useUserStore.tsx index 3e976cc..a7ae2ce 100644 --- a/src/hooks/useUserStore.tsx +++ b/src/hooks/useUserStore.tsx @@ -16,6 +16,7 @@ interface UserState { user: User | null; token: string | null; isLoggedIn: boolean; + updateUser: (partial: Partial) => void; setUserAndToken: (user: User, token: string) => void; updateShopId: (shopId: string) => void; clearUser: () => void; @@ -28,6 +29,14 @@ export const useUserStore = create()( token: null, isLoggedIn: false, + updateUser: (partial) => { + const current = get(); + if (!current.user) return; + set({ + user: { ...current.user, ...partial }, + }); + }, + setUserAndToken: (user, token) => set({ user, diff --git a/src/pages/ProfileEditPage.tsx b/src/pages/ProfileEditPage.tsx index 86de889..374fc03 100644 --- a/src/pages/ProfileEditPage.tsx +++ b/src/pages/ProfileEditPage.tsx @@ -31,7 +31,7 @@ const FIELD_LABELS: Record = { export default function ProfileEditPage() { const navigate = useNavigate(); - const { user } = useUserStore(); + const { user, updateUser } = useUserStore(); const [isSubmitting, setIsSubmitting] = useState(false); const openModal = useModalStore((state) => state.openModal); @@ -99,6 +99,7 @@ export default function ProfileEditPage() { try { await putUser(user.id, payload); + updateUser(payload); openModal({ type: "message", iconType: "none", diff --git a/src/pages/ProfileRegisterPage.tsx b/src/pages/ProfileRegisterPage.tsx index 8f49ba2..e96fe8d 100644 --- a/src/pages/ProfileRegisterPage.tsx +++ b/src/pages/ProfileRegisterPage.tsx @@ -31,7 +31,7 @@ const FIELD_LABELS: Record = { export default function ProfileRegisterPage() { const navigate = useNavigate(); - const { user } = useUserStore(); + const { user, updateUser } = useUserStore(); const [isSubmitting, setIsSubmitting] = useState(false); const openModal = useModalStore((state) => state.openModal); @@ -84,6 +84,7 @@ export default function ProfileRegisterPage() { try { await putUser(user.id, payload); + updateUser(payload); openModal({ type: "message", iconType: "none", From 97ca6089f8f20b64e84e62d178b0868f017be746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EC=88=98=EB=B9=88=20Subin=20OH?= Date: Wed, 7 May 2025 23:32:15 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D/=ED=8E=B8=EC=A7=91=20=EB=A6=AC=EB=8B=A4?= =?UTF-8?q?=EC=9D=B4=EB=A0=89=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/ProfileEditPage.tsx | 42 ++++++++++++++++++++++--------- src/pages/ProfileRegisterPage.tsx | 32 +++++++++++++++++------ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/pages/ProfileEditPage.tsx b/src/pages/ProfileEditPage.tsx index 374fc03..effc260 100644 --- a/src/pages/ProfileEditPage.tsx +++ b/src/pages/ProfileEditPage.tsx @@ -43,9 +43,35 @@ export default function ProfileEditPage() { }); useEffect(() => { - async function fetchUser() { + if (!user) { + openModal({ + type: "alert", + iconType: "warning", + message: "로그인 후에 이용 가능한 기능입니다.", + onClose: () => navigate(ROUTES.AUTH.SIGNIN), + }); + return; + } + if (user.type === "employer") { + openModal({ + type: "alert", + iconType: "warning", + message: "알바생 계정으로만 이용 가능한 기능입니다.", + onClose: () => navigate(ROUTES.SHOP.ROOT), + }); + return; + } + }, []); + + useEffect(() => { + const fetchUser = async () => { if (!user?.id) return; const res = await getUser(user.id); + + if (!res.data.item?.name) { + navigate(ROUTES.PROFILE.REGISTER); + return; + } const { name, phone, address, bio } = res.data.item; setForm({ name: name ?? "", @@ -53,24 +79,16 @@ export default function ProfileEditPage() { address, bio: bio ?? "", }); - } + }; fetchUser(); - }, [user?.id]); + }, [user?.id, navigate]); const handleChange = (key: keyof FormType, value: string | SeoulDistrict) => { setForm((prev) => ({ ...prev, [key]: value })); }; const handleSubmit = async () => { - if (!user?.id) { - openModal({ - type: "alert", - iconType: "warning", - message: "로그인 정보가 없습니다.", - }); - return; - } - + if (!user?.id) return; if (isSubmitting) return; const requiredFields: Array = ["name", "phone", "address"]; diff --git a/src/pages/ProfileRegisterPage.tsx b/src/pages/ProfileRegisterPage.tsx index e96fe8d..584542c 100644 --- a/src/pages/ProfileRegisterPage.tsx +++ b/src/pages/ProfileRegisterPage.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import type { AxiosError } from "axios"; import { useNavigate } from "react-router-dom"; @@ -42,20 +42,36 @@ export default function ProfileRegisterPage() { bio: "", }); - const handleChange = (key: keyof FormType, value: string | SeoulDistrict) => { - setForm((prev) => ({ ...prev, [key]: value })); - }; - - const handleSubmit = async () => { - if (!user?.id) { + useEffect(() => { + if (!user) { openModal({ type: "alert", iconType: "warning", - message: "로그인 정보가 없습니다.", + message: "로그인 후에 이용 가능한 기능입니다.", + onClose: () => navigate(ROUTES.AUTH.SIGNIN), }); return; } + if (user.type === "employer") { + openModal({ + type: "alert", + iconType: "warning", + message: "알바생 계정으로만 이용 가능한 기능입니다.", + onClose: () => navigate(ROUTES.SHOP.ROOT), + }); + return; + } + if (user.name) { + navigate(ROUTES.PROFILE.EDIT); + } + }, []); + + const handleChange = (key: keyof FormType, value: string | SeoulDistrict) => { + setForm((prev) => ({ ...prev, [key]: value })); + }; + const handleSubmit = async () => { + if (!user?.id) return; if (isSubmitting) return; const requiredFields: Array = ["name", "phone", "address"]; From abb64ab4f1c3195144a26b1471e760d909bc11ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EC=88=98=EB=B9=88=20Subin=20OH?= Date: Wed, 7 May 2025 23:38:12 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=EB=B0=98=EC=9D=91=ED=98=95=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/ProfileEditPage.tsx | 2 +- src/pages/ProfileRegisterPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ProfileEditPage.tsx b/src/pages/ProfileEditPage.tsx index effc260..892cf57 100644 --- a/src/pages/ProfileEditPage.tsx +++ b/src/pages/ProfileEditPage.tsx @@ -156,7 +156,7 @@ export default function ProfileEditPage() { -
+
-
+