import React, { useState, useMemo } from 'react'; import { Button } from './ui/button'; import { Input } from './ui/input'; import { Card, CardContent } from './ui/card'; import { Search } from 'lucide-react'; import CreateFormSection from './CreateFormSection'; // Import icons import { ellipsisIconFigma, formsTutorialBg, formsTutorialOverlay, playIconWhiteFigma, } from '../assets/images'; interface FormData { name: string; date: string; subscribers: number; shortCodeId: number; audience: { main: string; extra: string; }; } const formsData: FormData[] = [ { name: "Subscription Form with GDPR consent", date: "Last edited on 12/03/2025 2:04 PM", subscribers: 10, shortCodeId: 1, audience: { main: "Test, Customers", extra: "+2" } }, { name: "Newsletter Signup", date: "Last edited on 12/03/2025 2:04 PM", subscribers: 15, shortCodeId: 2, audience: { main: "Sample, Squad", extra: "2+" } }, { name: "Minimal subscription form with selection of list", date: "Last edited on 12/03/2025 2:04 PM", subscribers: 20, shortCodeId: 3, audience: { main: "Example, Crew", extra: "3+" } }, { name: "Subscription Form", date: "Last edited on 12/03/2025 2:04 PM", subscribers: 20, shortCodeId: 4, audience: { main: "Demo, Group", extra: "1+" } }, { name: "Subscription Form For Update", date: "Last edited on 12/03/2025 2:04 PM", subscribers: 50, shortCodeId: 5, audience: { main: "Trial, Unit", extra: "0+" } }, { name: "Contact Form with File Upload", date: "Last edited on 11/03/2025 1:30 PM", subscribers: 35, shortCodeId: 6, audience: { main: "Business, Leads", extra: "+5" } }, { name: "Event Registration Form", date: "Last edited on 10/03/2025 3:15 PM", subscribers: 80, shortCodeId: 7, audience: { main: "Events, Users", extra: "+12" } }, { name: "Product Feedback Survey", date: "Last edited on 09/03/2025 11:45 AM", subscribers: 25, shortCodeId: 8, audience: { main: "Feedback, Team", extra: "+3" } }, { name: "Lead Generation Form", date: "Last edited on 08/03/2025 4:20 PM", subscribers: 45, shortCodeId: 9, audience: { main: "Sales, Prospects", extra: "+8" } }, { name: "Email Preferences Update", date: "Last edited on 07/03/2025 9:10 AM", subscribers: 12, shortCodeId: 10, audience: { main: "Settings, Users", extra: "+1" } }, { name: "Multi-step Registration Form", date: "Last edited on 06/03/2025 2:45 PM", subscribers: 60, shortCodeId: 11, audience: { main: "Register, Members", extra: "+15" } }, { name: "Quick Survey Form", date: "Last edited on 05/03/2025 10:30 AM", subscribers: 18, shortCodeId: 12, audience: { main: "Survey, Users", extra: "+2" } }, { name: "Partner Application Form", date: "Last edited on 04/03/2025 1:15 PM", subscribers: 8, shortCodeId: 13, audience: { main: "Partners, Apps", extra: "+0" } }, { name: "Job Application Form", date: "Last edited on 03/03/2025 3:50 PM", subscribers: 22, shortCodeId: 14, audience: { main: "Careers, Team", extra: "+4" } }, { name: "Customer Support Form", date: "Last edited on 02/03/2025 11:20 AM", subscribers: 16, shortCodeId: 15, audience: { main: "Support, Cases", extra: "+1" } }, { name: "Product Demo Request", date: "Last edited on 01/03/2025 4:35 PM", subscribers: 38, shortCodeId: 16, audience: { main: "Demo, Requests", extra: "+6" } }, { name: "Blog Subscription Form", date: "Last edited on 28/02/2025 9:45 AM", subscribers: 55, shortCodeId: 17, audience: { main: "Blog, Readers", extra: "+10" } }, { name: "Webinar Registration", date: "Last edited on 27/02/2025 2:15 PM", subscribers: 42, shortCodeId: 18, audience: { main: "Webinar, Attendees", extra: "+7" } }, { name: "Free Trial Signup", date: "Last edited on 26/02/2025 10:30 AM", subscribers: 68, shortCodeId: 19, audience: { main: "Trial, Users", extra: "+14" } }, { name: "Beta Testing Application", date: "Last edited on 25/02/2025 3:20 PM", subscribers: 29, shortCodeId: 20, audience: { main: "Beta, Testers", extra: "+5" } }, { name: "Affiliate Program Form", date: "Last edited on 24/02/2025 1:10 PM", subscribers: 14, shortCodeId: 21, audience: { main: "Affiliate, Partners", extra: "+2" } }, { name: "Consultation Request", date: "Last edited on 23/02/2025 11:50 AM", subscribers: 31, shortCodeId: 22, audience: { main: "Consultation, Leads", extra: "+4" } }, { name: "Newsletter Unsubscribe", date: "Last edited on 22/02/2025 4:25 PM", subscribers: 7, shortCodeId: 23, audience: { main: "Unsubscribe, Users", extra: "+0" } }, { name: "Custom Quote Request", date: "Last edited on 21/02/2025 9:15 AM", subscribers: 26, shortCodeId: 24, audience: { main: "Quote, Requests", extra: "+3" } }, { name: "Workshop Registration", date: "Last edited on 20/02/2025 2:40 PM", subscribers: 44, shortCodeId: 25, audience: { main: "Workshop, Participants", extra: "+8" } }, ]; const FormList: React.FC = () => { const [searchTerm, setSearchTerm] = useState(''); const [currentPage, setCurrentPage] = useState(1); const [forms, setForms] = useState(formsData); // Use actual forms data const itemsPerPage = 10; // Filter forms based on search term const filteredForms = useMemo(() => { return forms.filter(form => form.name.toLowerCase().includes(searchTerm.toLowerCase()) ); }, [searchTerm, forms]); // Calculate pagination const totalPages = Math.ceil(filteredForms.length / itemsPerPage); const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; const currentForms = filteredForms.slice(startIndex, endIndex); // Reset to first page when search changes const handleSearchChange = (e: React.ChangeEvent) => { setSearchTerm(e.target.value); setCurrentPage(1); }; // Handle clear filters functionality const handleClearFilters = () => { setSearchTerm(''); setCurrentPage(1); }; // Handle delete form functionality const handleDeleteForm = (formIndex: number) => { const globalIndex = startIndex + formIndex; const formToDelete = filteredForms[globalIndex]; // Remove the form from the forms array setForms(prevForms => prevForms.filter(form => form.shortCodeId !== formToDelete.shortCodeId)); // If we're on the last page and it becomes empty, go to previous page const newFilteredCount = filteredForms.length - 1; const newTotalPages = Math.ceil(newFilteredCount / itemsPerPage); if (currentPage > newTotalPages && newTotalPages > 0) { setCurrentPage(newTotalPages); } }; // Handle copy short code functionality const handleCopyShortCode = async (shortCodeId: number) => { const textToCopy = `id="${shortCodeId}"`; try { await navigator.clipboard.writeText(textToCopy); // You could add a toast notification here if desired console.log(`Copied to clipboard: ${textToCopy}`); } catch (err) { // Fallback for older browsers const textArea = document.createElement('textarea'); textArea.value = textToCopy; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { document.execCommand('copy'); console.log(`Copied to clipboard: ${textToCopy}`); } catch (fallbackErr) { console.error('Failed to copy text: ', fallbackErr); } document.body.removeChild(textArea); } }; const handlePageChange = (page: number) => { setCurrentPage(page); }; const handlePreviousPage = () => { if (currentPage > 1) { setCurrentPage(currentPage - 1); } }; const handleNextPage = () => { if (currentPage < totalPages) { setCurrentPage(currentPage + 1); } }; // Generate page numbers for pagination const getPageNumbers = () => { const pages = []; const showPages = 3; // Show 3 page numbers at most if (totalPages <= showPages) { for (let i = 1; i <= totalPages; i++) { pages.push(i); } } else { if (currentPage <= 2) { pages.push(1, 2, 3); } else if (currentPage >= totalPages - 1) { pages.push(totalPages - 2, totalPages - 1, totalPages); } else { pages.push(currentPage - 1, currentPage, currentPage + 1); } } return pages; }; return (
{/* Header Section */}

Forms

Forms are interactive tools that collect user input, helping you capture data, receive feedback, and streamline communication

{/* Start creating forms and How to create Forms sections */}

Start creating forms

{/* Left side - Popular forms grid */}
{/* Right side - How to create Forms tutorial */}
{/* Play Button Overlay */}
Play video

How to create Forms?

Learn how to create, customize, and manage forms effortlessly with our step-by-step tutorials

{/* All Forms Section */}

All Forms

{/* Search and Filters */}
Type: All
Sort: Last edited
{/* Data Table or Empty State */}
{filteredForms.length > 0 ? ( <> {/* Data Table */}
{/* Form Name Column */}
{/* Header */}

Form Name

{/* Form Rows */} {currentForms.map((form, index) => (

{form.name}

{form.date}

))}
{/* Subscribers Column */}

Subscribers

{currentForms.map((form, index) => (

{form.subscribers}

))}
{/* Short Code Column */}

Short Code

{currentForms.map((form, index) => (

{`id="${form.shortCodeId}"`}

handleCopyShortCode(form.shortCodeId)} title={`Copy ${`id="${form.shortCodeId}"`}`} >
))}
{/* Audience Column */}

Audience

{currentForms.map((form, index) => (

{form.audience.main} {form.audience.extra}

))}
{/* Actions Column */}

Actions

{currentForms.map((_, index) => (
handleDeleteForm(index)} >
))}
{/* Pagination - Only show if there are results and multiple pages */} {totalPages > 1 && (
{/* Previous Button */} {/* Page Numbers */} {getPageNumbers().map((pageNum) => ( ))} {/* Ellipsis (show if there are more pages beyond visible range) */} {totalPages > 3 && currentPage < totalPages - 1 && (
)} {/* Next Button */}
)} ) : ( /* Empty State - No Forms data found */

No Forms data found

)}
); }; export default FormList;