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 27 마이페이지 UI 및 기능 구현 #89

Merged
merged 3 commits into from
May 10, 2024
Merged
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
4,472 changes: 2,236 additions & 2,236 deletions .pnp.cjs

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/components/MyPage/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { InputProps } from "./types";

const Input = ({ value, id, placeholder, type, onChange }: InputProps) => {
const Input = ({ value, id, placeholder, type, disabled, onChange }: InputProps) => {
const [isHideClicked, setIsHideClicked] = useState(false);

const handleHideClick = () => {
Expand All @@ -10,12 +10,13 @@ const Input = ({ value, id, placeholder, type, onChange }: InputProps) => {
return (
<div className="w-full relative">
<input
className="w-full h-10 bg-[#CCEEFF] text-center "
className={`w-full h-10 bg-[#CCEEFF] text-center ${disabled ? "text-gray-400" : ""}`}
value={value}
placeholder={placeholder}
id={id}
type={isHideClicked ? "text" : "password"}
type={type === "password" && !isHideClicked ? "password" : "text"}
onChange={onChange}
disabled={disabled}
/>
{type === "password" && (
<button className="absolute right-3 top-2.5" onClick={handleHideClick}>
Expand Down
1 change: 1 addition & 0 deletions src/components/MyPage/Input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface InputProps {
id: string;
type?: string;
placeholder: string;
disabled?: boolean;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
}
119 changes: 70 additions & 49 deletions src/components/MyPage/UserInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,97 @@
import React, { ChangeEvent, useState, useContext } from "react";
import AuthContext from "context/AuthContext";
import Input from "../Input";
import React, { useState, useEffect } from "react";
import { UserInfoProps } from "./types";
import { getAuth, deleteUser } from "firebase/auth";
import { app } from "firebaseApp";
import { getAuth, signOut } from "firebase/auth";
import { toast } from "react-toastify";
import { useRouter } from "pages/routing";
import { app, db } from "../../../firebaseApp";
import { getDocs, collection, deleteDoc, doc } from "firebase/firestore";

const UserInfo = () => {
const [userInfo, setUserInfo] = useState<UserInfoProps>({
name: "",
id: "",
email: "",
password: "",
passwordCheck: "",
docId: "",
});

const { user } = useContext(AuthContext);

console.log(user);

const auth = getAuth(app);
const router = useRouter();

console.log(auth.currentUser?.uid);
console.log("=============");

const handleUpdateUserInfo = (e: ChangeEvent<HTMLInputElement>) => {
const { id, value } = e.target;
const handleGetUserInfo = async () => {
try {
const querySnapshot = await getDocs(collection(db, "userInfo"));

setUserInfo((prev: UserInfoProps) => ({
...prev,
[id]: value,
}));
querySnapshot.forEach(doc => {
const { name, email } = doc.data();
setUserInfo(prev => ({
...prev,
name,
email,
docId: doc.id,
}));
});
} catch (e: any) {
toast.error("오류가 발생했습니다");
}
};

const handleDeleteUser = async () => {
try {
await deleteUser(auth.currentUser!).then(res => {
console.log(res);
});
if (confirm("탈퇴하시겠습니까?")) {
try {
await deleteDoc(doc(db, "userInfo", userInfo.docId));
await signOut(auth);

toast.success("회원탈퇴를 완료하였습니다.");

toast.success("회원탈퇴를 완료하였습니다.");
router.push("/");
} catch (error: any) {
console.log(error);
router.push("/");
} catch (error: any) {
console.log(error);
}
}
};

useEffect(() => {
handleGetUserInfo();
}, []);

return (
<div className="w-1/2 h-full flex-Center flex-col gap-2 border-1 p-2 border-cyan-600">
<img className="w-28 h-28 bg-slate-400 rounded-full" src="" />
<Input value={userInfo.name} placeholder="이름" id="name" onChange={handleUpdateUserInfo} />
<Input value={userInfo.email} placeholder="이메일" id="email" onChange={handleUpdateUserInfo} />
<Input
value={userInfo.password}
placeholder="패스워드"
id="password"
type="password"
onChange={handleUpdateUserInfo}
/>
<Input
value={userInfo.passwordCheck}
placeholder="패스워드 확인"
id="passwordCheck"
type="password"
onChange={handleUpdateUserInfo}
/>
<button className="w-full h-10 bg-[#FF4A50] text-center text-cyan-50" onClick={handleDeleteUser}>
<>
<h2 className="text-textBlue font-semibold">마이페이지</h2>
<div className="flex items-center w-full">
<div className="w-4/5">
<img
className="flex w-28 h-28 bg-slate-400 rounded-full"
src="https://www.ailee-shopperhouse.com/images/avatars/1.png"
/>
</div>
<div className="w-1/5">
<div className="flex flex-row justify-between font-semibold">
<div className="flex flex-col items-center dark:text-textWhite">
<h5>생성(개수)</h5>
<p>66</p>
</div>
{/* <div className="flex flex-col items-center font-semibold">
<h5>회원등급</h5>
<p>VIP</p>
</div>
<div className="flex flex-col items-center font-semibold">
<h5>평점</h5>
<p>4.5</p>
</div> */}
</div>
</div>
</div>
<div className="w-full flex flex-col p-2">
<h4 className="text-textBlue font-semibold">{userInfo.name}</h4>
<h5 className="text-textPrimary dark:text-textWhite">{userInfo.email}</h5>
</div>

<button
className="w-full h-16 border-1 border-[#FF4A50] hover:border-gray-500 text-center font-semibold text-[#FF4A50] hover:text-gray-500"
onClick={handleDeleteUser}
>
탈퇴하기
</button>
</div>
</>
);
};

Expand Down
4 changes: 1 addition & 3 deletions src/components/MyPage/UserInfo/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export interface UserInfoProps {
name: string;
id: string;
email: string;
password: string;
passwordCheck: string;
docId: string;
}
65 changes: 31 additions & 34 deletions src/components/MyPage/UserPrevious/index.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
import React from "react";

const CHATLISTDATA = [
{ id: 1, title: "리드미를 써줘", data: "2024-05-10" },
{ id: 2, title: "borderColor가 원하는 값으로 설정해줘", data: "2024-05-05" },
{ id: 3, title: "알고리즘이 중요해?", data: "2024-04-29" },
{ id: 4, title: "자료구조에 대해서 알려줘", data: "2024-04-27" },
{ id: 5, title: "bfs dfs 차이점", data: "2024-04-25" },
{ id: 6, title: "스택은 뭐야", data: "2024-04-18" },
{ id: 7, title: "꿀이랑 허니에 대해 성분 비교 좀", data: "2024-04-13" },
{ id: 8, title: "프로젝트에 대해서 간략하게 알려줘", data: "2024-03-30" },
{ id: 9, title: "해당 프로젝트 설치를 어떻게 해", data: "2024-03-27" },
{ id: 10, title: "테스트 코드를 좀 만들어줘", data: "2024-03-29" },
];

const UserPreviousList = () => {
return (
<div className="w-full h-full grid grid-cols-5 gap-2 border-1 p-2 border-cyan-600">
<button className="h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500 whitespace-wrap">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<button className=" h-32 bg-[#BBDDFF] flex-Center hover:scale-110 transition-transform ease-in-out duration-500">
ReadMe Monster
</button>
<div className="w-full h-full flex flex-wrap gap-2 p-2 ">
{CHATLISTDATA.map(data => {
return (
<div
key={data.id}
className="relative w-28 h-28 bg-[#BBDDFF] hover:scale-110 transition-transform ease-in-out duration-500 cursor-pointer"
style={{ backgroundImage: `url(${"/images/rm-logo.png"})`, backgroundSize: "cover" }}
>
<div className="absolute top-1 right-0 px-2 py-1 text-xs text-white bg-gray-600 rounded-full">
{data.data}
</div>

<div className="absolute bottom-0 left-0 right-0 px-2 text-center bg-gray-800 text-white overflow-hidden whitespace-nowrap">
<div className="truncate font-semibold text-sm">{data.title}</div>
</div>
</div>
);
})}
</div>
);
};
Expand Down
14 changes: 6 additions & 8 deletions src/pages/myPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import UserPreviousList from "../../components/MyPage/UserPrevious";

const MyPage = () => {
return (
<div className="w-fullflex flex-col items-center justify-center">
<section className="w-full">
<div className="flex-Center gap-5 h-[calc(100vh-100px)] p-20 ">
<UserInfo />
<UserPreviousList />
</div>
</section>
</div>
<section className="w-full flex justify-center ">
<div className="flex flex-col items-center justify-center gap-3 p-10 w-2/5 ">
<UserInfo />
<UserPreviousList />
</div>
</section>
);
};

Expand Down
Loading