import { getCoreRowModel, getSortedRowModel, useReactTable, type ColumnDef } from "@tanstack/react-table"; import { useMemo, useState } from "react"; import { DataTableProvider, DataTableWrapper, DataTableToolbar, DataTableFilters, useDataTable, } from "@calcom/features/data-table"; import { useSegments } from "@calcom/features/data-table/hooks/useSegments"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Button } from "@calcom/ui/components/button"; import { Dialog, DialogContent, DialogHeader } from "@calcom/ui/components/dialog"; import { Icon } from "@calcom/ui/components/icon"; import { showToast } from "@calcom/ui/components/toast"; import { useVoicePreview } from "../hooks/useVoicePreview"; type Voice = { voice_id: string; voice_name: string; provider: 'elevenlabs' | 'openai' | 'deepgram'; gender: 'male' | 'female'; accent?: string; age?: string; preview_audio_url?: string; }; type VoiceSelectionDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; selectedVoiceId?: string; onVoiceSelect: (voiceId: string) => void; }; function VoiceSelectionTable({ selectedVoiceId, onVoiceSelect }: { selectedVoiceId?: string; onVoiceSelect: (voiceId: string) => void }) { return ( ); } function VoiceSelectionContent({ selectedVoiceId, onVoiceSelect }: { selectedVoiceId?: string; onVoiceSelect: (voiceId: string) => void }) { const { t } = useLocale(); const { playingVoiceId, handlePlayVoice } = useVoicePreview(); const [rowSelection, setRowSelection] = useState({}); const { data: voices, isLoading } = trpc.viewer.aiVoiceAgent.listVoices.useQuery(); const handleUseVoice = (voiceId: string) => { onVoiceSelect(voiceId); showToast("Voice selected successfully", "success"); }; const voiceData: Voice[] = useMemo(() => { if (!voices) return []; return voices; }, [voices]); const columns = useMemo[]>( () => [ { id: "voice", accessorKey: "voice_name", header: t("voice"), size: 200, cell: ({ row }) => (
{row.original.voice_name}
), }, { id: "trait", accessorKey: "accent", header: t("trait"), size: 200, cell: ({ row }) => (
{row.original.accent && ( {row.original.accent} )} {row.original.gender && ( {row.original.gender} )} {row.original.provider && ( {row.original.provider} )} {row.original.age && ( {row.original.age} )}
), }, { id: "voice_id", accessorKey: "voice_id", header: t("voice_id"), size: 200, cell: ({ row }) => ( {row.original.voice_id} ), }, { id: "actions", header: "", size: 120, cell: ({ row }) => ( ), }, ], [t, playingVoiceId, selectedVoiceId] ); const table = useReactTable({ data: voiceData, columns, enableRowSelection: false, manualPagination: false, state: { rowSelection, }, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), onRowSelectionChange: setRowSelection, getRowId: (row) => row.voice_id, }); return (
testId="voice-selection-data-table" table={table} isPending={isLoading} totalRowCount={voiceData?.length || 0} paginationMode="standard" className="h-auto" />
); } export function VoiceSelectionDialog({ open, onOpenChange, selectedVoiceId, onVoiceSelect, }: VoiceSelectionDialogProps) { const { t } = useLocale(); const handleVoiceSelect = (voiceId: string) => { onVoiceSelect(voiceId); onOpenChange(false); }; return (
); }