Skip to content

Commit b8dd15d

Browse files
committed
on hold
1 parent fcab107 commit b8dd15d

File tree

6 files changed

+167
-148
lines changed

6 files changed

+167
-148
lines changed

apps/X/app/api/user/route.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PrismaClient } from "@prisma/client";
22
import { authOptions } from "app/lib/auth";
33
import { getServerSession } from "next-auth";
4-
import { NextResponse } from "next/server";
4+
import { NextRequest, NextResponse } from "next/server";
55

66
const prisma = new PrismaClient();
77

@@ -10,7 +10,6 @@ export const GET = async () => {
1010
if (!session) {
1111
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
1212
}
13-
1413
const userID = session.user.id;
1514

1615
try {
@@ -34,3 +33,46 @@ export const GET = async () => {
3433
});
3534
}
3635
};
36+
37+
interface EditUserInfoProp {
38+
username: string;
39+
bio: string;
40+
location: string;
41+
biolink: string;
42+
dob: string;
43+
}
44+
45+
export const POST = async (req: NextRequest, user: EditUserInfoProp) => {
46+
console.log("Hitting here");
47+
try {
48+
const session = await getServerSession(authOptions);
49+
if (!session) {
50+
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
51+
}
52+
const body = await req.json();
53+
console.log("Request Body:", body);
54+
const userID = session?.user?.id;
55+
56+
const updatedUser = await prisma.user.update({
57+
data: {
58+
username: user.username,
59+
bio: user.bio,
60+
location: user.location,
61+
bioLink: user.biolink,
62+
DOB: user.dob,
63+
},
64+
where: { id: userID },
65+
});
66+
67+
console.log(updatedUser, "<<<<<<<<<<<<<<<<<<<<<<<");
68+
return NextResponse.json(
69+
{ message: "Profile updated successfully", data: updatedUser },
70+
{ status: 200 }
71+
);
72+
} catch (error) {
73+
return NextResponse.json(
74+
{ message: "Getting error while Updating User Profile" },
75+
{ status: 500 }
76+
);
77+
}
78+
};

apps/X/src/components/ui/Post/TopPostHome.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const TopPost = () => {
2323
setPostInput(e.target.value);
2424
};
2525
const handelClick = async () => {
26-
console.log(postInput);
2726
if (!session?.user?.email) {
2827
console.error("No User session found");
2928
return;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import axios from "axios";
2+
import { Button } from "../button";
3+
import { useState } from "react";
4+
5+
interface ProfileFormData {
6+
username: string;
7+
bio: string;
8+
location: string;
9+
biolink: string;
10+
dob: string;
11+
}
12+
13+
export const EditProfileComp = () => {
14+
const [formInput, setFormInput] = useState<ProfileFormData>({
15+
username: "",
16+
bio: "",
17+
location: "",
18+
biolink: "",
19+
dob: "",
20+
});
21+
22+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
23+
const { name, value } = e.target;
24+
setFormInput((prev) => ({
25+
...prev,
26+
[name]: value,
27+
}));
28+
};
29+
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
30+
e.preventDefault();
31+
console.log("submiting", formInput);
32+
try {
33+
const response = await axios.post("/api/user", formInput);
34+
} catch (error) {
35+
console.error("Error updating Profile", error);
36+
}
37+
};
38+
return (
39+
<div>
40+
<div>
41+
<form onSubmit={handleSubmit}>
42+
<div className="flex items-center justify-between">
43+
<p className="text-xl font-semibold">Edit profile</p>
44+
<Button type="submit" className="rounded-2xl px-5 py-1">
45+
Save
46+
</Button>
47+
</div>
48+
<div>
49+
<div className="flex flex-col border mt-3">
50+
<label className="text-sm text-slate-500 pl-2 pt-1">Name</label>
51+
<input
52+
name="username"
53+
value={formInput.username}
54+
className="border-none focus:outline-none bg-transparent pl-2 pb-1 pt-1"
55+
onChange={handleChange}
56+
/>
57+
</div>
58+
<div className="flex flex-col border mt-6">
59+
<label className="text-sm text-slate-500 pl-2 pt-1">Bio</label>
60+
<input
61+
name="Bio"
62+
value={formInput.bio}
63+
className="border-none focus:outline-none bg-transparent pl-2 h-16 pb-1 pt-1"
64+
onChange={handleChange}
65+
/>
66+
</div>
67+
<div className="flex flex-col border mt-6">
68+
<label className="text-sm text-slate-500 pl-2 pt-1">
69+
Location
70+
</label>
71+
<input
72+
name="Location"
73+
value={formInput.location}
74+
className="border-none focus:outline-none bg-transparent pl-2 pb-1 pt-1"
75+
onChange={handleChange}
76+
/>
77+
</div>
78+
<div className="flex flex-col border mt-6">
79+
<label className="text-sm text-slate-500 pl-2 pt-1">
80+
Website
81+
</label>
82+
<input
83+
name="Website"
84+
value={formInput.biolink}
85+
className="border-none focus:outline-none bg-transparent pl-2 pb-1 pt-1"
86+
onChange={handleChange}
87+
/>
88+
</div>
89+
<div className="flex flex-col border mt-6">
90+
<label className="text-sm text-slate-500 pl-2 pt-1 pb-1">
91+
Date of Birth
92+
</label>
93+
<input
94+
type="date"
95+
name="DOB"
96+
value={formInput.dob}
97+
className="border-none focus:outline-none text-slate-700 bg-transparent pl-2"
98+
onChange={handleChange}
99+
/>
100+
</div>
101+
</div>
102+
</form>
103+
</div>
104+
</div>
105+
);
106+
};

apps/X/src/components/ui/Profile/UserInfo.tsx

Lines changed: 15 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

3-
import { TopHeader } from "@/components/TopHeader";
3+
import { LoaderComp } from "@/components/LoaderComp";
4+
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
45
import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
56
import axios from "axios";
67
import { useSession } from "next-auth/react";
@@ -9,11 +10,8 @@ import { AiOutlineLink } from "react-icons/ai";
910
import { GrLocation } from "react-icons/gr";
1011
import { IoCalendarOutline } from "react-icons/io5";
1112
import { PiBalloon } from "react-icons/pi";
12-
import { Button } from "../button";
1313
import { TweetComp } from "../TweetComp";
14-
import { NextResponse } from "next/server";
15-
import { LoaderComp } from "@/components/LoaderComp";
16-
14+
import { EditProfileComp } from "./EditProfileComp";
1715
interface UserDataProps {
1816
DOB: string;
1917
location: string;
@@ -61,7 +59,7 @@ export const UserInfo = () => {
6159
try {
6260
const response = await axios.get(`api/post/$[userID]`);
6361
const tweetsByUser = response.data.data;
64-
console.log(tweetsByUser, "This is from user");
62+
// console.log(tweetsByUser, "This is from user");
6563
setUserTweet(tweetsByUser);
6664
} catch (error) {
6765
console.log(error);
@@ -96,9 +94,17 @@ export const UserInfo = () => {
9694
</div>
9795
<div className="text-right pr-4 mt-4">
9896
<div>
99-
<Button className="bg-black text-white rounded-2xl border px-7 border-white hover:bg-neutral-900 transition duration-200 font-bold text-md">
97+
{/* <Button className="bg-black text-white rounded-2xl border px-7 border-white hover:bg-neutral-900 transition duration-200 font-bold text-md">
10098
Edit Profile
101-
</Button>
99+
</Button> */}
100+
<Dialog>
101+
<DialogTrigger className="bg-black text-white rounded-2xl border px-7 border-white hover:bg-neutral-900 transition duration-200 font-bold text-md">
102+
Edit Profile
103+
</DialogTrigger>
104+
<DialogContent className="bg-black w-full">
105+
<EditProfileComp />
106+
</DialogContent>
107+
</Dialog>
102108
</div>
103109
</div>
104110
</div>
@@ -145,137 +151,7 @@ export const UserInfo = () => {
145151
<span className="text-gray-500 ml-1">Followers</span>
146152
</div>
147153
</div>
148-
</div>
149-
150-
{/* <div className="mb-4 border-b border-gray-200 dark:border-gray-700">
151-
<ul
152-
className="flex flex-wrap -mb-px text-sm font-medium text-center"
153-
id="default-styled-tab"
154-
data-tabs-toggle="#default-styled-tab-content"
155-
data-tabs-active-classes="text-purple-600 hover:text-purple-600 dark:text-purple-500 dark:hover:text-purple-500 border-purple-600 dark:border-purple-500"
156-
data-tabs-inactive-classes="dark:border-transparent text-gray-500 hover:text-gray-600 dark:text-gray-400 border-gray-100 hover:border-gray-300 dark:border-gray-700 dark:hover:text-gray-300"
157-
role="tablist"
158-
>
159-
<li className="me-2" role="presentation">
160-
<button
161-
className="inline-block p-4 border-b-2 rounded-t-lg"
162-
id="profile-styled-tab"
163-
data-tabs-target="#styled-profile"
164-
type="button"
165-
role="tab"
166-
aria-controls="profile"
167-
aria-selected="false"
168-
>
169-
Profile
170-
</button>
171-
</li>
172-
<li className="me-2" role="presentation">
173-
<button
174-
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
175-
id="dashboard-styled-tab"
176-
data-tabs-target="#styled-dashboard"
177-
type="button"
178-
role="tab"
179-
aria-controls="dashboard"
180-
aria-selected="false"
181-
>
182-
Dashboard
183-
</button>
184-
</li>
185-
<li className="me-2" role="presentation">
186-
<button
187-
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
188-
id="settings-styled-tab"
189-
data-tabs-target="#styled-settings"
190-
type="button"
191-
role="tab"
192-
aria-controls="settings"
193-
aria-selected="false"
194-
>
195-
Settings
196-
</button>
197-
</li>
198-
<li role="presentation">
199-
<button
200-
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
201-
id="contacts-styled-tab"
202-
data-tabs-target="#styled-contacts"
203-
type="button"
204-
role="tab"
205-
aria-controls="contacts"
206-
aria-selected="false"
207-
>
208-
Contacts
209-
</button>
210-
</li>
211-
</ul>
212-
</div>
213-
<div id="default-styled-tab-content">
214-
<div
215-
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
216-
id="styled-profile"
217-
role="tabpanel"
218-
aria-labelledby="profile-tab"
219-
>
220-
<p className="text-sm text-gray-500 dark:text-gray-400">
221-
This is some placeholder content the{" "}
222-
<strong className="font-medium text-gray-800 dark:text-white">
223-
Profile tab associated content
224-
</strong>
225-
. Clicking another tab will toggle the visibility of this one
226-
for the next. The tab JavaScript swaps classes to control the
227-
content visibility and styling.
228-
</p>
229-
</div>
230-
<div
231-
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
232-
id="styled-dashboard"
233-
role="tabpanel"
234-
aria-labelledby="dashboard-tab"
235-
>
236-
<p className="text-sm text-gray-500 dark:text-gray-400">
237-
This is some placeholder content the{" "}
238-
<strong className="font-medium text-gray-800 dark:text-white">
239-
Dashboard tabs associated content
240-
</strong>
241-
. Clicking another tab will toggle the visibility of this one
242-
for the next. The tab JavaScript swaps classes to control the
243-
content visibility and styling.
244-
</p>
245-
</div>
246-
<div
247-
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
248-
id="styled-settings"
249-
role="tabpanel"
250-
aria-labelledby="settings-tab"
251-
>
252-
<p className="text-sm text-gray-500 dark:text-gray-400">
253-
This is some placeholder content the{" "}
254-
<strong className="font-medium text-gray-800 dark:text-white">
255-
Settings tabs associated content
256-
</strong>
257-
. Clicking another tab will toggle the visibility of this one
258-
for the next. The tab JavaScript swaps classNamees to control
259-
the content visibility and styling.
260-
</p>
261-
</div>
262-
<div
263-
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
264-
id="styled-contacts"
265-
role="tabpanel"
266-
aria-labelledby="contacts-tab"
267-
>
268-
<p className="text-sm text-gray-500 dark:text-gray-400">
269-
This is some placeholder content the{" "}
270-
<strong className="font-medium text-gray-800 dark:text-white">
271-
Contacts tabs associated content
272-
</strong>
273-
. Clicking another tab will toggle the visibility of this one
274-
for the next. The tab JavaScript swaps classes to control the
275-
content visibility and styling.
276-
</p>
277-
</div>
278-
</div> */}
154+
</div>{" "}
279155
</div>
280156
</div>
281157
<br />

apps/X/src/components/ui/home/HomeLeft.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ export const HomeLeft = () => {
139139
</div>
140140
</div>
141141
<div className="">
142-
{/* <Button
143-
className="invisible custom:visible rounded-3xl w-full custom:mt-3 px-20 py-6 font-semibold"
144-
onClick={onPostClick}
145-
>
146-
Post
147-
</Button> */}
148142
<Dialog>
149143
<DialogTrigger className="invisible custom:visible rounded-3xl w-full custom:mt-3 px-20 py-3 font-semibold bg-white text-black items-start">
150144
Post

apps/X/src/components/ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import { TopHeader } from "../TopHeader";
2020
import { userInfo } from "os";
2121

2222
import { X_loaderComp } from "../X_loaderComp";
23+
import { EditProfileComp } from "./Profile/EditProfileComp";
2324

2425
export {
26+
EditProfileComp,
2527
TopHead,
2628
TopPost,
2729
SigninComp,

0 commit comments

Comments
 (0)