import React, { useState } from 'react'; import { InputText } from 'primereact/inputtext'; import { InputNumber } from 'primereact/inputnumber'; import { InputSwitch } from 'primereact/inputswitch'; import { Button } from 'primereact/button'; import 'primeicons/primeicons.css'; const WorkshopForm = () => { const [title, setTitle] = useState(''); const [summary, setSummary] = useState(''); const [checked, setChecked] = useState(false); const [price, setPrice] = useState(0); const [videoUrl, setVideoUrl] = useState(''); const [topics, setTopics] = useState(['']); const handleSubmit = (e) => { e.preventDefault(); let embedCode = ''; // Check if it's a YouTube video if (videoUrl.includes('youtube.com') || videoUrl.includes('youtu.be')) { const videoId = videoUrl.split('v=')[1] || videoUrl.split('/').pop(); embedCode = ``; } // Check if it's a Vimeo video else if (videoUrl.includes('vimeo.com')) { const videoId = videoUrl.split('/').pop(); embedCode = ``; } // Add more conditions here for other video services const payload = { title, summary, isPaidResource: checked, price: checked ? price : null, videoUrl, topics: topics.map(topic => topic.trim().toLowerCase()) // Include topics in the payload }; console.log(payload); }; const handleTopicChange = (index, value) => { const updatedTopics = topics.map((topic, i) => i === index ? value : topic); setTopics(updatedTopics); }; const addTopic = () => { setTopics([...topics, '']); // Add an empty string to the topics array }; const removeTopic = (index) => { const updatedTopics = topics.filter((_, i) => i !== index); setTopics(updatedTopics); }; return (
); } export default WorkshopForm;