MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / AddProject

Function AddProject

client/src/component/AddProject.jsx:6–186  ·  view source on GitHub ↗
({ mode })

Source from the content-addressed store, hash-verified

4import { toast } from 'react-toastify';
5
6function AddProject({ mode }) {
7 const [isModalOpen, setIsModalOpen] = useState(false);
8 const [isLoading, setIsLoading] = useState(false);
9
10 const context = useContext(projectContext);
11 const { addProject } = context;
12
13 // Separate state for each input
14 const [title, setTitle] = useState("");
15 const [description, setDescription] = useState("");
16 const [gitHubLink, setGitHubLink] = useState("");
17 const [youTubeLink, setYouTubeLink] = useState("");
18 const [tags, setTags] = useState("");
19
20 const refClose = useRef(null);
21
22 // Handle form submission
23 const handleSubmit = async (e) => {
24 e.preventDefault(); // Prevent default form submission
25 setIsLoading(true);
26 try {
27 if (title.trim() === "") {
28 toast.error("Title is required");
29 return;
30 }
31
32 // Validate GitHub Link
33 if (gitHubLink && !/^https:\/\/github\.com\//.test(gitHubLink)) {
34 toast.error("Please enter a valid GitHub URL.");
35 return;
36 }
37
38 // Validate YouTube Link
39 if (youTubeLink && !/^https:\/\/(www\.)?youtube\.com\/watch\?v=/.test(youTubeLink)) {
40 toast.error("Please enter a valid YouTube URL.");
41 return;
42 }
43
44 // Modify YouTube link to embed format
45 const modifiedYouTubeLink = modifyYouTubeLink(youTubeLink);
46
47 // Call addProject function from context
48 await addProject(title, description, gitHubLink, modifiedYouTubeLink, tags);
49 toast.success("Project Added Successfully");
50 // console.log(title + " " + description + " " + gitHubLink + " " + youTubeLink)
51 // Clear form
52 setTitle("");
53 setDescription("");
54 setGitHubLink("");
55 setYouTubeLink("");
56 setTags("");
57
58 // Close modal
59 refClose.current.click();
60 } catch (error) {
61 toast.error("Failed to upload the project. Please try again.");
62 } finally {
63 setIsLoading(false); // End loading state

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected