feat: enhance board visibility controls with dropdown menu and success notifications (#65)
* feat: enhance board visibility controls with dropdown menu and success notifications * feat: tweak design --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk>
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { HiOutlineEye, HiOutlineEyeSlash } from "react-icons/hi2";
|
import { HiOutlineEye, HiOutlineEyeSlash } from "react-icons/hi2";
|
||||||
|
|
||||||
import Button from "~/components/Button";
|
import Button from "~/components/Button";
|
||||||
|
import CheckboxDropdown from "~/components/CheckboxDropdown";
|
||||||
import { usePopup } from "~/providers/popup";
|
import { usePopup } from "~/providers/popup";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ const VisibilityButton = ({
|
|||||||
}: {
|
}: {
|
||||||
visibility: "public" | "private";
|
visibility: "public" | "private";
|
||||||
boardPublicId: string;
|
boardPublicId: string;
|
||||||
|
boardSlug: string;
|
||||||
queryParams: QueryParams;
|
queryParams: QueryParams;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
@@ -38,7 +40,11 @@ const VisibilityButton = ({
|
|||||||
|
|
||||||
const updateBoardVisibility = api.board.update.useMutation({
|
const updateBoardVisibility = api.board.update.useMutation({
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
setStateVisibility(isPublic ? "private" : "public");
|
showPopup({
|
||||||
|
header: "Board visibility updated",
|
||||||
|
message: `The visibility of your board has been set to ${isPublic ? "public" : "private"}.`,
|
||||||
|
icon: "success",
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
showPopup({
|
showPopup({
|
||||||
@@ -52,23 +58,39 @@ const VisibilityButton = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleUpdateBoardVisibility = () => {
|
|
||||||
updateBoardVisibility.mutate({
|
|
||||||
visibility: isPublic ? "private" : "public",
|
|
||||||
boardPublicId,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<div className="relative">
|
||||||
variant="secondary"
|
<CheckboxDropdown
|
||||||
onClick={handleUpdateBoardVisibility}
|
items={[
|
||||||
iconLeft={isPublic ? <HiOutlineEye /> : <HiOutlineEyeSlash />}
|
{
|
||||||
isLoading={updateBoardVisibility.isPending}
|
key: "public",
|
||||||
disabled={isLoading || !isAdmin}
|
value: "Public",
|
||||||
>
|
selected: isPublic,
|
||||||
{isPublic ? "Public" : "Private"}
|
},
|
||||||
</Button>
|
{
|
||||||
|
key: "private",
|
||||||
|
value: "Private",
|
||||||
|
selected: !isPublic,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
handleSelect={(_g, i) => {
|
||||||
|
setStateVisibility(isPublic ? "private" : "public");
|
||||||
|
updateBoardVisibility.mutate({
|
||||||
|
visibility: i.key as "public" | "private",
|
||||||
|
boardPublicId,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
menuSpacing="md"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
iconLeft={isPublic ? <HiOutlineEye /> : <HiOutlineEyeSlash />}
|
||||||
|
disabled={isLoading || !isAdmin}
|
||||||
|
>
|
||||||
|
Visibility
|
||||||
|
</Button>
|
||||||
|
</CheckboxDropdown>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -260,13 +260,16 @@ export default function BoardPage() {
|
|||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
{!boardData && !isLoading && (
|
{!boardData && !isLoading && (
|
||||||
<p className="block p-0 py-0 font-bold leading-[2.3rem] tracking-tight text-neutral-900 dark:text-dark-1000 sm:text-[1.2rem]">Board not found</p>
|
<p className="block p-0 py-0 font-bold leading-[2.3rem] tracking-tight text-neutral-900 dark:text-dark-1000 sm:text-[1.2rem]">
|
||||||
|
Board not found
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<VisibilityButton
|
<VisibilityButton
|
||||||
visibility={boardData?.visibility ?? "private"}
|
visibility={boardData?.visibility ?? "private"}
|
||||||
boardPublicId={boardId ?? ""}
|
boardPublicId={boardId ?? ""}
|
||||||
|
boardSlug={boardData?.slug ?? ""}
|
||||||
queryParams={queryParams}
|
queryParams={queryParams}
|
||||||
isLoading={!boardData}
|
isLoading={!boardData}
|
||||||
isAdmin={workspace.role === "admin"}
|
isAdmin={workspace.role === "admin"}
|
||||||
@@ -374,12 +377,13 @@ export default function BoardPage() {
|
|||||||
}}
|
}}
|
||||||
key={card.publicId}
|
key={card.publicId}
|
||||||
href={`/cards/${card.publicId}`}
|
href={`/cards/${card.publicId}`}
|
||||||
className={`mb-2 flex !cursor-pointer flex-col ${card.publicId.startsWith(
|
className={`mb-2 flex !cursor-pointer flex-col ${
|
||||||
"PLACEHOLDER",
|
card.publicId.startsWith(
|
||||||
)
|
"PLACEHOLDER",
|
||||||
? "pointer-events-none"
|
)
|
||||||
: ""
|
? "pointer-events-none"
|
||||||
}`}
|
: ""
|
||||||
|
}`}
|
||||||
ref={provided.innerRef}
|
ref={provided.innerRef}
|
||||||
{...provided.draggableProps}
|
{...provided.draggableProps}
|
||||||
{...provided.dragHandleProps}
|
{...provided.dragHandleProps}
|
||||||
|
|||||||
Reference in New Issue
Block a user