diff --git a/next.config.ts b/next.config.ts
index e0c829f..1be8d48 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -7,6 +7,14 @@ const nextConfig: NextConfig = {
protocol: "https",
hostname: "**",
},
+ ...(process.env.NEXT_PUBLIC_MODE === "DEV"
+ ? [
+ {
+ protocol: "http" as "http",
+ hostname: "localhost",
+ },
+ ]
+ : []),
],
},
};
diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx
index b7ff2f2..517600f 100644
--- a/src/app/settings/page.tsx
+++ b/src/app/settings/page.tsx
@@ -4,7 +4,7 @@ import Editor from "@/components/editor";
import sanitizeHtml from "sanitize-html";
import { getCookie, hasCookie } from "@/helpers/cookie";
import { UserType } from "@/types/UserType";
-import { Avatar, Button, Form, Input } from "@nextui-org/react";
+import { Avatar, Button, Form, Input, Spacer } from "@nextui-org/react";
import { redirect, usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { toast } from "react-toastify";
@@ -13,9 +13,9 @@ import Image from "next/image";
export default function UserPage() {
const [user, setUser] = useState();
- const [profilePicture, setProfilePicture] = useState("");
+ const [profilePicture, setProfilePicture] = useState(null);
const [name, setName] = useState("");
- const [bannerPicture, setBannerPicture] = useState("");
+ const [bannerPicture, setBannerPicture] = useState(null);
const [bio, setBio] = useState("");
const [errors] = useState({});
const pathname = usePathname();
@@ -104,7 +104,7 @@ export default function UserPage() {
if (response.ok) {
toast.success("Changed settings");
- setUser(await response.json());
+ setUser((await response.json()).data);
setWaitingSave(false);
} else {
toast.error("Failed to update settings");
@@ -127,31 +127,104 @@ export default function UserPage() {
Bio
- Profile Picture
+ {
+ const file = e.target.files?.[0];
+ if (!file) return;
+
+ const formData = new FormData();
+ formData.append("upload", file);
+
+ try {
+ const response = await fetch(
+ process.env.NEXT_PUBLIC_MODE === "PROD"
+ ? "https://d2jam.com/api/v1/image"
+ : "http://localhost:3005/api/v1/image",
+ {
+ method: "POST",
+ body: formData,
+ headers: {
+ authorization: `Bearer ${getCookie("token")}`,
+ },
+ credentials: "include",
+ }
+ );
+
+ if (response.ok) {
+ const data = await response.json();
+ setProfilePicture(data.data);
+ toast.success(data.message);
+ } else {
+ toast.error("Failed to upload image");
+ }
+ } catch (error) {
+ console.error(error);
+ toast.error("Error uploading image");
+ }
+ }}
/>
- {profilePicture && }
+ {profilePicture && (
+
+
+
+
+
+ )}
- Banner Image
+ {
+ const file = e.target.files?.[0];
+ if (!file) return;
+
+ const formData = new FormData();
+ formData.append("upload", file);
+
+ try {
+ const response = await fetch(
+ process.env.NEXT_PUBLIC_MODE === "PROD"
+ ? "https://d2jam.com/api/v1/image"
+ : "http://localhost:3005/api/v1/image",
+ {
+ method: "POST",
+ body: formData,
+ headers: {
+ authorization: `Bearer ${getCookie("token")}`,
+ },
+ credentials: "include",
+ }
+ );
+
+ if (response.ok) {
+ const data = await response.json();
+ setBannerPicture(data.data);
+ toast.success(data.message);
+ } else {
+ toast.error("Failed to upload image");
+ }
+ } catch (error) {
+ console.error(error);
+ toast.error("Error uploading image");
+ }
+ }}
/>
- {bannerPicture &&
- bannerPicture.startsWith("https://") &&
- bannerPicture.length > 8 && (
+ {bannerPicture && (
+
- )}
+
+
+
+ )}