fixed card edit

This commit is contained in:
rockyeverlast
2024-06-05 20:02:13 +05:30
parent c18583e1b0
commit 1937773ecf
4 changed files with 34 additions and 33 deletions

View File

@@ -39,15 +39,13 @@ const EditPartner = () => {
const { id } = useParams();
const toast = useToast();
const navigate = useNavigate();
const { data, error, isLoading } = useGetPartnersByIdQuery(id);
const { data, error, isLoading, refetch } = useGetPartnersByIdQuery(id);
const [isLoadingEdit, setIsLoadingEdit] = useState(false);
const [selectedImage, setSelectedImage] = useState(fallbackImage);
const [largeImageData, setLargeImageData] = useState(null);
const [updatePartners] = useUpdatePartnersMutation();
const [valueQuill, setValueQuill] = useState(data?.data?.content);
console.log(valueQuill);
const {
register,
handleSubmit,
@@ -59,7 +57,7 @@ const EditPartner = () => {
defaultValues: {
website_link: "",
description: "",
company_logo: null,
banner_image: "",
},
});
@@ -73,7 +71,7 @@ const EditPartner = () => {
);
setValue("website_link", data?.data?.website_link);
setValue("description", data?.data?.description);
setValue("company_logo", data?.data?.company_logo);
setValue("banner_image", data?.data?.banner_image);
// setValueQuill(data?.data?.content);
}
}, [data, setValue]);
@@ -97,8 +95,8 @@ const EditPartner = () => {
const form = new FormData();
form.append("website_link", data?.website_link);
form.append("description", data?.description);
if (data?.company_logo[0]) {
form.append("company_logo", data?.company_logo[0]);
if (data?.banner_image[0]) {
form.append("banner_image", data?.banner_image[0]);
}
// Log formData entries
@@ -116,7 +114,7 @@ const EditPartner = () => {
<ToastBox status={"success"} message={response?.data?.message} />
),
});
refetch();
reset();
navigate("/partners");
// setDeleteAlert(false);
@@ -298,7 +296,7 @@ const EditPartner = () => {
</Stack>
</Box>
<Input
{...register("image")}
{...register("banner_image")}
type="file"
height="100%"
width="100%"

View File

@@ -36,9 +36,9 @@ const ViewPartner = () => {
flexDirection={"column"}
>
<Header
title={"Privacy Policy"}
btnTitle={"Edit Privacy Policy"}
link={`/policy/edit/${id}`}
title={"Cards"}
btnTitle={"Edit Cards"}
link={`/partners/edit/${id}`}
/>
<Box display={"flex"}>

View File

@@ -16,15 +16,13 @@ import {
Kbd,
} from "@chakra-ui/react";
import {
useGetBlogByIdQuery,
useGetUsecaseByIdQuery,
useUpdateBlogMutation,
useUpdateUsecaseMutation,
} from "../../Services/api.service";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import FullscreenLoaders from "../../Components/Loaders/FullscreenLoaders";
import { addBlogSchema, addUsecase, editUsecase } from "../../Validations/Validations";
import { editUsecase } from "../../Validations/Validations";
import fallbackImage from "../../assets/fallBackImage.png";
import fallbackImageLarge from "../../assets/ultp-fallback-img.webp";
import { OPACITY_ON_LOAD } from "../../Layout/animations";
@@ -70,9 +68,9 @@ const EditUseCase = () => {
title: blog?.title,
meta_description: blog?.meta_description,
content: blog?.content,
// banner_image: null,
// icon: null,
// attachment: null,
// banner_image: null,
// icon: null,
// attachment: null,
},
});
@@ -103,11 +101,11 @@ const EditUseCase = () => {
if (data?.icon[0]) {
formData.append("icon", data.icon[0]);
}
if(data?.attachment !== blog?.attachment){
Array.from(data?.attachment).forEach((file, index) => {
if (data?.attachment !== blog?.attachment) {
Array.from(data?.attachment).forEach((file, index) => {
formData.append(`attachment`, file);
})}
});
}
try {
setIsLoading01(true);
@@ -130,7 +128,7 @@ const EditUseCase = () => {
});
reset();
navigate("/usecase");
}else if(response?.error?.status === 500){
} else if (response?.error?.status === 500) {
setIsLoading01(false);
toast({
render: () => (
@@ -140,7 +138,6 @@ const EditUseCase = () => {
/>
),
});
}
})
.catch((error) => {
@@ -193,7 +190,7 @@ const EditUseCase = () => {
display={"flex"}
flexDirection={"column"}
>
<Header title={"Blog"} />
<Header title={"UseCases"} />
<Box className="d-flex">
<Box className="col-5 d-flex flex-column gap-2 pt-4">
<span className="web-text-large fw-bold rubix-text-dark">
@@ -339,7 +336,7 @@ const EditUseCase = () => {
)}
</FormControl>
<FormControl className="mb-5">
<FormControl className="mb-5">
<FormLabel className="web-text-large fw-bold rubix-text-dark">
Banner image
</FormLabel>
@@ -549,12 +546,18 @@ const EditUseCase = () => {
className="web-text-medium form-control rounded-1"
size="sm"
multiple={true}
onChange={()=> console.log(e.target.value)}
/><FormHelperText className="web-text-small">
You can select multiple documents using <span className="text-dark">
<Kbd size={'sm'} className="text-dark">ctrl</Kbd> + <Kbd className="text-dark">select</Kbd>
</span>.
</FormHelperText>
onChange={() => console.log(e.target.value)}
/>
<FormHelperText className="web-text-small">
You can select multiple documents using{" "}
<span className="text-dark">
<Kbd size={"sm"} className="text-dark">
ctrl
</Kbd>{" "}
+ <Kbd className="text-dark">select</Kbd>
</span>
.
</FormHelperText>
{errors.attachment && (
<span className="text-danger web-text-small fw-bold ps-2 d-flex align-items-center gap-1 mt-1">
<TiWarning className="fw-bold fs-5 " />{" "}

View File

@@ -578,7 +578,7 @@ export const addPolicy = Yup.object().shape({
export const addPartnerCard = Yup.object().shape({
website_link: Yup.string().required("link is required"),
description: Yup.string().required("description is required"),
company_logo: Yup.mixed().required("logo is required")
banner_image: Yup.mixed().required("logo is required")
// .test("required", "You need to provide a file", (files) => {
// // return file && file.size <-- u can use this if you don't want to allow empty files to be uploaded;
// if (files) return true;