Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fixed form Handling of products #86

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions client/src/pages/Product/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ import { useLocation } from "react-router-dom";
const Product = () => {
const { shoeImage, shoeName, brand, pId, price } = useLocation().state;

const [formData, setFormData] = React.useState();
const [shoeSize, setShoeSize] = React.useState();

function handleChange(event) {
setFormData(parseInt(event.target.innerText));
setShoeSize(parseInt(event.target.innerText));
}
async function handleSubmit(event) {
event.preventDefault();
if(!shoeSize){
toast.error("Select Shoe size ")
return
}
try {
const { data } = await axios.post(
"http://localhost:3000/api/cart/add",
{
pId,
price,
size: formData,
size: shoeSize,
},
{
headers: {
Expand All @@ -28,11 +32,23 @@ const Product = () => {
withCredentials: true,
}
);
toast(data.message);
window.location.href = "/";
if(data.success){

toast.success(data.message);
setTimeout(() => {
window.location.href = "/";
}, 2000);
}
else
{
toast.error(data.message);
setTimeout(() => {
window.location.href = "/signup";
}, 2000);
}
} catch (error) {
toast.error(error.response.data.message);
// console.error(error);

}
}
return (
Expand Down Expand Up @@ -105,39 +121,39 @@ const Product = () => {
<div className="flex items-center mt-2 mb-5">
<button
type="button"
className="bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600"
className={`${shoeSize === 7 ? 'bg-blue-500 text-white' : ''}bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600`}
name="size"
onClick={handleChange}
>
7
</button>
<button
type="button"
className="bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600 "
className={`${shoeSize === 8 ? 'bg-blue-500 text-white' : ''}bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600 `}
name="size"
onClick={handleChange}
>
8
</button>
<button
type="button"
className="bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600"
className={`${shoeSize === 9 ? 'bg-blue-500 text-white' : ''}bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600`}
name="size"
onClick={handleChange}
>
9
</button>
<button
type="button"
className="bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600"
className={`${shoeSize === 10 ? 'bg-blue-500 text-white' : ''}bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600`}
name="size"
onClick={handleChange}
>
10
</button>
<button
type="button"
className="bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600"
className={`${shoeSize === 11 ? 'bg-blue-500 text-white' : ''}bg-gray-300 darkk:bg-gray-700 text-gray-700 darkk:text-white py-2 px-4 rounded-full font-bold mr-2 hover:bg-gray-400 darkk:hover:bg-gray-600`}
name="size"
onClick={handleChange}
>
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { con } from "../app.js";
export const isAuthenticated = async (req, res, next) => {
const { jjtoken } = req.cookies;
if (!jjtoken) {
return res.status(404).json({
return res.status(200).json({
success: false,
message: "Login First",
});
Expand Down
Loading