diff --git a/src/app/dashboard/(admin)/admin/(overview)/users/[id]/page.tsx b/src/app/dashboard/(admin)/admin/(overview)/users/[id]/page.tsx index f59951440..fdbb42c12 100644 --- a/src/app/dashboard/(admin)/admin/(overview)/users/[id]/page.tsx +++ b/src/app/dashboard/(admin)/admin/(overview)/users/[id]/page.tsx @@ -2,6 +2,7 @@ import axios from "axios"; import { ChevronLeft, ChevronRight, Star } from "lucide-react"; +import { useSession } from "next-auth/react"; import { useParams } from "next/navigation"; import { useEffect, useState } from "react"; @@ -23,7 +24,8 @@ export interface UserDetailsProperties { email: string; id: string; is_active: boolean; - name: string; + first_name: string; + last_name: string; products: []; created_at: string; } @@ -46,6 +48,7 @@ const UserDetails = () => { const [userData, setUserData] = useState(); const [rating, setRating] = useState(0); const { toast } = useToast(); + const { data: session } = useSession(); const [totalProducts, setTotalProducts] = useState({ title: "Total Products", @@ -74,9 +77,12 @@ const UserDetails = () => { setLoading(true); const baseUrl = await getApiUrl(); const API_URL = `${baseUrl}/api/v1/users/${id}`; - const response = await axios.get(`${API_URL}`); - - const userDetails: UserDetailsProperties = response.data; + const response = await axios.get(`${API_URL}`, { + headers: { + Authorization: `Bearer ${session?.access_token}`, + }, + }); + const userDetails: UserDetailsProperties = response.data.user; setUserData(userDetails); setTotalSales((previous) => ({ ...previous, @@ -103,7 +109,7 @@ const UserDetails = () => { setLoading(false); } })(); - }, [id, toast]); + }, [id, session?.access_token, toast]); const handleRatingClick = (index: number) => { setRating(index); @@ -121,18 +127,19 @@ const UserDetails = () => {
- {userData?.name?.charAt(0).toUpperCase() ?? + {userData?.first_name?.charAt(0).toUpperCase() || userData?.email?.charAt(0).toUpperCase()}
- {userData?.name ? ( - (userData?.name ?? userData?.email) - ) : ( -
- )} + {userData?.first_name || userData?.last_name + ? userData.first_name + " " + userData.last_name + : (userData?.email ?? ( +
+ ))}
+
{userData?.email || (
@@ -163,9 +170,7 @@ const UserDetails = () => { ))}
-
- ({userData?.products.length} products) -
+
(50 products)
Date Added {userData?.created_at ? ( diff --git a/src/app/dashboard/(admin)/admin/(overview)/users/page.tsx b/src/app/dashboard/(admin)/admin/(overview)/users/page.tsx index 064625067..8144482e7 100644 --- a/src/app/dashboard/(admin)/admin/(overview)/users/page.tsx +++ b/src/app/dashboard/(admin)/admin/(overview)/users/page.tsx @@ -23,6 +23,7 @@ import { UserCardData } from "./data/user-dummy-data"; import "./assets/style.css"; import axios from "axios"; +import { getSession } from "next-auth/react"; import { getApiUrl } from "~/actions/getApiUrl"; import { useToast } from "~/components/ui/use-toast"; @@ -73,6 +74,7 @@ const UserPage = () => { const [isDialogOpen, setIsDialogOpen] = useState(false); const { toast } = useToast(); + // const { data: session } = useSession(); const [totalUserOverview, setTotalUserOverview] = useState({ title: "Total Users", @@ -114,16 +116,28 @@ const UserPage = () => { const fetchData = useCallback(async () => { try { + const session = await getSession(); setLoading(true); const baseUrl = await getApiUrl(); const API_URL = `${baseUrl}/api/v1/users`; - const response = await axios.get(`${API_URL}?page=${page}`); - setIsNextPageActive(response.data.data?.next_page_url ? true : false); - setIsPreviousPageActive(response.data.data?.prev_page_url ? true : false); - const usersData: UserData[] = response.data.data.data; + const response = await axios.get(`${API_URL}?page=${page}`, { + headers: { + Authorization: `Bearer ${session?.access_token}`, + }, + }); + setIsNextPageActive( + response.data.data.pagination.current_page === + response.data.data.pagination.last_page + ? false + : true, + ); + setIsPreviousPageActive( + response.data.data.pagination.current_page === 1 ? false : true, + ); + const usersData: UserData[] = response.data.data?.users || []; setData(usersData); setFilterData(usersData); - const totalUser = response.data.data.total; + const totalUser = response.data.data.total || 0; const deletedUser = usersData.filter( (user) => user.deleted_at !== null, ).length;