Skip to content

Commit

Permalink
Merge pull request #825 from bounswe/bugfix/728/redirecting-game-afte…
Browse files Browse the repository at this point in the history
…r-create

page refreshed after navigating
  • Loading branch information
yunusemrealtug authored Dec 25, 2023
2 parents f0ef716 + e486a9f commit 7ca0415
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ludos/frontend/src/components/CreateGameForum.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ const CreateGameForm = (formComp) => {
// Add more platforms as needed
];
const [currentStep, setCurrentStep] = useState(1);
const [releaseDateGiven, setReleaseDateGiven] = useState(false);
const totalSteps = 4;

useEffect(() => {
if (formComp.formData !== null) {
setFormData(formComp.formData);
setIsTagSelected(formComp.formData.tags.length > 0);
setReleaseDateGiven(formComp.formData.releaseDate != "");
}
}, []);

Expand Down Expand Up @@ -210,6 +212,9 @@ const CreateGameForm = (formComp) => {
...prevData,
[name]: parsedValue,
}));
if (name === "releaseDate") {
setReleaseDateGiven(!!value); // Set releaseDateGiven to true if value is not empty
}
}
};

Expand Down Expand Up @@ -257,6 +262,17 @@ const CreateGameForm = (formComp) => {
});
return; // Prevent form submission
}
if (!releaseDateGiven) {
toast.error("Please give a release date", {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
});
return; // Prevent form submission
}

if (formComp.formData !== null) {
const apiUrl = `http://${process.env.REACT_APP_API_URL}/game/${formComp.formData.id}/edit`;
Expand All @@ -277,6 +293,7 @@ const CreateGameForm = (formComp) => {
pauseOnHover: true,
draggable: true,
});

console.log("Game edited successfully:", response.data);
navigate(`/game/${convertToSlug(formData.title)}`);
})
Expand Down Expand Up @@ -311,8 +328,10 @@ const CreateGameForm = (formComp) => {
pauseOnHover: true,
draggable: true,
});

console.log("Game created successfully:", response.data);
navigate(`/game/${convertToSlug(formData.title)}`);
window.location.reload();
})
.catch((error) => {
// Error creating game
Expand Down Expand Up @@ -455,6 +474,7 @@ const CreateGameForm = (formComp) => {
type="date"
value={formData.releaseDate}
onChange={handleInputChange}
required
fullWidth
/>
<TextField
Expand Down

0 comments on commit 7ca0415

Please sign in to comment.