From 03c05dfddd4fc55b479aeffb8e951e3d695e4e74 Mon Sep 17 00:00:00 2001 From: josetano2 Date: Fri, 23 Aug 2024 01:45:31 +0700 Subject: [PATCH] feat: small fix --- src/config/cloudinary.js | 52 ++++++++----------- .../src/components/ProfileSidebar.jsx | 24 +++++++-- .../src/pages/ProfileDetailPage.jsx | 6 ++- src/ss_frontend/src/pages/ProfilePage.jsx | 10 ---- 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/config/cloudinary.js b/src/config/cloudinary.js index b69f134..341036e 100644 --- a/src/config/cloudinary.js +++ b/src/config/cloudinary.js @@ -1,37 +1,27 @@ import { Cloudinary } from "@cloudinary/url-gen"; -export const cld = new Cloudinary({ cloud: { cloudName: "djg4ybxvx" } }); +export const cld = new Cloudinary({ cloud: { cloudName: "dau03r7yn" } }); -export async function uploadImage(file, onLoading) { - onLoading(true); - const formData = new FormData(); - formData.append("file", file); - formData.append("upload_preset", "c9digoqw"); - - // const response = await fetch( - // `https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`, - // { - // method: "POST", - // body: formData, - // } - // ); +export async function uploadImage({ file, onLoading }) { + onLoading(true); + const formData = new FormData(); + formData.append("file", file); + formData.append("upload_preset", "cdlo4fjr"); - // if (response.ok) { - // const data = await response.json(); - // onLoading(false); - // return data.secure_url; - // } else { - // onLoading(false); - // throw new Error("Upload failed"); - // } - try { - const response = await axios.post( - `https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`, // replace with your cloud_name - formData - ); - console.log(response.data); - return response.data.secure_url; - } catch (error) { - console.error(error); + const response = await fetch( + `https://api.cloudinary.com/v1_1/dau03r7yn/image/upload`, + { + method: "POST", + body: formData, } + ); + + if (response.ok) { + const data = await response.json(); + onLoading(false); + return data.secure_url; + } else { + onLoading(false); + throw new Error("Upload failed"); + } } diff --git a/src/ss_frontend/src/components/ProfileSidebar.jsx b/src/ss_frontend/src/components/ProfileSidebar.jsx index 597104f..fcfd7ec 100644 --- a/src/ss_frontend/src/components/ProfileSidebar.jsx +++ b/src/ss_frontend/src/components/ProfileSidebar.jsx @@ -1,8 +1,13 @@ -import React from "react"; +import React, { useEffect } from "react"; import { AiOutlineUser } from "react-icons/ai"; -import { Link } from "react-router-dom"; +import { Link, useNavigate } from "react-router-dom"; +import { useAuth } from "../hooks/UseAuth"; +import { useQuery } from "@tanstack/react-query"; const ProfileSidebar = () => { + const { isAuthenticated, getUser, user } = useAuth(); + const navigate = useNavigate(); + return ( <>
@@ -11,9 +16,18 @@ const ProfileSidebar = () => {

You haven't logged in yet

- - Login using internet identity - + {isAuthenticated ? ( + <> +
tes
+ + ) : ( + + Login using internet identity + + )}
diff --git a/src/ss_frontend/src/pages/ProfileDetailPage.jsx b/src/ss_frontend/src/pages/ProfileDetailPage.jsx index e4b3a00..8b34bff 100644 --- a/src/ss_frontend/src/pages/ProfileDetailPage.jsx +++ b/src/ss_frontend/src/pages/ProfileDetailPage.jsx @@ -16,10 +16,12 @@ export default function ProfileDetailPage() { if (!isLoading) { if (data.ok) { setUsername(data.ok.username); + } else { + navigate(`/profile-form`); } } }, [data, isLoading]); - + // masukin post - return
{username}
; + return
{username}
; } diff --git a/src/ss_frontend/src/pages/ProfilePage.jsx b/src/ss_frontend/src/pages/ProfilePage.jsx index d0bb35c..7fbc595 100644 --- a/src/ss_frontend/src/pages/ProfilePage.jsx +++ b/src/ss_frontend/src/pages/ProfilePage.jsx @@ -17,16 +17,6 @@ export default function ProfilePage() { queryFn: getUser, }); - useEffect(() => { - if (!isLoading) { - if (data.ok) { - navigate(`/profile`); - } else { - navigate(`/profile-form`); - } - } - }, [data, isLoading]); - return ( <>