feat: delete lesson videos from Bunny
This commit is contained in:
@@ -93,6 +93,7 @@ const CourseModal: React.FC<{
|
||||
const [bunnyConfigured, setBunnyConfigured] = useState<boolean | null>(null);
|
||||
const [bunnyUploadState, setBunnyUploadState] = useState<'idle' | 'uploading' | 'uploaded' | 'error'>('idle');
|
||||
const [bunnyUploadMessage, setBunnyUploadMessage] = useState('');
|
||||
const [deletingVideoId, setDeletingVideoId] = useState<string | null>(null);
|
||||
|
||||
// Tips & Global Attachments
|
||||
const [tips, setTips] = useState<string[]>([]);
|
||||
@@ -340,8 +341,26 @@ const CourseModal: React.FC<{
|
||||
setBunnyUploadMessage('');
|
||||
};
|
||||
|
||||
const removeLesson = (id: string) => {
|
||||
setLessons(lessons.filter(l => l.id !== id));
|
||||
const removeLesson = async (lesson: Lesson) => {
|
||||
const video = lesson.media?.find((media) => media.provider === 'bunny');
|
||||
const message = video
|
||||
? 'Excluir esta aula e o vídeo enviado? O vídeo será removido permanentemente e esta ação não poderá ser desfeita.'
|
||||
: 'Excluir esta aula? Esta ação não poderá ser desfeita após salvar o curso.';
|
||||
if (!window.confirm(message)) return;
|
||||
|
||||
if (video) {
|
||||
setDeletingVideoId(video.externalId);
|
||||
try {
|
||||
await instructorApi.deleteBunnyVideo(video.externalId);
|
||||
} catch (error) {
|
||||
alert(error instanceof Error ? error.message : 'Não foi possível excluir o vídeo. Tente novamente.');
|
||||
return;
|
||||
} finally {
|
||||
setDeletingVideoId(null);
|
||||
}
|
||||
}
|
||||
|
||||
setLessons((current) => current.filter((item) => item.id !== lesson.id));
|
||||
};
|
||||
|
||||
const toggleLessonAccess = (id: string) => {
|
||||
@@ -778,10 +797,12 @@ const CourseModal: React.FC<{
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeLesson(lesson.id)}
|
||||
className="p-1.5 text-gray-400 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-colors"
|
||||
disabled={Boolean(lesson.media?.[0]?.provider === 'bunny' && deletingVideoId === lesson.media[0].externalId)}
|
||||
onClick={() => void removeLesson(lesson)}
|
||||
className="p-1.5 text-gray-400 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
||||
title="Excluir aula e vídeo"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
{lesson.media?.[0]?.provider === 'bunny' && deletingVideoId === lesson.media[0].externalId ? <Loader2 className="w-4 h-4 animate-spin" /> : <Trash2 className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user