import { Group, Text, Switch, Tooltip } from "@mantine/core"; import { modals } from "@mantine/modals"; import { useAtom } from "jotai"; import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { updateWorkspace } from "@/features/workspace/services/workspace-service.ts"; import { notifications } from "@mantine/notifications"; import { useHasFeature } from "@/ee/hooks/use-feature"; import { Feature } from "@/ee/features"; import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label.ts"; export default function DisablePublicSharing() { const { t } = useTranslation(); return (
{t("Disable public sharing")} {t("Prevent members from sharing pages publicly.")}
); } function DisablePublicSharingToggle() { const { t } = useTranslation(); const [workspace, setWorkspace] = useAtom(workspaceAtom); const [checked, setChecked] = useState( workspace?.settings?.sharing?.disabled === true, ); const hasAccess = useHasFeature(Feature.SECURITY_SETTINGS); const upgradeLabel = useUpgradeLabel(); const applyChange = async (value: boolean) => { try { const updatedWorkspace = await updateWorkspace({ disablePublicSharing: value, }); setChecked(value); setWorkspace(updatedWorkspace); } catch (err) { notifications.show({ message: err?.response?.data?.message, color: "red", }); } }; const handleChange = (event: React.ChangeEvent) => { const value = event.currentTarget.checked; modals.openConfirmModal({ title: value ? t("Disable public sharing") : t("Enable public sharing"), children: ( {value ? t( "Are you sure you want to disable public sharing? All existing shared links in this workspace will be deleted.", ) : t( "Are you sure you want to enable public sharing? Members will be able to share pages publicly.", )} ), centered: true, labels: { confirm: t("Confirm"), cancel: t("Cancel") }, confirmProps: value ? { color: "red" } : {}, onConfirm: () => applyChange(value), }); }; return ( ); }