import { Box, FormControl, FormHelperText, FormLabel, Input, Stack, Textarea, Heading, Button, useToast, Divider, Image, } from "@chakra-ui/react"; import React, { useState } from "react"; import fallbackImage from "../../assets/ultp-fallback-img.webp"; import { TiWarning } from "react-icons/ti"; import { motion } from "framer-motion"; import { OPACITY_ON_LOAD } from "../../Layout/animations"; import { yupResolver } from "@hookform/resolvers/yup"; import { useForm } from "react-hook-form"; import { addCommunityBannerSchema, addCommunitySchema, } from "../../Validations/Validations"; import { useNavigate } from "react-router-dom"; import Loader01 from "../../Components/Loaders/Loader01"; import Header from "../Header"; import ToastBox from "../ToastBox"; const AddBanner = ({ createApi, navigateLink, title }) => { const toast = useToast(); const navigate = useNavigate(); const [isLoading, setIsLoading] = useState(false); const [selectedImage, setSelectedImage] = useState(fallbackImage); const [largeImageData, setLargeImageData] = useState(null); const { register, handleSubmit, reset, formState: { errors }, } = useForm({ resolver: yupResolver(addCommunityBannerSchema), }); const onSubmit = async (data) => { console.log(data); try { setIsLoading(true); const formData = new FormData(); formData.append("heading", data.heading); formData.append("sub_heading", data.sub_heading); formData.append("CTO_button_link", data.CTO_button_link); formData.append("CTO_button_title", data.CTO_button_title); if (data.banner_image[0]) { formData.append("banner_image", data.banner_image[0]); } // Trigger the mutation createApi(formData) .then((response) => { // Handle the response here console.log("Mutation response:", response?.data?.statusCode); console.log("Mutation response:", response?.data?.message); if (response?.data?.statusCode === 200) { setIsLoading(false); toast({ render: () => ( ), }); reset(); navigate(navigateLink); } else if (response?.data?.statusCode === 500) { setIsLoading(false); toast({ render: () => ( ), }); } }) .catch((error) => { // Handle errors console.error("Error creating community:", error); setIsLoading(false); // Handle error notification if needed }); } catch (error) { // Handle errors console.error("Error creating community:", error); setIsLoading(false); } }; const handleImageChange = (e) => { const file = e.target.files[0]; setLargeImageData(file); if (file) { const reader = new FileReader(); reader.onloadend = () => { setSelectedImage(reader.result); }; reader.readAsDataURL(file); } }; return (
Banner Info Select the platform for which you need to create this campaign. Banner Image Below is the profile that will be displayed on the community page. <> Selected Image {selectedImage === fallbackImage || largeImageData === null ? ( "" ) : ( {largeImageData?.name} {(largeImageData?.size / (1024 * 1024)).toFixed(2)} mb )}
Heading {errors.name && ( {errors.heading.message} )} Sub Heading {errors.sub_heading && ( {" "} {errors.sub_heading.message} )} Button title Maximum characters must be 100 characters. {errors.CTO_button_title && ( {" "} {errors.CTO_button_title.message} )} Button link Please share proper linked in link here. {errors.CTO_button_link && ( {" "} {errors.CTO_button_link.message} )} Banner image {/* */} Drop images here or click to upload {errors.banner_image && ( {" "} {errors.banner_image.message} )} Maximum limit of image is 5mb.
); }; export default AddBanner;