mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
* Update Switch component onChange handler to use boolean callback - Remove synthetic event handling from Switch component - Update onChange signature to (checked: boolean) => void - Update all call points across the codebase: - PublicAccess.tsx: Updated handlers for indexing, showLastModified, and published switches - Security.tsx: Created individual handlers for all security preferences - Preferences.tsx: Created individual handlers for user preferences - CollectionForm.tsx: Added createSwitchRegister helper for react-hook-form compatibility - TemplatizeDialog: Updated publish handler - DocumentMenu.tsx: Added handlers for embeds and full-width toggles - Search.tsx: Updated SearchTitlesFilter handler - Application.tsx: Added createSwitchRegister helper - Details.tsx: Updated public branding handler - Features.tsx: Created individual handlers for seamless edit and commenting - OAuthClientForm.tsx: Added createSwitchRegister helper - Maintained backward compatibility with react-hook-form - Improved type safety and code clarity * Fix ESLint floating promise errors - Add void operator to onChange call in CollectionForm.tsx - Add void operator to document.save call in DocumentMenu.tsx These changes fix the @typescript-eslint/no-floating-promises errors while maintaining the existing functionality. * Fix Switch component onChange handlers in remaining files - Updated DocumentCopy.tsx handlers to use boolean parameter - Updated Notifications.tsx to use closure pattern for event types - Updated SlackListItem.tsx to use closure pattern for event names - All TypeScript errors resolved * Refactor createSwitchRegister into utils/forms - Created shared utility function in app/utils/forms.ts - Removed duplicate implementations from CollectionForm, Application, and OAuthClientForm - Updated all usage points to use the shared utility - Improved TypeScript typing with Record<string, unknown> - Fixed imports and removed unused variables - Maintained existing functionality while reducing code duplication * Fix TypeScript errors in createSwitchRegister utility - Updated generic constraint from Record<string, unknown> to FieldValues - Added Path import from react-hook-form for proper type safety - Fixed parameter type from keyof TFormData to Path<TFormData> - Improved type compatibility with react-hook-form's UseFormRegister Resolves TypeScript compilation errors in CI pipeline. * Remove unnecessary handlePublishChange callbacks - Removed handlePublishChange wrapper in DocumentCopy.tsx - Removed handlePublishChange wrapper in TemplatizeDialog/index.tsx - Updated Switch components to use setPublish directly - Simplified code by leveraging boolean callback from Switch component Since Switch now passes boolean directly, no need for intermediate callbacks. * Address review feedback: simplify callbacks and fix fullWidth behavior 1. DocumentCopy.tsx: - Remove handleRecursiveChange callback wrapper - Use setRecursive directly with Switch component 2. DocumentMenu.tsx: - Add void user.save() to persist user preference - Add document.fullWidth = checked for optimistic update behavior Both changes leverage the boolean callback from Switch component properly. * Update Security.tsx * i18n --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import uniq from "lodash/uniq";
|
|
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
import { usePopoverState, PopoverDisclosure } from "reakit/Popover";
|
|
import { toast } from "sonner";
|
|
import styled from "styled-components";
|
|
import { s } from "@shared/styles";
|
|
import { IntegrationType } from "@shared/types";
|
|
import Collection from "~/models/Collection";
|
|
import Integration from "~/models/Integration";
|
|
import { ConnectedButton } from "~/scenes/Settings/components/ConnectedButton";
|
|
import ButtonLink from "~/components/ButtonLink";
|
|
import Flex from "~/components/Flex";
|
|
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
|
import ListItem from "~/components/List/Item";
|
|
import Popover from "~/components/Popover";
|
|
import Switch from "~/components/Switch";
|
|
import Text from "~/components/Text";
|
|
|
|
type Props = {
|
|
integration: Integration<IntegrationType.Post>;
|
|
collection: Collection;
|
|
};
|
|
|
|
function SlackListItem({ integration, collection }: Props) {
|
|
const { t } = useTranslation();
|
|
|
|
const handleChange = (eventName: string) => async (checked: boolean) => {
|
|
if (checked) {
|
|
integration.events = uniq([...integration.events, eventName]);
|
|
} else {
|
|
integration.events = integration.events.filter((n) => n !== eventName);
|
|
}
|
|
|
|
await integration.save();
|
|
|
|
toast.success(t("Settings saved"));
|
|
};
|
|
|
|
const mapping: Record<string, string> = {
|
|
"documents.publish": t("document published"),
|
|
"documents.update": t("document updated"),
|
|
};
|
|
|
|
const popover = usePopoverState({
|
|
gutter: 0,
|
|
placement: "bottom-start",
|
|
});
|
|
|
|
return (
|
|
<ListItem
|
|
key={integration.id}
|
|
title={
|
|
<Flex align="center" gap={6}>
|
|
<CollectionIcon collection={collection} /> {collection.name}
|
|
</Flex>
|
|
}
|
|
subtitle={
|
|
<>
|
|
<Trans
|
|
defaults={`Posting to the <em>{{ channelName }}</em> channel on`}
|
|
values={{
|
|
channelName: integration.settings.channel,
|
|
events: integration.events.map((ev) => mapping[ev]).join(", "),
|
|
}}
|
|
components={{
|
|
em: <strong />,
|
|
}}
|
|
/>{" "}
|
|
<PopoverDisclosure {...popover}>
|
|
{(props) => (
|
|
<ButtonLink {...props}>
|
|
{integration.events.map((ev) => mapping[ev]).join(", ")}
|
|
</ButtonLink>
|
|
)}
|
|
</PopoverDisclosure>
|
|
<Popover {...popover} aria-label={t("Settings")}>
|
|
<Events>
|
|
<h3>{t("Notifications")}</h3>
|
|
<Text as="p" type="secondary">
|
|
{t("These events should be posted to Slack")}
|
|
</Text>
|
|
<Switch
|
|
label={t("Document published")}
|
|
name="documents.publish"
|
|
checked={integration.events.includes("documents.publish")}
|
|
onChange={handleChange("documents.publish")}
|
|
/>
|
|
<Switch
|
|
label={t("Document updated")}
|
|
name="documents.update"
|
|
checked={integration.events.includes("documents.update")}
|
|
onChange={handleChange("documents.update")}
|
|
/>
|
|
</Events>
|
|
</Popover>
|
|
</>
|
|
}
|
|
actions={
|
|
<ConnectedButton
|
|
onClick={integration.delete}
|
|
confirmationMessage={t(
|
|
"This will prevent any future updates from being posted to this Slack channel. Are you sure?"
|
|
)}
|
|
/>
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const Events = styled.div`
|
|
color: ${s("text")};
|
|
margin-top: -12px;
|
|
`;
|
|
|
|
export default observer(SlackListItem);
|