-
{data.positionTag ? data.positionTag + " " : ""}
{name}
diff --git a/src/app/(route)/my/profile/_components/ProfileImageInput.tsx b/src/app/(route)/my/profile/_components/EditProfileImage/FormEditProfileImageWithPreview.tsx
similarity index 63%
rename from src/app/(route)/my/profile/_components/ProfileImageInput.tsx
rename to src/app/(route)/my/profile/_components/EditProfileImage/FormEditProfileImageWithPreview.tsx
index a0cfbaa..030e46e 100644
--- a/src/app/(route)/my/profile/_components/ProfileImageInput.tsx
+++ b/src/app/(route)/my/profile/_components/EditProfileImage/FormEditProfileImageWithPreview.tsx
@@ -1,13 +1,24 @@
"use client";
import { ChangeEvent, useEffect, useState } from "react";
-
+import ProfileInputArea from "../ProfileInputArea";
import useModal from "@/hooks/useModal";
import ProfileImagePreviewModal from "./ProfileImagePreviewModal";
-import Button from "@/common/Atoms/Form/Button";
+import handleAlert from "@/common/Molecules/handleAlert";
+import ProfileImg from "@/common/Atoms/Image/ProfileImg";
+import { DummyProfileImg } from "@public/images";
import ImageInputWithButton from "@/common/Molecules/Form/ImageInputWithButton";
+import Button from "@/common/Atoms/Form/Button";
-export default function ProfileImageInput() {
- const [imageUrl, setImageUrl] = useState("");
+export type ProfileImageFormProps = {
+ initProfileUrl: string;
+ saveImage: (imageUrl: string) => any;
+};
+
+export default function FormEditProfileImageWithPreview({
+ initProfileUrl,
+ saveImage,
+}: ProfileImageFormProps) {
+ const [imageUrl, setImageUrl] = useState(initProfileUrl);
const { Modal, open, close } = useModal({
children: (
+
{Modal}
- >
+
);
}
diff --git a/src/app/(route)/my/profile/_components/ProfileImagePreviewModal.tsx b/src/app/(route)/my/profile/_components/EditProfileImage/ProfileImagePreviewModal.tsx
similarity index 100%
rename from src/app/(route)/my/profile/_components/ProfileImagePreviewModal.tsx
rename to src/app/(route)/my/profile/_components/EditProfileImage/ProfileImagePreviewModal.tsx
diff --git a/src/app/(route)/my/profile/_components/FormEditProfile.tsx b/src/app/(route)/my/profile/_components/FormEditProfile.tsx
index f7b369a..5d882a6 100644
--- a/src/app/(route)/my/profile/_components/FormEditProfile.tsx
+++ b/src/app/(route)/my/profile/_components/FormEditProfile.tsx
@@ -1,48 +1,21 @@
-import { ActionMeta } from "react-select";
-import {
- ChangeEvent,
- Dispatch,
- FormEvent,
- SetStateAction,
- useEffect,
-} from "react";
+"use client";
+import { FormEvent } from "react";
import Input from "@/common/Molecules/Form/Input";
-import ProfileImageInput from "./ProfileImageInput";
import ProfileInputArea from "./ProfileInputArea";
import Button from "@/common/Atoms/Form/Button";
import { CATEGORIES } from "@/constants/categories/job_category";
-import { Session } from "next-auth";
import { TProfileData } from "./ProfileForms";
import { profileAction } from "@/lib/action";
-import handleAlert from "@/app/(auth)/_components/ErrorAlert";
+import handleAlert from "@/common/Molecules/handleAlert";
export default function FormEditProfile({
userId,
profile,
- sessionProvider,
}: {
userId: string;
profile: TProfileData;
- sessionProvider: string;
}) {
- // const changeData = (
- // e: ChangeEvent
| ChangeEvent
- // ) => {
- // console.log(e.target.name);
- // const name = e.target.name;
- // const value = e.target.value;
- // setData((p) => ({ ...p, [name]: value }));
- // };
- // const changeMultiSelect: (
- // newValue: unknown,
- // actionMeta: ActionMeta
- // ) => void = (newValue) => {
- // // console.log({ newValue });
- // if (Array.isArray(newValue)) setData((p) => ({ ...p, interest: newValue }));
- // };
- console.log("?" + userId);
-
async function save(e: FormEvent) {
e.preventDefault();
@@ -79,8 +52,7 @@ export default function FormEditProfile({
name="email"
// value={data.email}
// onChange={changeData}
- placeholder="이메일 주소를 입력하세요"
- readOnly={sessionProvider !== "credentials"}
+ readOnly
/>
{false && (
diff --git a/src/app/(route)/my/profile/_components/ProfileForms.tsx b/src/app/(route)/my/profile/_components/ProfileForms.tsx
index 9201129..78f6953 100644
--- a/src/app/(route)/my/profile/_components/ProfileForms.tsx
+++ b/src/app/(route)/my/profile/_components/ProfileForms.tsx
@@ -1,36 +1,32 @@
-"use client";
-import ProfileInputArea from "./ProfileInputArea";
-import ProfileImageInput from "./ProfileImageInput";
-import FormEditProfile from "./FormEditProfile";
-import { getUser } from "@/dummies/user";
-import { useEffect, useState } from "react";
import SectionTitle from "@/common/Atoms/Text/SectionTitle";
-import FormUpdatePassword from "./FormUpdatePassword";
-import FormUpdatePhoneNumber from "./FormUpdatePhoneNumber";
+import FormUpdatePassword from "./UpdatePassword/FormUpdatePassword";
+import FormUpdatePhoneNumber from "./UpdatePhoneNumber/FormUpdatePhoneNumber";
import DeleteAccountConfirm from "./DeleteAccountConfirm";
-import ProfilePreview from "./ProfilePreview";
-import { Session } from "next-auth";
import { CategoryOption } from "@/types/model/Category";
-import { ProfileSchema } from "@/types/model/Profile";
+import { ProfileFullDataSchema } from "@/types/model/Profile";
import { CATEGORIES_ALL_OPTIONS } from "@/constants/categories/job_category";
+import FormEditProfileImageWithPreview from "./EditProfileImage/FormEditProfileImageWithPreview";
+import FormEditProfile from "./FormEditProfile";
+import connectDB from "@/lib/db";
+import { User } from "@/lib/schema";
+import { Session } from "next-auth";
export type TProfileData = {
- profileUrl: string;
positionTag: string;
introduce: string;
email: string;
interest: Array
;
};
-export default function ProfileForms({
- userId,
+export default async function ProfileForms({
+ session,
profile,
- sessionProvider,
}: {
- userId: string;
- profile: ProfileSchema | null;
- sessionProvider: string;
+ session: Session | null;
+ profile: ProfileFullDataSchema | null;
}) {
+ const userId = session?.user.id as string;
+ const sessionProvider = session?.account.provider as string;
// const user = getUser();
const interestCategory: CategoryOption[] =
profile?.my_category && profile.my_category.length > 0
@@ -41,8 +37,8 @@ export default function ProfileForms({
) as CategoryOption
)
: [];
+ const initProfileUrl = profile?.userId.profile_img || "";
const profileData = {
- profileUrl: profile?.userId.profile_img || "",
positionTag: profile?.position_tag || "",
introduce: profile?.introduce || "",
email: profile?.userId.email || "",
@@ -50,47 +46,53 @@ export default function ProfileForms({
};
console.log({ profile, profileData });
- const [data, setData] = useState(profileData);
- const setProfileImage = (image: string) => {
- setData((prev) => ({ ...prev, profileUrl: image }));
- };
+ async function saveImage(imageUrl: string) {
+ "use server";
+ await connectDB();
+
+ try {
+ const updated = await User.findOneAndUpdate(
+ { userId },
+ { image: imageUrl }
+ );
+ return updated;
+ // handleAlert("success", "프로필 이미지가 저장되었습니다.");
+ } catch (error: any) {
+ // handleAlert("error", error.message);
+ }
+ }
return (
<>
-
-
-
{profile?.userId.name}
-
-
-
-
-
- {sessionProvider === "credentials" && (
- <>
-
-
- 비밀번호 수정
-
-
- >
- )}
-
-
- 연락처 수정
-
-
-
-
-
+
+
{session?.user.name}
+
+
+
+ {sessionProvider === "credentials" && (
+ <>
+
+
+ 비밀번호 수정
+
+
+ >
+ )}
+
+
+ 연락처 수정
+
+
+
+
+
- {/*
>
);
}
diff --git a/src/app/(route)/my/profile/_components/FormUpdatePassword.tsx b/src/app/(route)/my/profile/_components/UpdatePassword/FormUpdatePassword.tsx
similarity index 92%
rename from src/app/(route)/my/profile/_components/FormUpdatePassword.tsx
rename to src/app/(route)/my/profile/_components/UpdatePassword/FormUpdatePassword.tsx
index cb1a984..0571311 100644
--- a/src/app/(route)/my/profile/_components/FormUpdatePassword.tsx
+++ b/src/app/(route)/my/profile/_components/UpdatePassword/FormUpdatePassword.tsx
@@ -1,10 +1,10 @@
import Input from "@/common/Molecules/Form/Input";
import Button from "@/common/Atoms/Form/Button";
-import ProfileInputArea from "./ProfileInputArea";
+import ProfileInputArea from "../ProfileInputArea";
export default function FormUpdatePassword() {
return (
-