diff --git a/src/app/(admin)/admin/posts/create/_components/Form.tsx b/src/app/(admin)/admin/posts/create/_components/Form.tsx index ac522b34..b9e727b7 100644 --- a/src/app/(admin)/admin/posts/create/_components/Form.tsx +++ b/src/app/(admin)/admin/posts/create/_components/Form.tsx @@ -31,12 +31,18 @@ export default function PostForm({ tags }: { tags: TagWithPostCount[] }) { useEffect(() => { if ( - session?.user?.role! === "Admin" || - session?.user?.role! === "SuperAdmin" + !( + session?.user?.role === "Admin" || session?.user?.role === "SuperAdmin" + ) && + session?.user?.role ) { - return; + setTag([ + { + label: session?.user?.role.toString(), + value: session?.user?.role.toString(), + }, + ]); } - setTag([{ label: session?.user?.role!, value: session?.user?.role! }]); }, [session?.user?.role]); return ( diff --git a/src/app/(admin)/admin/posts/create/_components/Tags.tsx b/src/app/(admin)/admin/posts/create/_components/Tags.tsx index bd813393..b57a9139 100644 --- a/src/app/(admin)/admin/posts/create/_components/Tags.tsx +++ b/src/app/(admin)/admin/posts/create/_components/Tags.tsx @@ -38,21 +38,23 @@ export default function Tags({ switch (actionMeta.action) { case "remove-value": case "pop-value": - if (actionMeta.removedValue.value === session?.user?.role) { + if (actionMeta.removedValue.value === session?.user?.role.toString()) { return; } break; case "clear": newValue = tags - .filter((v) => v.tagName === session?.user?.role) + .filter((v) => v.tagName === session?.user?.role.toString()) .map((tag) => ({ value: tag.tagName, label: tag.tagName })); break; } setState( newValue - .filter((v) => v.value === session?.user?.role) - .concat(newValue.filter((v) => v.value !== session?.user?.role)), + .filter((v) => v.value === session?.user?.role.toString()) + .concat( + newValue.filter((v) => v.value !== session?.user?.role.toString()), + ), ); }; @@ -74,7 +76,9 @@ export default function Tags({ onChange={onChange} name="tags" required - isClearable={options.some((v) => v.value !== session?.user?.role)} + isClearable={options.some( + (v) => v.value !== session?.user?.role.toString(), + )} classNames={{ control: () => "rounded-xl border border-neutral-400 px-[18px] active:border-black hover:border-black py-[14px] text-black placeholder-neutral-500 bg-white focus:outline-none transition-all duration-500",