From a2e054e2cda4544b84bd0384bed6c631988af88a Mon Sep 17 00:00:00 2001 From: Sumit2280 Date: Fri, 24 Oct 2025 15:42:49 +0530 Subject: [PATCH] Admin can add and delete sample recordings when admin clicks on add button it redirects to the recording page. admin can select which recording should be sample recording from his recordings. --- app/src/app/admin/layout.tsx | 3 + app/src/app/layout.tsx | 4 +- app/src/app/transcriptions/page.tsx | 1 + app/src/components/Header.tsx | 4 +- app/src/components/Navigation.tsx | 21 ++++++- app/src/components/TranscriptionCard.tsx | 39 +++++++++++-- app/src/components/TranscriptionItem.tsx | 70 +++++++++++++++++++++--- 7 files changed, 123 insertions(+), 19 deletions(-) diff --git a/app/src/app/admin/layout.tsx b/app/src/app/admin/layout.tsx index 825366f..14ea5d0 100644 --- a/app/src/app/admin/layout.tsx +++ b/app/src/app/admin/layout.tsx @@ -22,6 +22,9 @@ export default async function AdminLayout({ Subscriptions + + Sample Recordings +
{children}
diff --git a/app/src/app/layout.tsx b/app/src/app/layout.tsx index 6200783..8d1e8ff 100644 --- a/app/src/app/layout.tsx +++ b/app/src/app/layout.tsx @@ -6,6 +6,7 @@ import { secondaryFont } from "@/fonts"; import { CookiesProvider } from "next-client-cookies/server"; import Header from "@/components/Header"; import { isSignedIn } from "@/actions/auth"; +import { validateRequest } from "@/auth"; export const metadata: Metadata = { title: "Lingo.ai", @@ -17,6 +18,7 @@ export default async function RootLayout({ children: React.ReactNode; }>) { const isUserSignedIn = await isSignedIn(); + const { user } = await validateRequest(); return ( @@ -24,7 +26,7 @@ export default async function RootLayout({ -
+
{children}
diff --git a/app/src/app/transcriptions/page.tsx b/app/src/app/transcriptions/page.tsx index ea8b40e..0e7c215 100644 --- a/app/src/app/transcriptions/page.tsx +++ b/app/src/app/transcriptions/page.tsx @@ -36,6 +36,7 @@ const page = async () => { ); diff --git a/app/src/components/Header.tsx b/app/src/components/Header.tsx index cceec0e..4ffce5b 100644 --- a/app/src/components/Header.tsx +++ b/app/src/components/Header.tsx @@ -3,12 +3,14 @@ import Navigation from "./Navigation"; type HeaderProps = { isSignedIn: boolean; + userRole: string; }; -const Header = ({ isSignedIn }: HeaderProps) => { +const Header = ({ isSignedIn, userRole }: HeaderProps) => { return ( { +const Navigation = ({ isSignedIn, userRole }: NavigationProps) => { const pathname = usePathname() as string; const router = useRouter(); const [uiState, setUIState] = useState({ @@ -222,7 +223,21 @@ const Navigation = ({ isSignedIn }: NavigationProps) => { )} - {isSignedIn && ( + {isSignedIn && userRole === "ADMIN" && ( + + )} + + {isSignedIn && userRole !== "ADMIN" && ( )} - {pathname !== "/transcriptions" && ( + {pathname !== "/transcriptions" && userRole !== "ADMIN" && ( + + )} ); }; diff --git a/app/src/components/TranscriptionItem.tsx b/app/src/components/TranscriptionItem.tsx index 6d42ed5..317af1a 100644 --- a/app/src/components/TranscriptionItem.tsx +++ b/app/src/components/TranscriptionItem.tsx @@ -14,14 +14,18 @@ import { SelectTrigger, SelectValue, } from "./ui/select"; +import { toast } from "sonner"; +import { API } from "@/lib/axios"; +import { Button } from "./ui/button"; interface TranscriptionItemProps { initialTranscriptionsData: userTranscriptions[]; userId: string | null; + userRole: string | null; } const TranscriptionItem = (props: TranscriptionItemProps) => { - const { initialTranscriptionsData, userId } = props; + const { initialTranscriptionsData, userId, userRole } = props; const [defaultTranscriptionFilter, setDefaultTranscriptionFilter] = useState(userId ? "user" : "true"); @@ -30,7 +34,7 @@ const TranscriptionItem = (props: TranscriptionItemProps) => { ); const [isLoading, setIsLoading] = useState(true); - const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = + const { data, fetchNextPage, hasNextPage, isFetchingNextPage, refetch } = useTranscriptions( initialTranscriptionsData, defaultTranscriptionFilter, @@ -79,6 +83,36 @@ const TranscriptionItem = (props: TranscriptionItemProps) => { (page: { transcriptions: userTranscriptions[] }) => page.transcriptions ) || []; + const handleDeleteRecording = async (recordingId: String) => { + try { + const confirmDelete = confirm( + "Are you sure you want to delete this recording?" + ); + if (!confirmDelete) return; + + await API.delete(`/admin/transcriptions/${recordingId}`); + refetch(); + toast.success("Recording deleted successfully"); + } catch (error) { + console.error("Failed to delete recording:", error); + toast.error("Failed to delete recording"); + } + }; + + const handleMakeDefault = async (recordingId: String) => { + console.log("Make default clicked for recording ID:", recordingId); + // try { + // await API.post(`/admin/transcriptions/${recordingId}/make-default`); + // refetch(); + // toast.success("Recording set as default successfully"); + // } catch (error) { + // console.error("Failed to set recording as default:", error); + // toast.error("Failed to set recording as default"); + // } + }; + + console.log("Filtered Transcriptions:", filteredTranscriptions); + return (
@@ -116,11 +150,23 @@ const TranscriptionItem = (props: TranscriptionItemProps) => {
) : ( <> -
-

Audio Recordings

-

- Manage and play your uploaded audio recordings -

+
+
+

Audio Recordings

+

+ Manage and play your uploaded audio recordings +

+
+
+ {userRole === "ADMIN" && ( + + )} +
@@ -133,12 +179,16 @@ const TranscriptionItem = (props: TranscriptionItemProps) => { + {userRole === "ADMIN" && ( + Sample + )} File Name File Size Language Duration Upload Date + {userRole === "ADMIN" && Actions} @@ -146,7 +196,6 @@ const TranscriptionItem = (props: TranscriptionItemProps) => { handlePlayPause(idx)} onAudioEnd={handleAudioEnd} @@ -155,6 +204,11 @@ const TranscriptionItem = (props: TranscriptionItemProps) => { ? lastItemRef : undefined } + onDelete={() => handleDeleteRecording(transcription.id)} + onToggleDefault={() => + handleMakeDefault(transcription.id) + } + userRole={userRole} /> ))}