mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 14:43:06 +08:00
d7a5fda53c
* feat: feature flag upgrade * fix translations * refactor * fix * fix
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { Group, Text, Switch, MantineSize, Tooltip } from "@mantine/core";
|
|
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.ts";
|
|
import { Feature } from "@/ee/features.ts";
|
|
import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label.ts";
|
|
|
|
export default function EnforceSso() {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Group justify="space-between" wrap="nowrap" gap="xl">
|
|
<div>
|
|
<Text size="md">{t("Enforce SSO")}</Text>
|
|
<Text size="sm" c="dimmed">
|
|
{t(
|
|
"Once enforced, members will not be able to login with email and password.",
|
|
)}
|
|
</Text>
|
|
</div>
|
|
|
|
<EnforceSsoToggle />
|
|
</Group>
|
|
);
|
|
}
|
|
|
|
interface EnforceSsoToggleProps {
|
|
size?: MantineSize;
|
|
label?: string;
|
|
}
|
|
export function EnforceSsoToggle({ size, label }: EnforceSsoToggleProps) {
|
|
const { t } = useTranslation();
|
|
const [workspace, setWorkspace] = useAtom(workspaceAtom);
|
|
const [checked, setChecked] = useState(workspace?.enforceSso);
|
|
const hasAccess = useHasFeature(Feature.SSO_CUSTOM);
|
|
const upgradeLabel = useUpgradeLabel();
|
|
|
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
const value = event.currentTarget.checked;
|
|
try {
|
|
const updatedWorkspace = await updateWorkspace({ enforceSso: value });
|
|
setChecked(value);
|
|
setWorkspace(updatedWorkspace);
|
|
} catch (err) {
|
|
notifications.show({
|
|
message: err?.response?.data?.message,
|
|
color: "red",
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Tooltip label={upgradeLabel} disabled={hasAccess} refProp="rootRef">
|
|
<Switch
|
|
size={size}
|
|
label={label}
|
|
labelPosition="left"
|
|
defaultChecked={checked}
|
|
onChange={handleChange}
|
|
disabled={!hasAccess}
|
|
aria-label={t("Toggle sso enforcement")}
|
|
/>
|
|
</Tooltip>
|
|
);
|
|
}
|