|
@@ -1,6 +1,8 @@
|
|
|
|
|
+import { useState } from 'react'
|
|
|
import { DotsHorizontalIcon } from '@radix-ui/react-icons'
|
|
import { DotsHorizontalIcon } from '@radix-ui/react-icons'
|
|
|
import { type Row } from '@tanstack/react-table'
|
|
import { type Row } from '@tanstack/react-table'
|
|
|
-import { CircleCheck, Eye, Pencil, RefreshCcw } from 'lucide-react'
|
|
|
|
|
|
|
+import { CircleCheck, Download, Eye, Pencil, RefreshCcw } from 'lucide-react'
|
|
|
|
|
+import { toast } from 'sonner'
|
|
|
import { Button } from '@/components/ui/button'
|
|
import { Button } from '@/components/ui/button'
|
|
|
import {
|
|
import {
|
|
|
DropdownMenu,
|
|
DropdownMenu,
|
|
@@ -10,8 +12,10 @@ import {
|
|
|
DropdownMenuTrigger,
|
|
DropdownMenuTrigger,
|
|
|
} from '@/components/ui/dropdown-menu'
|
|
} from '@/components/ui/dropdown-menu'
|
|
|
|
|
|
|
|
|
|
+import { evaluationsService } from '@/services/evaluations.service'
|
|
|
import { type Evaluation } from '@/types/evaluations.types'
|
|
import { type Evaluation } from '@/types/evaluations.types'
|
|
|
import { useEvaluations } from './evaluations-provider'
|
|
import { useEvaluations } from './evaluations-provider'
|
|
|
|
|
+import { downloadFromUrl } from '@/lib/downloadFromUrl'
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
row: Row<Evaluation>
|
|
row: Row<Evaluation>
|
|
@@ -19,6 +23,7 @@ interface Props {
|
|
|
|
|
|
|
|
export function DataTableRowActions({ row }: Props) {
|
|
export function DataTableRowActions({ row }: Props) {
|
|
|
const { setOpen, setCurrentRow } = useEvaluations()
|
|
const { setOpen, setCurrentRow } = useEvaluations()
|
|
|
|
|
+ const [isDownloading, setIsDownloading] = useState(false)
|
|
|
|
|
|
|
|
const evaluations = row.original
|
|
const evaluations = row.original
|
|
|
|
|
|
|
@@ -42,6 +47,35 @@ export function DataTableRowActions({ row }: Props) {
|
|
|
setOpen('edit')
|
|
setOpen('edit')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const handleDownloadVideo = async () => {
|
|
|
|
|
+ setIsDownloading(true)
|
|
|
|
|
+ const toastId = toast.loading('در حال دانلود ویدیو...')
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ let media = evaluations.media?.[0]
|
|
|
|
|
+
|
|
|
|
|
+ if (!media?.url) {
|
|
|
|
|
+ const detail = await evaluationsService.detail(evaluations.id)
|
|
|
|
|
+ media = detail?.media?.[0]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!media?.url) {
|
|
|
|
|
+ toast.error('ویدیویی برای دانلود یافت نشد.', { id: toastId })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const filename =
|
|
|
|
|
+ media.name || `evaluation-${evaluations.id}.${media.extension || 'mp4'}`
|
|
|
|
|
+
|
|
|
|
|
+ await downloadFromUrl(media.url, filename)
|
|
|
|
|
+ toast.success('دانلود ویدیو شروع شد.', { id: toastId })
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ toast.error('خطا در دانلود ویدیو!', { id: toastId })
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setIsDownloading(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<DropdownMenu>
|
|
<DropdownMenu>
|
|
|
<DropdownMenuTrigger asChild>
|
|
<DropdownMenuTrigger asChild>
|
|
@@ -68,6 +102,16 @@ export function DataTableRowActions({ row }: Props) {
|
|
|
</DropdownMenuShortcut>
|
|
</DropdownMenuShortcut>
|
|
|
</DropdownMenuItem>
|
|
</DropdownMenuItem>
|
|
|
|
|
|
|
|
|
|
+ <DropdownMenuItem
|
|
|
|
|
+ onClick={handleDownloadVideo}
|
|
|
|
|
+ disabled={isDownloading}
|
|
|
|
|
+ >
|
|
|
|
|
+ دانلود ویدیو
|
|
|
|
|
+ <DropdownMenuShortcut>
|
|
|
|
|
+ <Download size={16} />
|
|
|
|
|
+ </DropdownMenuShortcut>
|
|
|
|
|
+ </DropdownMenuItem>
|
|
|
|
|
+
|
|
|
<DropdownMenuItem
|
|
<DropdownMenuItem
|
|
|
onClick={handleShowConfirmApprove}
|
|
onClick={handleShowConfirmApprove}
|
|
|
disabled={evaluations?.status !== 'approved_ai'}
|
|
disabled={evaluations?.status !== 'approved_ai'}
|