Skip to content

Commit

Permalink
Merge pull request #753 from jasirneoito/633/fix-admin-blog-status
Browse files Browse the repository at this point in the history
fix: blog status in admin page and drafted fillter added #633
  • Loading branch information
jasirtp authored Jan 12, 2022
2 parents 31b17d6 + 7687f7f commit 3e0abe8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 42 deletions.
51 changes: 38 additions & 13 deletions component/admin/AdminBlogsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function AdminBlogsList({ posts, updated }) {
* @param {*} blog
* @author athulraj2002
* @returns null
*
*
*/
async function updatePostById(updateData, newPostId) {
try {
Expand All @@ -24,18 +24,18 @@ export default function AdminBlogsList({ posts, updated }) {
}
updated();
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
}

const approveBlog = async (blog) => {
try {
const newUpdatedPost = {
status: 'published',
status: "published"
};
updatePostById(blog.id, newUpdatedPost);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
};

Expand All @@ -48,22 +48,22 @@ export default function AdminBlogsList({ posts, updated }) {
const rejectBlog = async (blog) => {
try {
const newUpdatedPost = {
status: 'rejected',
status: "rejected"
};
updatePostById(blog.id, newUpdatedPost);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
};

const unpublishBlog = async (blog) => {
const unPublishBlog = async (blog) => {
try {
const newUpdatedPost = {
status: 'pending',
status: "pending"
};
updatePostById(blog.id, newUpdatedPost);
} catch (err) {
notify(err?.response?.data?.message ?? err?.message, 'error');
notify(err?.response?.data?.message ?? err?.message, "error");
}
// console.log(response);
};
Expand Down Expand Up @@ -97,13 +97,37 @@ export default function AdminBlogsList({ posts, updated }) {
{moment(item.updated_at).format("LL")}
{" - "}
<Link href={`/u/${item.user.user_name}`}>
<a className="text-blue-500">
{item.user.user_name}
</a>
<a className="text-blue-500">{item.user.user_name}</a>
</Link>
</div>
</div>
<div className="flex items-center">
<div
className={`flex items-center w-32 justify-center rounded-full h-8 mr-3 ${
item.status === "approved" && MyBlogsstyles.successBg
} ${item.status === "pending" && MyBlogStyles.warningBg} ${
item.status === "drafted" && MyBlogStyles.draftedBg
} ${
item.status === "published" && MyBlogStyles.publishedBg
} ${item.status === "rejected" && MyBlogStyles.dangerBg}`}
>
<span
className={`capitalize ${
item.status === "approved" && MyBlogStyles.successText
} ${
item.status === "pending" && MyBlogStyles.warningText
} ${
item.status === "drafted" && MyBlogStyles.draftedText
} ${
item.status === "published" &&
MyBlogStyles.publishedText
} ${
item.status === "rejected" && MyBlogStyles.dangerText
}`}
>
{item.status}
</span>
</div>
<Link
href={
item.status === "published"
Expand All @@ -127,6 +151,7 @@ export default function AdminBlogsList({ posts, updated }) {
</>
</div>
</Link>

{item.status == "published" ? (
<div
className={`flex items-center w-28 justify-center rounded-full h-8 mr-3 ${MyBlogStyles.publishedBg} `}
Expand Down Expand Up @@ -175,7 +200,7 @@ export default function AdminBlogsList({ posts, updated }) {
)}
{item.status == "published" && (
<div
onClick={() => unpublishBlog(item)}
onClick={() => unPublishBlog(item)}
className={`flex items-center w-28 justify-center rounded-full h-8 mr-3 cursor-pointer hover:opacity-50 duration-500 ${MyBlogStyles.warningBg} `}
>
<span
Expand Down
65 changes: 36 additions & 29 deletions component/admin/AdminNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import Select from "react-select";
import styles from "../myblogs/blogs.module.scss";
import TagService from "../../services/TagService";
import notify from "../../lib/notify";
import { useRouter } from 'next/router'
import { useRouter } from "next/router";

export default function AdminNavbar({ changeTag, changeStatus, event }) {
const statusOptions = [
{ label:event? "ALL EVENTS" : "ALL POSTS", value: "" },
{ label: event ? "ALL EVENTS" : "ALL POSTS", value: "" },
// { label: "APPROVED", value: "approved" },
{ label: "PENDING", value: "pending" },
{ label: "REJECTED", value: "rejected" },
{ label: "PUBLISHED", value: "published" },
{ label: "DRAFTED", value: "drafted" }
];
const [tagOptions, setTagOptions] = useState([]);

const router = useRouter()
const router = useRouter();

useEffect(() => {
getSettingsTags();
Expand Down Expand Up @@ -71,34 +72,40 @@ export default function AdminNavbar({ changeTag, changeStatus, event }) {
<div className="bg-white flex flex-row items-center rounded shadow-sm h-sub-nav">
<div className="flex flex-row justify-end items-center font-semibold h-full w-full md:px-5 px-3">
<div className="flex items-center py-3">
{event ? " " :
<Select
options={tagOptions}
isMulti={false}
onChange={(e) => selectCategory(e)}
className={`basic-single postFilter m-0 outline-none focus:outline-none text-sm bg-gray-200 border rounded px-0 cursor-pointer md:mr-4 ${styles.min_w_10}`}
classNamePrefix="Category"
clearValue={() => undefined}
placeholder="Select Tag"
// closeMenuOnSelect={false}
/>
}
{event ? "" :
<Select
options={statusOptions}
isMulti={false}
onChange={(e) => selectStatus(e)}
className={`basic-single postFilter md:block hidden m-0 outline-none focus:outline-none text-sm bg-gray-200 border rounded px-0 cursor-pointer ${styles.min_w_10}`}
classNamePrefix="Blog Status"
clearValue={() => undefined}
placeholder="Select Status"
// closeMenuOnSelect={false}
/>}
{router.pathname.split('/')[2] === 'events' && <div className="bg-black h-8 ml-4 hover:bg-white border border-black text-white hover:text-black hidden md:flex items-center text-sm font-semibold px-4 py-2 md:mr-3 rounded-sm cursor-pointer duration-700 blogs_h_40px__3sE3c">
{event ? (
" "
) : (
<Select
options={tagOptions}
isMulti={false}
onChange={(e) => selectCategory(e)}
className={`basic-single postFilter m-0 outline-none focus:outline-none text-sm bg-gray-200 border rounded px-0 cursor-pointer md:mr-4 ${styles.min_w_10}`}
classNamePrefix="Category"
clearValue={() => undefined}
placeholder="Select Tag"
// closeMenuOnSelect={false}
/>
)}
{event ? (
""
) : (
<Select
options={statusOptions}
isMulti={false}
onChange={(e) => selectStatus(e)}
className={`basic-single postFilter md:block hidden m-0 outline-none focus:outline-none text-sm bg-gray-200 border rounded px-0 cursor-pointer ${styles.min_w_10}`}
classNamePrefix="Blog Status"
clearValue={() => undefined}
placeholder="Select Status"
// closeMenuOnSelect={false}
/>
)}
{router.pathname.split("/")[2] === "events" && (
<div className="bg-black h-8 ml-4 hover:bg-white border border-black text-white hover:text-black hidden md:flex items-center text-sm font-semibold px-4 py-2 md:mr-3 rounded-sm cursor-pointer duration-700 blogs_h_40px__3sE3c">
<a href="/admin/events/create-event">Create Event</a>
</div>}
</div>
)}
</div>

</div>
</div>
);
Expand Down

0 comments on commit 3e0abe8

Please sign in to comment.