Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ozzydogandev committed Jan 21, 2025
1 parent 8de8d71 commit 0fbcd28
Showing 1 changed file with 21 additions and 38 deletions.
59 changes: 21 additions & 38 deletions src/views/ShareAProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ const ShareAProject = () => {
youtube_video_link: "",
tags: [],
});
const [errors, setErrors] = useState({
github_link: "",
youtube_video_link: "",
});

const validateUrl = (url) => {
const urlPattern = /^(https?:\/\/)?([\w-]+(\.[\w-]+)+)(\/[\w-.]*)*(\?.+)?$/;
return urlPattern.test(url);
};

const handleSubmit = async (e) => {
e.preventDefault();
if (newProject.tags.length === 0) {
Expand All @@ -43,51 +40,38 @@ const ShareAProject = () => {
label: "x",
},
});
//console.log("Please select at least one framework/language.");
return;
}
const newErrors = {};

// Validate GitHub URL (Required)
if (!newProject.github_link || !validateUrl(newProject.github_link)) {
newErrors.github_link = "Please provide a valid GitHub repository URL.";
toaster.create({
title: "Please provide a valid GitHub repository URL.",
type: "warning",
duration: 4000,
action: {
label: "x",
},
});
return;
}

// Validate Live Demo URL (Optional, only if provided)
if (
newProject.youtube_video_link &&
!validateUrl(newProject.youtube_video_link)
) {
newErrors.youtube_video_link = "Please provide a valid Live Demo URL.";
}
console.log(Object.keys(newErrors).length);
if (Object.keys(newErrors).length > 0) {
setErrors(newErrors); // Display errors

if (newErrors.github_link) {
console.log(newErrors.github_link);
toaster.create({
title: newErrors.github_link,
type: "warning",
duration: 4000,
action: {
label: "x",
},
});
}
if (newErrors.youtube_video_link) {
console.log(newErrors.youtube_video_link);
toaster.create({
title: newErrors.youtube_video_link,
type: "warning",
duration: 4000,
action: {
label: "x",
},
});
}
toaster.create({
title: "Please provide a valid Live Demo URL.",
type: "warning",
duration: 4000,
action: {
label: "x",
},
});
return;
}

try {
const response = await fetch("http://localhost:8001/api/v1/addProject", {
method: "POST",
Expand All @@ -99,7 +83,7 @@ const ShareAProject = () => {
});
if (response.ok) {
toaster.create({
title: "Project submitted succesfully!",
title: "Project submitted successfully!",
type: "success",
duration: 8000,
action: {
Expand All @@ -115,7 +99,6 @@ const ShareAProject = () => {
});
} else {
console.error("Failed to add project:", response.statusText);
//console.error("Failed to submit project");
}
} catch (error) {
toaster.create({
Expand All @@ -137,7 +120,7 @@ const ShareAProject = () => {
: [...prev.tags, value],
}));
};
//const isSubmitEnabled = newProject.tags.length > 0;

return (
<form onSubmit={handleSubmit}>
<div className="share-project-container">
Expand Down

0 comments on commit 0fbcd28

Please sign in to comment.