Fix webinar join logic to use event_start + duration
Users can now join webinar even if it's already started: - isWebinarJoinable(): returns true if current time <= event_start + duration - isWebinarEnded(): returns true if current time > event_start + duration - "Gabung Webinar" button shows as long as webinar hasn't ended - This allows latecomers to join immediately Previously used only event_start which prevented joining after start time. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -196,6 +196,17 @@ export default function ProductDetail() {
|
|||||||
return new Date() > eventEnd;
|
return new Date() > eventEnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check if webinar is currently running or about to start (can join)
|
||||||
|
const isWebinarJoinable = () => {
|
||||||
|
if (!product || product.type !== 'webinar' || !product.event_start) return false;
|
||||||
|
const eventStart = new Date(product.event_start);
|
||||||
|
const durationMs = (product.duration_minutes || 60) * 60 * 1000;
|
||||||
|
const eventEnd = new Date(eventStart.getTime() + durationMs);
|
||||||
|
const now = new Date();
|
||||||
|
// Can join if webinar hasn't ended yet (even if it's already started)
|
||||||
|
return now <= eventEnd;
|
||||||
|
};
|
||||||
|
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = () => {
|
||||||
if (!product) return;
|
if (!product) return;
|
||||||
addItem({ id: product.id, title: product.title, price: product.price, sale_price: product.sale_price, type: product.type });
|
addItem({ id: product.id, title: product.title, price: product.price, sale_price: product.sale_price, type: product.type });
|
||||||
@@ -254,9 +265,6 @@ export default function ProductDetail() {
|
|||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
case 'webinar':
|
case 'webinar':
|
||||||
// Check if webinar has ended
|
|
||||||
const webinarEnded = product.event_start && new Date(product.event_start) <= new Date();
|
|
||||||
|
|
||||||
if (product.recording_url) {
|
if (product.recording_url) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
@@ -278,8 +286,8 @@ export default function ProductDetail() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show "Gabung Webinar" if webinar hasn't ended and has meeting link
|
// Show "Gabung Webinar" if webinar hasn't ended yet (can join even if already started)
|
||||||
if (!webinarEnded && product.meeting_link) {
|
if (isWebinarJoinable() && product.meeting_link) {
|
||||||
return (
|
return (
|
||||||
<Button asChild size="lg" className="shadow-sm">
|
<Button asChild size="lg" className="shadow-sm">
|
||||||
<a href={product.meeting_link} target="_blank" rel="noopener noreferrer">
|
<a href={product.meeting_link} target="_blank" rel="noopener noreferrer">
|
||||||
@@ -291,7 +299,7 @@ export default function ProductDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Webinar has ended but no recording yet
|
// Webinar has ended but no recording yet
|
||||||
if (webinarEnded) {
|
if (isWebinarEnded()) {
|
||||||
return <Badge className="bg-muted text-primary">Rekaman segera tersedia</Badge>;
|
return <Badge className="bg-muted text-primary">Rekaman segera tersedia</Badge>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user