diff --git a/component/myblogs/MyBlogs.jsx b/component/myblogs/MyBlogs.jsx
index fc4db160..274b7b52 100644
--- a/component/myblogs/MyBlogs.jsx
+++ b/component/myblogs/MyBlogs.jsx
@@ -1,10 +1,31 @@
+import React, { useState, useEffect } from "react";
import moment from "moment";
import MyBlogsstyles from "../../styles/MyBlogs.module.css";
import Link from "next/link";
+import Cookies from "universal-cookie";
+import ModalConfirm from "../../component/popup/ModalConfirm";
+import notify from "../../lib/notify";
+import PostService from "../../services/PostService";
import Image from "next/image";
-export default function MyBlogs({ posts }) {
- console.log(posts, 'postss');
+export default function MyBlogs({ posts, fetchPosts }) {
+ const cookies = new Cookies();
+ const userCookie = cookies.get("userNullcast");
+
+ async function deletePost(postId) {
+ try {
+ const { message } = await PostService.deletePostById(
+ userCookie,
+ postId
+ );
+ notify(message);
+ fetchPosts();
+ } catch (err) {
+ notify(err?.response?.data?.message ?? err?.message, 'error');
+ }
+ }
+ // console.log('deletePost' ,postId);
+
return (
+
+
+ Delete
+
+ }
+ handleSubmit={() => deletePost(item.post_id)}
+ purpose={"delete"}
+ buttonColor={"red"}
+ heading={"Are you sure"}
+ text="Are you sure you want to delete this post?"
+ secondaryText="This cannot be undone"
+ />
+
{/* EDIT button goes to posts/write route*/}
{
- console.log("writenavprop", { post });
-
setCurrentPost(prevValue => ({ ...prevValue, ...post }));
// userState.setTags();
}, [post]);
@@ -71,7 +68,7 @@ export default function WriteNav({
/**
* gets tags from db and sets the tags
* options in label and value format
- * @author akhilalekha
+ * @author jasir
*/
async function getSettingsTags() {
try {
@@ -97,7 +94,7 @@ export default function WriteNav({
/**
* posts tags to db and sets state for user tags
* @param e react select handle change event
- * @author akhilalekha
+ * @author jasir
*/
const handleTags = async (e) => {
// console.log("handle tags", e);
@@ -150,57 +147,37 @@ export default function WriteNav({
/**
* gets form data and passes to parent getsettings function
* @param e form submit event
- * @author akhilalekha
+ * @author jasir
*/
const formSubmit = async (e) => {
//get form settings data - imageUpload canonicalUrl tags shortDescription metaTitle metaDescription
e.preventDefault();
- // console.log(e.target);
-
const postUrl = e.target.slug.value || "";
- // console.log({ postUrl });
- // console.log(`${baseUrl}/${postUrl}`);
- // let tags = Array.from(e.target.tags) || "";
- // // console.log("tags length: ", tags.length);
- // if (tags.length > 0) {
- // tags = tags.map((tag) => tag.value);
- // // console.log("multiple tags", tags);
- // } else {
- // tags = e.target.tags.value;
- // // console.log("single tag", tags);
- // }
-
const shortDes = e.target.shortDescription.value || "";
const metaTitle = e.target.metaTitle.value || "";
const metaDes = e.target.metaDescription.value || "";
const settingsData = {
- // tags: tagsId,
- // url: `p/${currentPost._id}`,
banner_image: currentPost.banner_image ? currentPost.banner_image : null,
- // shortDescription: shortDes,
+ og_description: shortDes,
meta_title: metaTitle,
- // metaDescription: metaDes,
+ meta_description: metaDes,
slug: postUrl,
mobiledoc: currentPost.mobiledoc,
};
- if (settingsData.slug === ""){
+ if (settingsData.slug === "") {
delete settingsData.slug;
getSettings(settingsData);
}
else {
getSettings(settingsData);
}
- // console.log(
- // Object.values(settingsData).some((k) => k !== "" || k !== null)
- // );
- // send prop
};
/**
* gets form data and passes to parent getsettings function
* @param e handle change event for other fields
* except tags and image
- * @author akhilalekha
+ * @author jasir
*/
const handleChange = (e) => {
@@ -219,16 +196,9 @@ export default function WriteNav({
/**
* gets img data and uploads to s3 bucket
* @param e handle change event for file upload field
- * @author akhilalekha
+ * @author jasir
*/
const handleImageUpload = async (image) => {
- // console.log(e.target.files[0]);
- // const imageUrl = URL.createObjectURL(e.target.files[0]);
- // console.log(imageUrl);
- // setImageSrc(imageUrl);
-
- // console.log(e.target.files[0]);
- // const imageFile = e.target.files[0] || "";
const imageFile = image;
const imageData = {
stage: "dev",
@@ -240,7 +210,6 @@ export default function WriteNav({
setLoading(true);
try {
const s3ImageUrl = await SharedService.uploadImage(imageFile, imageData);
- // console.log(s3ImageUrl);
setCurrentPost((prevValue) => {
return {
@@ -258,7 +227,7 @@ export default function WriteNav({
/**
* resets banner image state when user clicks on delete
* @param e handle change event for img delete button
- * @author akhilalekha
+ * @author jasir
*/
const handleImageDelete = async (e) => {
setCurrentPost((prevValue) => {
@@ -273,16 +242,15 @@ export default function WriteNav({
/**
* deletes post by id
- * @author akhilalekha
+ * @author jasir
*/
async function deletePost() {
try {
- const { msg, data } = await PostService.deletePostById(
+ const { message } = await PostService.deletePostById(
userCookie,
currentPost.id
);
- // console.log(msg);
- notify("Post deleted successfully");
+ notify(message);
router.push({
pathname: "/posts",
query: {
@@ -297,15 +265,13 @@ export default function WriteNav({
}
const handleBackOption = () => {
- // console.log(previousUrl);
router.push(previousUrl);
};
const handlePublish = () => {
const res = submitForReview();
- res.then((msg) => {
+ res.then((message) => {
handlePopup();
- // console.log(msg);
});
};
const handlePopup = () => {
@@ -349,23 +315,23 @@ export default function WriteNav({
{"/ Edit"}