Skip to content

Commit 040e995

Browse files
committed
feat: enhance user profile editing with profile image display and username input
1 parent 7a19423 commit 040e995

File tree

1 file changed

+72
-33
lines changed

1 file changed

+72
-33
lines changed

web/src/app/(content)/user/[username]/edit/UserEditProfile.tsx

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
88
import { zodResolver } from '@hookform/resolvers/zod';
99
import { deepFreeze } from '@shared/validation/common/deepFreeze';
1010
import type { UserProfileViewDto } from '@shared/validation/user/dto/UserProfileView.dto';
11+
import Image from 'next/image';
1112
import Link from 'next/link';
1213
import { useEffect } from 'react';
1314
import { useForm } from 'react-hook-form';
@@ -18,14 +19,7 @@ import {
1819
Input,
1920
TextArea,
2021
} from '@web/src/modules/shared/components/client/FormElements';
21-
22-
type UserProfileEditStore = {
23-
isLoading: boolean;
24-
isLocked: boolean;
25-
userData: UserProfileViewDto | null;
26-
setUserData: (data: UserProfileViewDto) => void;
27-
updateUserData: (data: Partial<UserProfileViewDto>) => void;
28-
};
22+
import { EarlySupporterBadge } from '@web/src/modules/user/components/UserBadges';
2923

3024
export const LinkRegexes = deepFreeze({
3125
bandcamp: /https?:\/\/[a-zA-Z0-9_-]+\.bandcamp\.com\/?/,
@@ -66,12 +60,21 @@ const socialLinksSchema = zod.object({
6660
});
6761

6862
const userProfileEditFormSchema = zod.object({
63+
username: zod.string().min(3).max(20),
6964
description: zod.string().optional(),
7065
socialLinks: socialLinksSchema,
7166
});
7267

7368
type UserProfileEditFormSchema = zod.infer<typeof userProfileEditFormSchema>;
7469

70+
type UserProfileEditStore = {
71+
isLoading: boolean;
72+
isLocked: boolean;
73+
userData: UserProfileViewDto | null;
74+
setUserData: (data: UserProfileViewDto) => void;
75+
updateUserData: (data: Partial<UserProfileViewDto>) => void;
76+
};
77+
7578
const useUserProfileEdit = create<UserProfileEditStore>((set, get) => {
7679
return {
7780
isLoading: true,
@@ -109,7 +112,7 @@ type UserEditProfileProps = {
109112
export const UserEditProfile: React.FC<UserEditProfileProps> = ({
110113
initialUserData,
111114
}) => {
112-
const { setUserData, isLoading, isLocked } = useUserProfileEdit();
115+
const { setUserData, isLoading, isLocked, userData } = useUserProfileEdit();
113116

114117
useEffect(() => {
115118
setUserData(initialUserData);
@@ -205,38 +208,74 @@ export const UserEditProfile: React.FC<UserEditProfileProps> = ({
205208
},
206209
];
207210

211+
const { username, profileImage } = initialUserData;
212+
208213
return (
209214
<div className='max-w-screen-lg mx-auto'>
210215
<section>
211-
<h1>Edit Profile</h1>
212-
{/* Add your edit profile form here */}
213-
216+
<div className='flex items-center justify-center gap-2 my-3 bg-cyan-800 border-cyan-400 text-cyan-300 border-2 rounded-lg px-3 py-2 text-sm'>
217+
<FontAwesomeIcon icon={faExclamationCircle} className='h-5' />
218+
<p>
219+
Please make sure to carefully review our{' '}
220+
<Link
221+
href='/guidelines'
222+
target='_blank'
223+
className='text-blue-400 hover:text-blue-300 hover:underline'
224+
>
225+
Community Guidelines
226+
</Link>
227+
<FontAwesomeIcon
228+
className='text-blue-400 ml-1 mr-1'
229+
size='xs'
230+
icon={faExternalLink}
231+
/>{' '}
232+
before sharing your profile. We want to ensure a safe and positive
233+
environment for all users.
234+
</p>
235+
</div>
236+
<div className='flex items-center gap-8'>
237+
<Image
238+
src={profileImage}
239+
alt={`Profile picture of ${username}`}
240+
className='w-32 h-32 rounded-full'
241+
width={128}
242+
height={128}
243+
/>
244+
<div>
245+
{/* Display name */}
246+
<div className='flex items-center gap-8'>
247+
<h1 className='text-3xl font-bold mb-1 relative'>
248+
Editing {username}&apos;s profile
249+
</h1>
250+
<EarlySupporterBadge />
251+
</div>
252+
</div>
253+
</div>
214254
<form
215255
className={`flex flex-col gap-6`}
216256
onSubmit={formMethods.handleSubmit(() => {
217257
// Handle form submission
218258
console.log('Form submitted');
219259
})}
220260
>
221-
<div className='flex items-center justify-center gap-2 my-3 bg-cyan-800 border-cyan-400 text-cyan-300 border-2 rounded-lg px-3 py-2 text-sm'>
222-
<FontAwesomeIcon icon={faExclamationCircle} className='h-5' />
223-
<p>
224-
Please make sure to carefully review our{' '}
225-
<Link
226-
href='/guidelines'
227-
target='_blank'
228-
className='text-blue-400 hover:text-blue-300 hover:underline'
229-
>
230-
Community Guidelines
231-
</Link>
232-
<FontAwesomeIcon
233-
className='text-blue-400 ml-1 mr-1'
234-
size='xs'
235-
icon={faExternalLink}
236-
/>{' '}
237-
before sharing your profile. We want to ensure a safe and positive
238-
environment for all users.
239-
</p>
261+
{/* Username */}
262+
<div>
263+
<Input
264+
id='username'
265+
label='Username'
266+
tooltip={
267+
<>
268+
<p>
269+
This is your username. It will be shown on your profile
270+
page, as well in all your songs and comments.
271+
</p>
272+
</>
273+
}
274+
isLoading={isLoading}
275+
disabled={isLocked}
276+
errorMessage={errors.username?.message}
277+
{...register('username')}
278+
/>
240279
</div>
241280
{/* Description */}
242281
<div>
@@ -264,9 +303,9 @@ export const UserEditProfile: React.FC<UserEditProfileProps> = ({
264303
Add links to your social media profiles. These links will be shown
265304
on your profile page.
266305
</p>
267-
<div className='flex-row gap-4 mt-2'>
306+
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4 mt-2'>
268307
{LinkFields.map((link) => (
269-
<div key={link.key} className='flex-1 min-w-[200px]'>
308+
<div key={link.key} className='min-w-[200px]'>
270309
<Input
271310
id={link.key}
272311
label={link.label}

0 commit comments

Comments
 (0)