* feat: setup schema for workspace roles * chore: regen migration * feat: add publicId to workspace roles * feat: setup default permissions * feat: add repo funcs * feat: setup basic router interactions * feat: add card permissions * feat: assert permissions for lists * feat: assert board permissions * feat: assert permission for remaining routes * feat: add permissions page to settings * feat: enable updating member roles * feat: order members by role and createdAt * feat: allow editing individual permissions * feat: reset role defaults * feat: clear all permission overrides * feat: allow users to delete entities they have created * feat: set roleId when inviting new members * feat: disable UI elements if user does not have permissions * feat: allow admins to assign the admin role to other users * feat: allow delete:list as default * refactor: centre permissions modal * chore: translations
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import { t } from "@lingui/core/macro";
|
|
import { useEffect, useState } from "react";
|
|
import { HiOutlineEye, HiOutlineEyeSlash } from "react-icons/hi2";
|
|
|
|
import Button from "~/components/Button";
|
|
import CheckboxDropdown from "~/components/CheckboxDropdown";
|
|
import { Tooltip } from "~/components/Tooltip";
|
|
import { usePermissions } from "~/hooks/usePermissions";
|
|
import { usePopup } from "~/providers/popup";
|
|
import { api } from "~/utils/api";
|
|
|
|
interface QueryParams {
|
|
boardPublicId: string;
|
|
members: string[];
|
|
labels: string[];
|
|
lists: string[];
|
|
}
|
|
|
|
const VisibilityButton = ({
|
|
visibility,
|
|
boardPublicId,
|
|
queryParams,
|
|
isLoading,
|
|
isAdmin,
|
|
}: {
|
|
visibility: "public" | "private";
|
|
boardPublicId: string;
|
|
boardSlug: string;
|
|
queryParams: QueryParams;
|
|
isLoading: boolean;
|
|
isAdmin: boolean;
|
|
}) => {
|
|
const { showPopup } = usePopup();
|
|
const { canEditBoard } = usePermissions();
|
|
const utils = api.useUtils();
|
|
const [stateVisibility, setStateVisibility] = useState<"public" | "private">(
|
|
visibility,
|
|
);
|
|
|
|
useEffect(() => {
|
|
setStateVisibility(visibility);
|
|
}, [visibility]);
|
|
|
|
const isPublic = stateVisibility === "public";
|
|
|
|
const updateBoardVisibility = api.board.update.useMutation({
|
|
onSuccess: () => {
|
|
showPopup({
|
|
header: t`Board visibility updated`,
|
|
message: t`The visibility of your board has been set to ${isPublic ? "public" : "private"}.`,
|
|
icon: "success",
|
|
});
|
|
},
|
|
onError: () => {
|
|
showPopup({
|
|
header: t`Unable to update board visibility`,
|
|
message: t`Please try again later, or contact customer support.`,
|
|
icon: "error",
|
|
});
|
|
},
|
|
onSettled: async () => {
|
|
await utils.board.byId.invalidate(queryParams);
|
|
},
|
|
});
|
|
|
|
const canEdit = canEditBoard || isAdmin;
|
|
|
|
return (
|
|
<div className="relative">
|
|
<Tooltip
|
|
content={
|
|
!canEdit && !isLoading ? t`You don't have permission` : undefined
|
|
}
|
|
>
|
|
<CheckboxDropdown
|
|
items={[
|
|
{
|
|
key: "public",
|
|
value: t`Public`,
|
|
selected: isPublic,
|
|
},
|
|
{
|
|
key: "private",
|
|
value: t`Private`,
|
|
selected: !isPublic,
|
|
},
|
|
]}
|
|
handleSelect={(_g, i) => {
|
|
if (!canEdit) return;
|
|
setStateVisibility(isPublic ? "private" : "public");
|
|
updateBoardVisibility.mutate({
|
|
visibility: i.key as "public" | "private",
|
|
boardPublicId,
|
|
});
|
|
}}
|
|
menuSpacing="md"
|
|
>
|
|
<Button
|
|
variant="secondary"
|
|
iconLeft={isPublic ? <HiOutlineEye /> : <HiOutlineEyeSlash />}
|
|
disabled={isLoading || !canEdit}
|
|
>
|
|
{t`Visibility`}
|
|
</Button>
|
|
</CheckboxDropdown>
|
|
</Tooltip>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default VisibilityButton;
|