mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 00:02:19 +10:00
feat(integrations): one-step install for workspace-scoped providers
This commit is contained in:
@@ -19,6 +19,7 @@ export default function ConnectionRow({
|
|||||||
isDisconnecting,
|
isDisconnecting,
|
||||||
}: ConnectionRowProps) {
|
}: ConnectionRowProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const isWorkspaceScoped = definition.oauth?.connectionScope === 'workspace';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
@@ -42,30 +43,47 @@ export default function ConnectionRow({
|
|||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Group gap="sm" wrap="nowrap" style={{ flexShrink: 0 }}>
|
<Group gap="sm" wrap="nowrap" style={{ flexShrink: 0 }}>
|
||||||
{connection ? (
|
{isWorkspaceScoped ? (
|
||||||
<>
|
<>
|
||||||
<Text size="xs" c="green">
|
{connection ? (
|
||||||
{t("Connected")}
|
<Text size="xs" c="green">
|
||||||
{connection.providerUserId && ` (${connection.providerUserId})`}
|
{t("Linked")}
|
||||||
</Text>
|
{connection.providerUserId && ` as @${connection.providerUserId}`}
|
||||||
<Button
|
</Text>
|
||||||
size="xs"
|
) : (
|
||||||
variant="subtle"
|
<Text size="xs" c="dimmed">
|
||||||
color="red"
|
{t("Use")} <code>/docmost help</code> {t("in")} {definition.name} {t("to link your account.")}
|
||||||
onClick={() => onDisconnect(connection.integrationId)}
|
</Text>
|
||||||
loading={isDisconnecting}
|
)}
|
||||||
>
|
|
||||||
{t("Disconnect")}
|
|
||||||
</Button>
|
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<>
|
||||||
size="xs"
|
{connection ? (
|
||||||
variant="light"
|
<>
|
||||||
onClick={() => onConnect(definition.type)}
|
<Text size="xs" c="green">
|
||||||
>
|
{t("Connected")}
|
||||||
{t("Connect")}
|
{connection.providerUserId && ` (${connection.providerUserId})`}
|
||||||
</Button>
|
</Text>
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant="subtle"
|
||||||
|
color="red"
|
||||||
|
onClick={() => onDisconnect(connection.integrationId)}
|
||||||
|
loading={isDisconnecting}
|
||||||
|
>
|
||||||
|
{t("Disconnect")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant="light"
|
||||||
|
onClick={() => onConnect(definition.type)}
|
||||||
|
>
|
||||||
|
{t("Connect")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
useUpdateIntegrationSettings,
|
useUpdateIntegrationSettings,
|
||||||
} from "../queries/integration-query";
|
} from "../queries/integration-query";
|
||||||
import { Integration } from "../types/integration.types";
|
import { Integration } from "../types/integration.types";
|
||||||
|
import { getOAuthAuthorizeUrl } from "../services/integration-service";
|
||||||
|
|
||||||
export default function Integrations() {
|
export default function Integrations() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -28,10 +29,21 @@ export default function Integrations() {
|
|||||||
const [configuring, setConfiguring] = useState<Integration | null>(null);
|
const [configuring, setConfiguring] = useState<Integration | null>(null);
|
||||||
|
|
||||||
const handleInstall = useCallback(
|
const handleInstall = useCallback(
|
||||||
(type: string) => {
|
async (type: string) => {
|
||||||
installMutation.mutate({ type });
|
const definition = available?.find((d) => d.type === type);
|
||||||
|
try {
|
||||||
|
const integration = await installMutation.mutateAsync({ type });
|
||||||
|
if (definition?.oauth?.connectionScope === 'workspace') {
|
||||||
|
const { authorizationUrl } = await getOAuthAuthorizeUrl({
|
||||||
|
integrationId: integration.id,
|
||||||
|
});
|
||||||
|
window.location.href = authorizationUrl;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// installMutation's onError already shows a notification
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[installMutation],
|
[installMutation, available],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleUninstall = useCallback(
|
const handleUninstall = useCallback(
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
export type IntegrationCapability = "oauth" | "unfurl" | "actions" | "webhooks";
|
export type IntegrationCapability = "oauth" | "unfurl" | "actions" | "webhooks";
|
||||||
|
|
||||||
|
export type OAuthConfig = {
|
||||||
|
authUrl: string;
|
||||||
|
tokenUrl: string;
|
||||||
|
scopes: string[];
|
||||||
|
connectionScope?: 'workspace' | 'user';
|
||||||
|
};
|
||||||
|
|
||||||
export type IntegrationDefinition = {
|
export type IntegrationDefinition = {
|
||||||
type: string;
|
type: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
capabilities: IntegrationCapability[];
|
capabilities: IntegrationCapability[];
|
||||||
|
oauth?: OAuthConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Integration = {
|
export type Integration = {
|
||||||
|
|||||||
Reference in New Issue
Block a user