-
+
{
/>
-
{user.username}
+
+ {user.username}
+
-
+
{followingCount} Following
{followerCount} Followers
-
- {watch('bio') || (
+
+ {watch('bio') ? (
+ {watch('bio')}
+ ) : (
Your bio will appear here.
)}
@@ -141,6 +166,10 @@ const ProfilePage: NextPage = () => {
+ ) : (
+
+
+
)}
>
diff --git a/src/pages/account/index.tsx b/src/pages/users/account/index.tsx
similarity index 96%
rename from src/pages/account/index.tsx
rename to src/pages/users/account/index.tsx
index d5cc046..fe42459 100644
--- a/src/pages/account/index.tsx
+++ b/src/pages/users/account/index.tsx
@@ -11,6 +11,7 @@ import DeleteAccount from '@/components/Account/DeleteAccount';
import accountPageReducer from '@/reducers/accountPageReducer';
import UserAvatar from '@/components/Account/UserAvatar';
import UserPosts from '@/components/Account/UserPosts';
+import UpdateProfileLink from '@/components/Account/UpdateProfileLink';
const AccountPage: NextPage = () => {
const { user } = useContext(UserContext);
@@ -57,6 +58,7 @@ const AccountPage: NextPage = () => {
+
diff --git a/src/requests/Account/sendUpdateProfileRequest.tsx b/src/requests/Account/sendUpdateProfileRequest.tsx
deleted file mode 100644
index 1a6b86b..0000000
--- a/src/requests/Account/sendUpdateProfileRequest.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import { z } from 'zod';
-import UpdateProfileSchema from '@/services/User/schema/UpdateProfileSchema';
-
-const sendUpdateProfileRequest = async (data: z.infer) => {
- if (!(data.userAvatar instanceof FileList)) {
- throw new Error('You must submit this form in a web browser.');
- }
-
- const { bio, userAvatar } = data;
-
- const formData = new FormData();
- if (userAvatar[0]) {
- formData.append('image', userAvatar[0]);
- }
-
- formData.append('bio', bio);
-
- const response = await fetch(`/api/users/profile`, {
- method: 'PUT',
- body: formData,
- });
-
- if (!response.ok) {
- throw new Error('Something went wrong.');
- }
-
- const updatedUser = await response.json();
-
- return updatedUser;
-};
-
-export default sendUpdateProfileRequest;
diff --git a/src/requests/Account/sendUpdateUserAvatarRequest.ts b/src/requests/Account/sendUpdateUserAvatarRequest.ts
new file mode 100644
index 0000000..8ce2c6c
--- /dev/null
+++ b/src/requests/Account/sendUpdateUserAvatarRequest.ts
@@ -0,0 +1,27 @@
+interface UpdateProfileRequestParams {
+ file: File;
+ userId: string;
+}
+
+const sendUpdateUserAvatarRequest = async ({
+ file,
+ userId,
+}: UpdateProfileRequestParams) => {
+ const formData = new FormData();
+ formData.append('file', file);
+
+ const response = await fetch(`/api/users/${userId}/`, {
+ method: 'PUT',
+ body: formData,
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to update profile.');
+ }
+
+ const json = await response.json();
+
+ return json;
+};
+
+export default sendUpdateUserAvatarRequest;
diff --git a/src/requests/Account/sendUpdateUserProfileRequest.ts.ts b/src/requests/Account/sendUpdateUserProfileRequest.ts.ts
new file mode 100644
index 0000000..8d421d6
--- /dev/null
+++ b/src/requests/Account/sendUpdateUserProfileRequest.ts.ts
@@ -0,0 +1,28 @@
+import UpdateProfileSchema from '@/services/User/schema/UpdateProfileSchema';
+import { z } from 'zod';
+
+interface UpdateProfileRequestParams {
+ userId: string;
+ bio: z.infer['bio'];
+}
+
+const sendUpdateUserProfileRequest = async ({
+ bio,
+ userId,
+}: UpdateProfileRequestParams) => {
+ const response = await fetch(`/api/users/${userId}/profile/update-bio`, {
+ method: 'PUT',
+ body: JSON.stringify({ bio }),
+ headers: { 'Content-Type': 'application/json' },
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to update profile.');
+ }
+
+ const json = await response.json();
+
+ return json;
+};
+
+export default sendUpdateUserProfileRequest;
diff --git a/src/services/User/schema/UpdateProfileSchema.tsx b/src/services/User/schema/UpdateProfileSchema.ts
similarity index 82%
rename from src/services/User/schema/UpdateProfileSchema.tsx
rename to src/services/User/schema/UpdateProfileSchema.ts
index 93c3ed0..b8face2 100644
--- a/src/services/User/schema/UpdateProfileSchema.tsx
+++ b/src/services/User/schema/UpdateProfileSchema.ts
@@ -1,14 +1,14 @@
import { z } from 'zod';
const UpdateProfileSchema = z.object({
- bio: z.string().min(1, 'Bio cannot be empty'),
+ bio: z.string(),
userAvatar: z
.instanceof(typeof FileList !== 'undefined' ? FileList : Object)
.refine((fileList) => fileList instanceof FileList, {
message: 'You must submit this form in a web browser.',
})
- .refine((fileList) => [...(fileList as FileList)].length === 1, {
- message: 'You must upload one file.',
+ .refine((fileList) => [...(fileList as FileList)].length <= 1, {
+ message: 'You must upload only one or zero files.',
})
.refine(
(fileList) =>