From 43c99f403318b1f706b35778b606517dfdd0d09e Mon Sep 17 00:00:00 2001 From: hmacr Date: Thu, 27 Jun 2024 04:02:41 +0530 Subject: [PATCH] review --- app/actions/definitions/documents.tsx | 4 +- app/components/TemplatizeDialog/Label.tsx | 22 ++++ .../TemplatizeDialog/SelectLocation.tsx | 124 ++++++++++++++++++ .../index.tsx} | 49 +++---- app/menus/NewTemplateMenu.tsx | 25 ++-- app/menus/TemplatesMenu.tsx | 51 ++----- app/models/Document.ts | 21 +-- app/scenes/DocumentMove.tsx | 10 +- app/stores/DocumentsStore.ts | 43 +++--- server/routes/api/documents/documents.test.ts | 91 ++++++++----- server/routes/api/documents/documents.ts | 22 +++- server/routes/api/documents/schema.ts | 19 +-- shared/i18n/locales/en_US/translation.json | 12 +- 13 files changed, 313 insertions(+), 180 deletions(-) create mode 100644 app/components/TemplatizeDialog/Label.tsx create mode 100644 app/components/TemplatizeDialog/SelectLocation.tsx rename app/components/{DocumentTemplatizeDialog.tsx => TemplatizeDialog/index.tsx} (72%) diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index 4271ce2418..68ccd3778f 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -37,10 +37,10 @@ import DocumentMove from "~/scenes/DocumentMove"; import DocumentPermanentDelete from "~/scenes/DocumentPermanentDelete"; import DocumentPublish from "~/scenes/DocumentPublish"; import DeleteDocumentsInTrash from "~/scenes/Trash/components/DeleteDocumentsInTrash"; -import DocumentTemplatizeDialog from "~/components/DocumentTemplatizeDialog"; import DuplicateDialog from "~/components/DuplicateDialog"; import SharePopover from "~/components/Sharing/Document"; import { getHeaderExpandedKey } from "~/components/Sidebar/components/Header"; +import DocumentTemplatizeDialog from "~/components/TemplatizeDialog"; import { createAction } from "~/actions"; import { DocumentSection, TrashSection } from "~/actions/sections"; import env from "~/env"; @@ -758,7 +758,7 @@ export const moveTemplateToWorkspace = createAction({ } await document.move({ - template: true, + collectionId: null, }); } }, diff --git a/app/components/TemplatizeDialog/Label.tsx b/app/components/TemplatizeDialog/Label.tsx new file mode 100644 index 0000000000..c211b87d3e --- /dev/null +++ b/app/components/TemplatizeDialog/Label.tsx @@ -0,0 +1,22 @@ +import React from "react"; +import styled from "styled-components"; +import Flex from "~/components/Flex"; + +const Label = ({ icon, value }: { icon: React.ReactNode; value: string }) => ( + + {icon} + {value} + +); + +const IconWrapper = styled.span` + display: flex; + justify-content: center; + align-items: center; + height: 24px; + width: 24px; + overflow: hidden; + flex-shrink: 0; +`; + +export default Label; diff --git a/app/components/TemplatizeDialog/SelectLocation.tsx b/app/components/TemplatizeDialog/SelectLocation.tsx new file mode 100644 index 0000000000..11a612d28f --- /dev/null +++ b/app/components/TemplatizeDialog/SelectLocation.tsx @@ -0,0 +1,124 @@ +import React, { useState } from "react"; +import { useTranslation } from "react-i18next"; +import { toast } from "sonner"; +import styled from "styled-components"; +import { AvatarSize } from "~/components/Avatar/Avatar"; +import CollectionIcon from "~/components/Icons/CollectionIcon"; +import InputSelect, { Option } from "~/components/InputSelect"; +import TeamLogo from "~/components/TeamLogo"; +import useCurrentTeam from "~/hooks/useCurrentTeam"; +import usePolicy from "~/hooks/usePolicy"; +import useStores from "~/hooks/useStores"; +import Label from "./Label"; + +type Props = { + id: string; + defaultCollectionId?: string | null; + onSelect: (collectionId: string | null) => void; +}; + +const SelectLocation = ({ id, defaultCollectionId, onSelect }: Props) => { + const { t } = useTranslation(); + const team = useCurrentTeam(); + const { collections, policies } = useStores(); + const can = usePolicy(team); + const [fetching, setFetching] = useState(false); + const [fetchError, setFetchError] = useState(); + + const workspaceOption: Option | null = can.createDocument + ? { + label: ( +