diff --git a/apps/X/app/api/user/route.ts b/apps/X/app/api/user/route.ts index 216b61a..bc0bd52 100644 --- a/apps/X/app/api/user/route.ts +++ b/apps/X/app/api/user/route.ts @@ -1,7 +1,7 @@ import { PrismaClient } from "@prisma/client"; import { authOptions } from "app/lib/auth"; import { getServerSession } from "next-auth"; -import { NextResponse } from "next/server"; +import { NextRequest, NextResponse } from "next/server"; const prisma = new PrismaClient(); @@ -10,7 +10,6 @@ export const GET = async () => { if (!session) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - const userID = session.user.id; try { @@ -34,3 +33,44 @@ export const GET = async () => { }); } }; + +interface EditUserInfoProp { + username: string; + bio: string; + location: string; + biolink: string; + dob: string; +} + +export const POST = async (req: NextRequest) => { + console.log("Hitting here"); + try { + const session = await getServerSession(authOptions); + if (!session) { + return NextResponse.json({ message: "Unauthorized" }, { status: 401 }); + } + const user: EditUserInfoProp = await req.json(); + const userID = session?.user?.id; + + const updatedUser = await prisma.user.update({ + data: { + username: user.username, + bio: user.bio, + location: user.location, + bioLink: user.biolink, + DOB: user.dob, + }, + where: { id: userID }, + }); + + return NextResponse.json( + { message: "Profile updated successfully", data: updatedUser }, + { status: 200 } + ); + } catch (error) { + return NextResponse.json( + { message: "Getting error while Updating User Profile" }, + { status: 500 } + ); + } +}; diff --git a/apps/X/src/components/ui/Post/TopPostHome.tsx b/apps/X/src/components/ui/Post/TopPostHome.tsx index 0bafca1..f15699c 100644 --- a/apps/X/src/components/ui/Post/TopPostHome.tsx +++ b/apps/X/src/components/ui/Post/TopPostHome.tsx @@ -23,7 +23,6 @@ export const TopPost = () => { setPostInput(e.target.value); }; const handelClick = async () => { - console.log(postInput); if (!session?.user?.email) { console.error("No User session found"); return; diff --git a/apps/X/src/components/ui/Profile/EditProfileComp.tsx b/apps/X/src/components/ui/Profile/EditProfileComp.tsx new file mode 100644 index 0000000..d1d91f6 --- /dev/null +++ b/apps/X/src/components/ui/Profile/EditProfileComp.tsx @@ -0,0 +1,107 @@ +"use client"; +import axios from "axios"; +import { Button } from "../button"; +import { useState } from "react"; + +interface ProfileFormData { + username: string; + bio: string; + location: string; + biolink: string; + dob: string; +} + +export const EditProfileComp = () => { + const [formInput, setFormInput] = useState({ + username: "", + bio: "", + location: "", + biolink: "", + dob: "", + }); + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFormInput((prev) => ({ + ...prev, + [name]: value, + })); + }; + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + console.log("submiting", formInput); + try { + const response = await axios.post("/api/user", formInput); + } catch (error) { + console.error("Error updating Profile", error); + } + }; + return ( +
+
+
+
+

Edit profile

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+ ); +}; diff --git a/apps/X/src/components/ui/Profile/UserInfo.tsx b/apps/X/src/components/ui/Profile/UserInfo.tsx index 834db7a..05b12eb 100644 --- a/apps/X/src/components/ui/Profile/UserInfo.tsx +++ b/apps/X/src/components/ui/Profile/UserInfo.tsx @@ -1,6 +1,7 @@ "use client"; -import { TopHeader } from "@/components/TopHeader"; +import { LoaderComp } from "@/components/LoaderComp"; +import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog"; import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar"; import axios from "axios"; import { useSession } from "next-auth/react"; @@ -9,11 +10,8 @@ import { AiOutlineLink } from "react-icons/ai"; import { GrLocation } from "react-icons/gr"; import { IoCalendarOutline } from "react-icons/io5"; import { PiBalloon } from "react-icons/pi"; -import { Button } from "../button"; import { TweetComp } from "../TweetComp"; -import { NextResponse } from "next/server"; -import { LoaderComp } from "@/components/LoaderComp"; - +import { EditProfileComp } from "./EditProfileComp"; interface UserDataProps { DOB: string; location: string; @@ -61,7 +59,7 @@ export const UserInfo = () => { try { const response = await axios.get(`api/post/$[userID]`); const tweetsByUser = response.data.data; - console.log(tweetsByUser, "This is from user"); + // console.log(tweetsByUser, "This is from user"); setUserTweet(tweetsByUser); } catch (error) { console.log(error); @@ -96,9 +94,17 @@ export const UserInfo = () => {
- + */} + + + Edit Profile + + + + +
@@ -145,137 +151,7 @@ export const UserInfo = () => { Followers - - - {/*
-
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
-
-
-
-

- This is some placeholder content the{" "} - - Profile tab associated content - - . Clicking another tab will toggle the visibility of this one - for the next. The tab JavaScript swaps classes to control the - content visibility and styling. -

-
-
-

- This is some placeholder content the{" "} - - Dashboard tabs associated content - - . Clicking another tab will toggle the visibility of this one - for the next. The tab JavaScript swaps classes to control the - content visibility and styling. -

-
-
-

- This is some placeholder content the{" "} - - Settings tabs associated content - - . Clicking another tab will toggle the visibility of this one - for the next. The tab JavaScript swaps classNamees to control - the content visibility and styling. -

-
-
-

- This is some placeholder content the{" "} - - Contacts tabs associated content - - . Clicking another tab will toggle the visibility of this one - for the next. The tab JavaScript swaps classes to control the - content visibility and styling. -

-
-
*/} + {" "}
diff --git a/apps/X/src/components/ui/home/HomeLeft.tsx b/apps/X/src/components/ui/home/HomeLeft.tsx index 3eb5f14..e58f48d 100644 --- a/apps/X/src/components/ui/home/HomeLeft.tsx +++ b/apps/X/src/components/ui/home/HomeLeft.tsx @@ -139,12 +139,6 @@ export const HomeLeft = () => {
- {/* */} Post diff --git a/apps/X/src/components/ui/index.ts b/apps/X/src/components/ui/index.ts index 8c9f818..99c0cfd 100644 --- a/apps/X/src/components/ui/index.ts +++ b/apps/X/src/components/ui/index.ts @@ -20,8 +20,10 @@ import { TopHeader } from "../TopHeader"; import { userInfo } from "os"; import { X_loaderComp } from "../X_loaderComp"; +import { EditProfileComp } from "./Profile/EditProfileComp"; export { + EditProfileComp, TopHead, TopPost, SigninComp,