Changes
This commit is contained in:
@@ -137,7 +137,7 @@ export default function Bootcamp() {
|
||||
};
|
||||
|
||||
const markAsCompleted = async () => {
|
||||
if (!selectedLesson || !user) return;
|
||||
if (!selectedLesson || !user || !product) return;
|
||||
|
||||
const { error } = await supabase
|
||||
.from('lesson_progress')
|
||||
@@ -152,7 +152,34 @@ export default function Bootcamp() {
|
||||
return;
|
||||
}
|
||||
|
||||
setProgress([...progress, { lesson_id: selectedLesson.id, completed_at: new Date().toISOString() }]);
|
||||
const newProgress = [...progress, { lesson_id: selectedLesson.id, completed_at: new Date().toISOString() }];
|
||||
setProgress(newProgress);
|
||||
|
||||
// Calculate completion percentage for notification
|
||||
const completedCount = newProgress.length;
|
||||
const completionPercent = Math.round((completedCount / totalLessons) * 100);
|
||||
|
||||
// Trigger progress notification at milestones
|
||||
if (completionPercent === 25 || completionPercent === 50 || completionPercent === 75 || completionPercent === 100) {
|
||||
try {
|
||||
await supabase.functions.invoke('send-notification', {
|
||||
body: {
|
||||
template_key: 'bootcamp_progress',
|
||||
recipient_email: user.email,
|
||||
recipient_name: user.user_metadata?.name || 'Peserta',
|
||||
variables: {
|
||||
bootcamp_title: product.title,
|
||||
progress_percent: completionPercent.toString(),
|
||||
completed_lessons: completedCount.toString(),
|
||||
total_lessons: totalLessons.toString(),
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.log('Progress notification skipped:', err);
|
||||
}
|
||||
}
|
||||
|
||||
toast({ title: 'Selesai!', description: 'Pelajaran ditandai selesai' });
|
||||
goToNextLesson();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user