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

Function handleSubmit

client/src/component/AddProject.jsx:23–65  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

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
64 }
65 };
66
67 // Function to modify YouTube link (from watch to embed URL)
68 const modifyYouTubeLink = (link) => {

Callers

nothing calls this directly

Calls 2

addProjectFunction · 0.85
modifyYouTubeLinkFunction · 0.70

Tested by

no test coverage detected