Skip to content

Commit

Permalink
Merge pull request #208 from teguhbayu/main
Browse files Browse the repository at this point in the history
fix(frontend): Removable Tag now works properly
  • Loading branch information
ahsanzizan authored Jun 12, 2024
2 parents 26ab326 + 951b3e6 commit dbb4c1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/app/(admin)/admin/posts/create/_components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
14 changes: 9 additions & 5 deletions src/app/(admin)/admin/posts/create/_components/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
);
};

Expand All @@ -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",
Expand Down

0 comments on commit dbb4c1c

Please sign in to comment.