Improve admin panel by refining user role checks and API calls
Refactors useAuth hook with type assertion for isAdmin and isSuperAdmin properties. Updates AdminPage component to use type assertion for user's first and last names. Modifies VideoManagement component to use a more robust async query function for fetching videos, including proper JSON parsing. Updates EditVideoDialog component to use a cleaner mutation function for updating video data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 170e18f0-0f13-4eca-8643-546bba1dd8cc Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/170e18f0-0f13-4eca-8643-546bba1dd8cc/e8Bo3CR
This commit is contained in:
parent
18d07fb8eb
commit
a9d7322fa8
BIN
attached_assets/image_1756817485634.png
Normal file
BIN
attached_assets/image_1756817485634.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 KiB |
@ -10,7 +10,7 @@ export function useAuth() {
|
|||||||
user,
|
user,
|
||||||
isLoading,
|
isLoading,
|
||||||
isAuthenticated: !!user,
|
isAuthenticated: !!user,
|
||||||
isAdmin: user?.isAdmin || false,
|
isAdmin: (user as any)?.isAdmin || false,
|
||||||
isSuperAdmin: user?.isSuperAdmin || false,
|
isSuperAdmin: (user as any)?.isSuperAdmin || false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ export default function AdminPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center space-x-4">
|
||||||
<Badge variant="secondary" className="text-sm">
|
<Badge variant="secondary" className="text-sm">
|
||||||
{user?.firstName} {user?.lastName}
|
{(user as any)?.firstName} {(user as any)?.lastName}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@ -127,7 +127,10 @@ function VideoManagement({
|
|||||||
}) {
|
}) {
|
||||||
const { data, isLoading } = useQuery({
|
const { data, isLoading } = useQuery({
|
||||||
queryKey: ["/api/admin/videos", { search, limit: 50 }],
|
queryKey: ["/api/admin/videos", { search, limit: 50 }],
|
||||||
queryFn: () => apiRequest(`/api/admin/videos?limit=50&search=${encodeURIComponent(search)}`),
|
queryFn: async () => {
|
||||||
|
const response = await apiRequest("GET", `/api/admin/videos?limit=50&search=${encodeURIComponent(search)}`);
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@ -215,10 +218,7 @@ function EditVideoDialog({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateMutation = useMutation({
|
const updateMutation = useMutation({
|
||||||
mutationFn: (data: any) => apiRequest(`/api/admin/videos/${video.id}`, {
|
mutationFn: (data: any) => apiRequest("PATCH", `/api/admin/videos/${video.id}`, data),
|
||||||
method: "PATCH",
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
}),
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast({
|
toast({
|
||||||
title: "Success",
|
title: "Success",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user