Skip to content

Commit

Permalink
feat: add age verification
Browse files Browse the repository at this point in the history
  • Loading branch information
louisjoecodes committed Dec 9, 2024
1 parent 7375fb1 commit 5d233f5
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
"use client";

import { Button } from "@/components/ui/button";
import { Button, buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { Loader2 } from "lucide-react";
import Image from "next/image";
import { useState } from "react";
import { LanguageDropdown, LANGUAGES } from "@/components/language-dropdown";
import Link from "next/link";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
} from "@/components/ui/dialog";

interface CallButtonProps {
status: "disconnected" | "connecting" | "connected" | "disconnecting";
Expand Down Expand Up @@ -35,6 +44,7 @@ export function CallButton({
languages,
}: CallButtonProps) {
const [isCalling, setIsCalling] = useState(false);
const [showAgeModal, setShowAgeModal] = useState(false);
const [ringingPhoneAudio] = useState(() => {
if (typeof Audio !== "undefined") {
const audioInstance = new Audio("/assets/ringing-phone.mp3");
Expand All @@ -49,6 +59,11 @@ export function CallButton({
requestMediaPermissions();
return;
}
setShowAgeModal(true);
};

const handleAgeConfirm = () => {
setShowAgeModal(false);
setIsCalling(true);
ringingPhoneAudio?.play();
setTimeout(() => {
Expand All @@ -57,6 +72,7 @@ export function CallButton({
startCall();
}, RINGING_PHONE_AUDIO_DURATION);
};

return (
<>
{!isCalling && (
Expand Down Expand Up @@ -97,6 +113,23 @@ export function CallButton({
</>
)}
</Button>

{!isCalling && (
<div className={"text-sm"}>
<span className="text-gray-200">Powered by</span>{" "}
<Link
target="_blank"
href="https://elevenlabs.io/conversational-ai"
className={cn(
buttonVariants({ variant: "link" }),
"text-white pl-0"
)}
>
ElevenLabs Conversational AI
</Link>
</div>
)}

{!isCalling && (
<div className={"flex items-center gap-2 text-sm mt-2"}>
<LanguageDropdown
Expand All @@ -117,6 +150,23 @@ export function CallButton({
Enable Video
</Label>
</div>

<Dialog open={showAgeModal} onOpenChange={setShowAgeModal}>
<DialogContent>
<DialogHeader>
<DialogTitle>Age Verification</DialogTitle>
<DialogDescription>
Please confirm that you are 18 years or older to continue.
</DialogDescription>
</DialogHeader>
<DialogFooter className="gap-y-2">
<Button variant="secondary" className="bg-red-800 hover:bg-red-600 text-white mb-2 sm:mb-0" onClick={() => setShowAgeModal(false)}>
Cancel
</Button>
<Button className="bg-green-800 hover:bg-green-600" onClick={handleAgeConfirm}>I confirm I am 18+</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}
122 changes: 122 additions & 0 deletions examples/conversational-ai/talk-to-santa/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"use client"

import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}

0 comments on commit 5d233f5

Please sign in to comment.