mirror of
https://github.com/outline/outline.git
synced 2026-12-02 01:34:47 +03:00
update useSettings
This commit is contained in:
1 parent
adcab68b59
commit
b48498d07f
3 files changed
+157
-1
No files matched your search
@@ -0,0 +1,122 @@
|
||||
import * as React from "react";
|
||||
import styled, { useTheme } from "styled-components";
|
||||
import Icon from "@shared/components/Icon";
|
||||
import Squircle from "@shared/components/Squircle";
|
||||
import { s, hover, ellipsis } from "@shared/styles";
|
||||
import Button from "~/components/ActionButton";
|
||||
|
||||
export type Integration = {
|
||||
id: string;
|
||||
name: string;
|
||||
icon?: string;
|
||||
description: string;
|
||||
isActive: boolean;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
integration: Integration;
|
||||
onInstall: (id: string) => void;
|
||||
onConfigure: (id: string) => void;
|
||||
};
|
||||
|
||||
const IntegrationCard: React.FC<Props> = ({
|
||||
integration,
|
||||
onInstall,
|
||||
onConfigure,
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<IconWrapper>
|
||||
{integration.icon ? (
|
||||
<Squircle color={theme.slateLight}>
|
||||
<Icon value={integration.icon} size={24} />
|
||||
</Squircle>
|
||||
) : (
|
||||
<Squircle color={theme.slateLight}>
|
||||
<Icon value="puzzle" size={24} />
|
||||
</Squircle>
|
||||
)}
|
||||
</IconWrapper>
|
||||
<Content>
|
||||
<Name>{integration.name}</Name>
|
||||
<Description>{integration.description}</Description>
|
||||
</Content>
|
||||
<Footer>
|
||||
<Status isActive={integration.isActive}>
|
||||
{integration.isActive ? "isActive" : "Not isActive"}
|
||||
</Status>
|
||||
{integration.isActive ? (
|
||||
<ActionButton onClick={() => onConfigure(integration.id)}>
|
||||
Configure
|
||||
</ActionButton>
|
||||
) : (
|
||||
<ActionButton onClick={() => onInstall(integration.id)}>
|
||||
Install
|
||||
</ActionButton>
|
||||
)}
|
||||
</Footer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default IntegrationCard;
|
||||
|
||||
const Card = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 12px;
|
||||
width: 200px;
|
||||
height: 220px;
|
||||
background: ${s("background")};
|
||||
border: 1px solid ${s("inputBorder")};
|
||||
border-radius: 8px;
|
||||
transition: box-shadow 200ms ease;
|
||||
cursor: pointer;
|
||||
|
||||
&: ${hover} {
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
`;
|
||||
|
||||
const IconWrapper = styled.div`
|
||||
margin-bottom: 12px;
|
||||
`;
|
||||
|
||||
const Content = styled.div`
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
`;
|
||||
|
||||
const Name = styled.h3`
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
color: ${s("text")};
|
||||
${ellipsis()}
|
||||
`;
|
||||
|
||||
const Description = styled.p`
|
||||
margin: 4px 0 0;
|
||||
font-size: 14px;
|
||||
color: ${s("textTertiary")};
|
||||
${ellipsis()}
|
||||
`;
|
||||
|
||||
const Footer = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 16px;
|
||||
`;
|
||||
|
||||
const Status = styled.span<{ isActive: boolean }>`
|
||||
font-size: 12px;
|
||||
color: ${(props) =>
|
||||
props.isActive ? props.theme.success : props.theme.danger};
|
||||
`;
|
||||
|
||||
const ActionButton = styled(Button)`
|
||||
padding: 4px 8px;
|
||||
font-size: 14px;
|
||||
`;
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
import React, { ComponentProps } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { integrationSettingsPath } from "@shared/utils/routeHelpers";
|
||||
import { Integrations } from "~/scenes/Settings/Integrations";
|
||||
import ZapierIcon from "~/components/Icons/ZapierIcon";
|
||||
import { Hook, PluginManager } from "~/utils/PluginManager";
|
||||
import isCloudHosted from "~/utils/isCloudHosted";
|
||||
@@ -26,6 +27,7 @@ import { useComputed } from "./useComputed";
|
||||
import useCurrentTeam from "./useCurrentTeam";
|
||||
import useCurrentUser from "./useCurrentUser";
|
||||
import usePolicy from "./usePolicy";
|
||||
import useStores from "./useStores";
|
||||
|
||||
const ApiKeys = lazy(() => import("~/scenes/Settings/ApiKeys"));
|
||||
const PersonalApiKeys = lazy(() => import("~/scenes/Settings/PersonalApiKeys"));
|
||||
@@ -50,14 +52,20 @@ export type ConfigItem = {
|
||||
component: React.ComponentType;
|
||||
enabled: boolean;
|
||||
group: string;
|
||||
isActive?: boolean;
|
||||
};
|
||||
|
||||
const useSettingsConfig = () => {
|
||||
const { integrations } = useStores();
|
||||
const user = useCurrentUser();
|
||||
const team = useCurrentTeam();
|
||||
const can = usePolicy(team);
|
||||
const { t } = useTranslation();
|
||||
|
||||
React.useEffect(() => {
|
||||
void integrations.fetchAll();
|
||||
}, [integrations]);
|
||||
|
||||
const config = useComputed(() => {
|
||||
const items: ConfigItem[] = [
|
||||
// Account
|
||||
@@ -183,6 +191,15 @@ const useSettingsConfig = () => {
|
||||
group: t("Integrations"),
|
||||
icon: ZapierIcon,
|
||||
},
|
||||
{
|
||||
name: "All Integrations",
|
||||
path: integrationSettingsPath("all"),
|
||||
component: Integrations,
|
||||
enabled: true,
|
||||
group: t("Integrations"),
|
||||
icon: ZapierIcon,
|
||||
isActive: true,
|
||||
},
|
||||
];
|
||||
|
||||
// Plugins
|
||||
@@ -203,13 +220,20 @@ const useSettingsConfig = () => {
|
||||
? plugin.value.enabled(team, user)
|
||||
: can.update,
|
||||
icon: plugin.value.icon,
|
||||
isActive: integrations.orderedData.some(
|
||||
(integration) =>
|
||||
integration.service.toLowerCase() === plugin.name.toLowerCase()
|
||||
),
|
||||
} as ConfigItem);
|
||||
});
|
||||
|
||||
return items;
|
||||
}, [t, can.createApiKey, can.update, can.createImport, can.createExport]);
|
||||
|
||||
return config.filter((item) => item.enabled);
|
||||
return config.filter(
|
||||
(item) =>
|
||||
item.enabled && (item.group === "Integrations" ? item.isActive : true)
|
||||
);
|
||||
};
|
||||
|
||||
export default useSettingsConfig;
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from "react";
|
||||
|
||||
export function Integrations() {
|
||||
return (
|
||||
<div>
|
||||
<h1>Integrations</h1>
|
||||
<p>Integrations settings will be available here.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user