Skip to content

Commit c4a500c

Browse files
authored
feat: profile page (#300)
* feat: user card * fix: update * merge develop && update * feat: user generate bio & favourite topic * fix: update user card * feat: added profile sidebar * fix: update * update * update * update * fix: fetch approved and public threads * fix: fetch approved and public threads * update * fix: clean up and update * update * make fetch user work with bio * update * update * design updating * update * update * fix: few changes * update * fix: design update * fix: footer in layout * fix: update * fix: resercation * update * profile upload * feat: move the cloudinary key to env * fix: layout * fix: layout update
1 parent 02adc39 commit c4a500c

File tree

48 files changed

+4514
-1767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4514
-1767
lines changed

apps/hasura/metadata/databases/masterbots/tables/public_user.yaml

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
table:
22
name: user
33
schema: public
4-
54
array_relationships:
65
- name: chats
76
using:
@@ -17,105 +16,104 @@ array_relationships:
1716
table:
1817
name: social_following
1918
schema: public
20-
2119
- name: following
2220
using:
2321
foreign_key_constraint_on:
2422
column: follower_id
2523
table:
2624
name: social_following
2725
schema: public
28-
2926
- name: preferences
3027
using:
3128
foreign_key_constraint_on:
3229
column: user_id
3330
table:
3431
name: preference
3532
schema: public
36-
3733
- name: prompts
3834
using:
3935
foreign_key_constraint_on:
4036
column: user_id
4137
table:
4238
name: prompt_user
4339
schema: public
44-
4540
- name: referrals
4641
using:
4742
foreign_key_constraint_on:
4843
column: referrer_id
4944
table:
5045
name: referral
5146
schema: public
52-
5347
- name: referralsByUserId
5448
using:
5549
foreign_key_constraint_on:
5650
column: user_id
5751
table:
5852
name: referral
5953
schema: public
60-
6154
- name: threads
6255
using:
6356
foreign_key_constraint_on:
6457
column: user_id
6558
table:
6659
name: thread
6760
schema: public
68-
6961
- name: userTokens
7062
using:
7163
foreign_key_constraint_on:
7264
column: user_id
7365
table:
7466
name: user_token
7567
schema: public
76-
7768
insert_permissions:
7869
- role: moderator
7970
permission:
8071
check: {}
8172
columns:
73+
- bio
74+
- date_joined
75+
- email
76+
- favourite_topic
8277
- get_free_month
8378
- is_blocked
84-
- email
79+
- last_login
8580
- password
86-
- profile_picture
8781
- pro_user_subscription_id
88-
- slug
89-
- username
90-
- date_joined
91-
- last_login
82+
- profile_picture
9283
- role
84+
- slug
9385
- user_id
86+
- username
9487
comment: ""
95-
9688
- role: user
9789
permission:
9890
check: {}
9991
columns:
92+
- bio
10093
- email
94+
- favourite_topic
10195
- get_free_month
10296
- is_blocked
10397
- last_login
10498
- password
10599
- pro_user_subscription_id
106100
- profile_picture
101+
- role
107102
- slug
108103
- username
109104
comment: ""
110105
select_permissions:
111106
- role: anonymous
112107
permission:
113108
columns:
109+
- bio
114110
- date_joined
115111
- email
112+
- favourite_topic
116113
- last_login
117114
- pro_user_subscription_id
118115
- profile_picture
116+
- role
119117
- slug
120118
- user_id
121119
- username
@@ -141,8 +139,10 @@ select_permissions:
141139
- role: user
142140
permission:
143141
columns:
142+
- bio
144143
- date_joined
145144
- email
145+
- favourite_topic
146146
- get_free_month
147147
- is_blocked
148148
- is_verified
@@ -156,26 +156,41 @@ select_permissions:
156156
filter:
157157
user_id:
158158
_eq: X-Hasura-User-Id
159-
comment: ""
159+
comment: ""
160160
update_permissions:
161161
- role: moderator
162162
permission:
163163
columns:
164+
- bio
165+
- date_joined
166+
- favourite_topic
167+
- get_free_month
164168
- is_blocked
169+
- last_login
170+
- password
171+
- pro_user_subscription_id
172+
- profile_picture
173+
- role
174+
- slug
175+
- username
165176
filter: {}
166177
check: null
167-
comment: "Allows moderators to block any user"
168-
178+
comment: Allows moderators to block any user
169179
- role: user
170180
permission:
171181
columns:
182+
- bio
183+
- favourite_topic
172184
- get_free_month
173185
- last_login
174186
- password
175187
- pro_user_subscription_id
176188
- profile_picture
189+
- role
190+
- slug
191+
- username
177192
filter:
178193
user_id:
179194
_eq: X-Hasura-User-Id
180195
check: null
181-
comment: ""
196+
comment: ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Could not auto-generate a down migration.
2+
-- Please write an appropriate down migration for the SQL below:
3+
alter table "public"."user" add column "bio" text
4+
null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table "public"."user" add column "bio" text
2+
null;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Could not auto-generate a down migration.
2+
-- Please write an appropriate down migration for the SQL below:
3+
-- alter table "public"."user" add column "favourite_topic" text
4+
-- null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table "public"."user" add column "favourite_topic" text
2+
null;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import FooterCT from '@/components/layout/footer/footer-ct'
2+
import NextTopLoader from 'nextjs-toploader'
3+
import { Hero } from '@/components/layout/profile/hero'
4+
import { ProfileSidebar } from '@/components/layout/profile/profile-page-sidebar'
5+
6+
interface ProfileLayoutProps {
7+
children: React.ReactNode
8+
}
9+
10+
export default async function ProfilePageLayout({ children }: ProfileLayoutProps) {
11+
return (
12+
<main className="min-h-screen flex flex-col p-0">
13+
<NextTopLoader color="#1ED761" initialPosition={0.2} />
14+
<Hero />
15+
<div className="flex-grow">
16+
<div className="relative flex min-h-[calc(100vh-4rem)]">
17+
<ProfileSidebar>
18+
<div className="relative h-full z-0">
19+
<div className='min-h-[calc(100vh-4rem)]'>
20+
{children}
21+
</div>
22+
<div className="sticky bottom-0 w-full left-0 z-50 dark:bg-black bg-white">
23+
<FooterCT className='flex justify-start items-center text-center'/>
24+
</div>
25+
</div>
26+
</ProfileSidebar>
27+
</div>
28+
</div>
29+
</main>
30+
)
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { BrowseChatMessageList } from '@/components/routes/browse/browse-chat-message-list'
2+
import { getThread } from '@/services/hasura'
3+
import { User } from 'mb-genql'
4+
5+
interface ThreadPageProps {
6+
params: {
7+
category: string
8+
threadId: string
9+
chatbot: string
10+
}
11+
}
12+
export default async function ThreadPage({ params }: ThreadPageProps) {
13+
14+
15+
const thread = await getThread({
16+
threadId: params.threadId,
17+
jwt: ''
18+
})
19+
20+
if(!thread){
21+
return <div>Thread not found</div>
22+
}
23+
const { user, chatbot, messages } = thread
24+
25+
return (
26+
<BrowseChatMessageList
27+
user={user as User | undefined}
28+
chatbot={chatbot}
29+
messages={messages}
30+
isThread
31+
/>
32+
)
33+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { authOptions } from "@/auth";
2+
import UserThreadPanel from "@/components/routes/thread/user-thread-panel";
3+
import { botNames } from "@/lib/constants/bots-names";
4+
import { getBrowseThreads, getThreads, getUserBySlug} from "@/services/hasura/hasura.service";
5+
import { getServerSession } from "next-auth";
6+
7+
8+
export default async function ProfileChatBot({ params }: { params: {
9+
slug: string;
10+
category: string;
11+
chatbot: string;
12+
}
13+
}) {
14+
let threads = [];
15+
const { slug, category, chatbot } = params;
16+
const session = await getServerSession(authOptions);
17+
const jwt = session ? session.user?.hasuraJwt : '';
18+
const { user, error } = await getUserBySlug({
19+
slug,
20+
isSameUser: session?.user.slug === slug
21+
});
22+
if (!user) return <div>No user found</div>
23+
24+
const chatbotName = botNames.get(chatbot);
25+
if (!chatbotName) {
26+
throw new Error(`Chatbot name for ${chatbot} not found`);
27+
}
28+
29+
const fetchThreads = async () => {
30+
try {
31+
const isOwnProfile = session?.user?.id === user?.userId;
32+
if (!isOwnProfile) {
33+
return await getBrowseThreads({
34+
userId: user.userId,
35+
chatbotName
36+
});
37+
}
38+
39+
if (!session?.user?.hasuraJwt) {
40+
throw new Error('Authentication required');
41+
}
42+
43+
return await getThreads({
44+
jwt,
45+
userId: user.userId,
46+
chatbotName
47+
});
48+
} catch (error) {
49+
console.error('Failed to fetch threads:', error);
50+
return [];
51+
}
52+
};
53+
54+
threads = await fetchThreads();
55+
56+
return (
57+
<UserThreadPanel
58+
threads={threads}
59+
chatbot={chatbot}
60+
page="profile"
61+
/>
62+
)
63+
}

apps/masterbots.ai/app/u/[slug]/t/[category]/[threadId]/page.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)