diff --git a/src/pages/Host/Spaces/Add/SpaceDetailsTwo.jsx b/src/pages/Host/Spaces/Add/SpaceDetailsTwo.jsx index 4ed54a1..5a622b1 100644 --- a/src/pages/Host/Spaces/Add/SpaceDetailsTwo.jsx +++ b/src/pages/Host/Spaces/Add/SpaceDetailsTwo.jsx @@ -13,7 +13,12 @@ import MkdSDK from "@/utils/MkdSDK"; import useDelayUnmount from "@/hooks/useDelayUnmount"; import { useContext } from "react"; import { GlobalContext, showToast } from "@/globalContext"; -import { DRAFT_STATUS, IMAGE_STATUS, SPACE_STATUS, SPACE_VISIBILITY } from "@/utils/constants"; +import { + DRAFT_STATUS, + IMAGE_STATUS, + SPACE_STATUS, + SPACE_VISIBILITY, +} from "@/utils/constants"; import { Link } from "react-router-dom"; import CustomSelectV2 from "@/components/CustomSelectV2"; import useCancellation from "@/hooks/api/useCancellation"; @@ -110,17 +115,33 @@ const SpaceDetailsTwo = () => { for (let i = 0; i < pictures.length; i++) { const file = pictures[i]; - const allowedTypes = ['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml']; - if (file?.type && !allowedTypes.includes(file?.type)) { - showToast(globalDispatch, 'Invalid file type. Only JPEG, PNG, WEBP, and SVG are allowed.', 4000, "ERROR"); + const allowedTypes = [ + "image/jpeg", + "image/png", + "image/webp", + "image/svg+xml", + ]; + if (file?.type && !allowedTypes.includes(file?.type)) { + showToast( + globalDispatch, + "Invalid file type. Only JPEG, PNG, WEBP, and SVG are allowed.", + 4000, + "ERROR" + ); return; - } + } + + if (file?.size && file?.size > 5 * 1024 * 1024) { + // 5 MB limit + showToast( + globalDispatch, + "One or more of the image is too large. Max size is 5 MB.", + 4000, + "ERROR" + ); + return; + } - if (file?.size && file?.size > 5 * 1024 * 1024) { // 5 MB limit - showToast(globalDispatch, 'One of the image is too large. Max size is 5 MB.', 4000, "ERROR"); - return; - } - const upload = await handleImageUpload(file); uploadedImages[i] = upload.url; uploadedIds[i] = upload.id; @@ -128,7 +149,16 @@ const SpaceDetailsTwo = () => { dispatch({ type: "SET_THUMBNAIL", payload: upload.id }); } } - dispatch({ type: "SET_DETAILS_TWO", payload: { faqs: data.faqs, amenities: data.amenities, addons: data.addons, pictures: uploadedImages, pictureIds: uploadedIds } }); + dispatch({ + type: "SET_DETAILS_TWO", + payload: { + faqs: data.faqs, + amenities: data.amenities, + addons: data.addons, + pictures: uploadedImages, + pictureIds: uploadedIds, + }, + }); globalDispatch({ type: "STOP_LOADING" }); navigate("/spaces/add/3"); @@ -156,7 +186,7 @@ const SpaceDetailsTwo = () => { name: spaceData.name, rule: spaceData.rule, }, - "POST", + "POST" ); dispatch({ type: "SET_PROPERTY_ID", payload: propertyResult.message }); } @@ -177,7 +207,7 @@ const SpaceDetailsTwo = () => { additional_guest_rate: spaceData.additional_guest_rate || undefined, size: spaceData.size || undefined, }, - "POST", + "POST" ); } @@ -190,7 +220,7 @@ const SpaceDetailsTwo = () => { property_id: propertyResult?.message ?? spaceData.property_id, add_on_id: addon_id, }, - "POST", + "POST" ); } @@ -208,7 +238,7 @@ const SpaceDetailsTwo = () => { photo_id: upload.id, is_approved: IMAGE_STATUS.IN_REVIEW, }, - "POST", + "POST" ); } if (file?.name == formValues.thumbnail) { @@ -219,7 +249,7 @@ const SpaceDetailsTwo = () => { default_image_id: upload.id, // is_approved: IMAGE_STATUS.APPROVED, }, - "PUT", + "PUT" ); } } @@ -234,7 +264,7 @@ const SpaceDetailsTwo = () => { question: faq.question, answer: faq.answer, }, - "POST", + "POST" ); } @@ -247,7 +277,7 @@ const SpaceDetailsTwo = () => { property_spaces_id: propertySpaceResult.message, amenity_id, }, - "POST", + "POST" ); } navigate("/account/my-spaces"); @@ -278,138 +308,228 @@ const SpaceDetailsTwo = () => { setPictures((prev) => { var copy = [...prev]; copy[i] = picFile; - return copy; + return copy.filter(Boolean); }); }); } }, []); - function isCatOthers(){ - const cat = spaceCategories.find((cat) => Number(cat.id) == Number(spaceData.category)) + function isCatOthers() { + const cat = spaceCategories.find( + (cat) => Number(cat.id) == Number(spaceData.category) + ); if (cat?.category === "Others") { - return true - } else return false + return true; + } else return false; } return ( -