diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eeacf2aa..708a31715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v0.59.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.58.0...v0.59.0) + +- feat(tiptap): allow inserting of embed code using a modal [`#1658`](https://github.com/isomerpages/isomercms-frontend/pull/1658) +- feat(tiptap): rm redundant logos [`#1679`](https://github.com/isomerpages/isomercms-frontend/pull/1679) +- Fix/is 689 reuse image/album tiles [`#1678`](https://github.com/isomerpages/isomercms-frontend/pull/1678) +- Fix/is724-apply-styles [`#1677`](https://github.com/isomerpages/isomercms-frontend/pull/1677) +- fix(editor): refactor to use `tooltip` [`#1669`](https://github.com/isomerpages/isomercms-frontend/pull/1669) +- release/0.58.0 [`#1675`](https://github.com/isomerpages/isomercms-frontend/pull/1675) + #### [v0.58.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.57.0...v0.58.0) +> 14 November 2023 + - fix(markdown): update styling to remove overflow [`#1671`](https://github.com/isomerpages/isomercms-frontend/pull/1671) - feat/addReportingBUtton [`#1674`](https://github.com/isomerpages/isomercms-frontend/pull/1674) - feat(media): add announcements and feature tour for media enhancements [`#1632`](https://github.com/isomerpages/isomercms-frontend/pull/1632) diff --git a/package-lock.json b/package-lock.json index 9d4768f6c..a28ded033 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isomercms-frontend", - "version": "0.58.0", + "version": "0.59.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isomercms-frontend", - "version": "0.58.0", + "version": "0.59.0", "hasInstallScript": true, "dependencies": { "@braintree/sanitize-url": "^6.0.1", diff --git a/package.json b/package.json index 046dd4543..e37f58c10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isomercms-frontend", - "version": "0.58.0", + "version": "0.59.0", "private": true, "engines": { "node": ">=16.0.0" diff --git a/src/components/EditorEmbedModal/EditorEmbedModal.stories.tsx b/src/components/EditorEmbedModal/EditorEmbedModal.stories.tsx new file mode 100644 index 000000000..a93e34b6d --- /dev/null +++ b/src/components/EditorEmbedModal/EditorEmbedModal.stories.tsx @@ -0,0 +1,41 @@ +import { useDisclosure } from "@chakra-ui/react" +import { Button } from "@opengovsg/design-system-react" +import type { Meta, StoryFn } from "@storybook/react" + +import { useSuccessToast } from "utils" + +import { EditorEmbedModal } from "./EditorEmbedModal" + +const editorEmbedModalMeta = { + title: "Components/Editor/Embed Modal", + component: EditorEmbedModal, +} as Meta + +const editorEmbedModalTemplate: StoryFn = () => { + const { isOpen, onOpen, onClose } = useDisclosure({ defaultIsOpen: true }) + const successToast = useSuccessToast() + const onProceed = () => { + successToast({ + id: "storybook-editor-embed-success", + description: "STORYBOOK: Embed has been successfully added", + }) + onClose() + } + + return ( + <> + + + + ) +} + +export const Default = editorEmbedModalTemplate.bind({}) +Default.args = {} + +export default editorEmbedModalMeta diff --git a/src/components/EditorEmbedModal/EditorEmbedModal.tsx b/src/components/EditorEmbedModal/EditorEmbedModal.tsx new file mode 100644 index 000000000..fcfe809ea --- /dev/null +++ b/src/components/EditorEmbedModal/EditorEmbedModal.tsx @@ -0,0 +1,185 @@ +import { + FormControl, + HStack, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + ModalOverlay, + Text, + Textarea, +} from "@chakra-ui/react" +import { yupResolver } from "@hookform/resolvers/yup" +import { + Button, + FormErrorMessage, + FormLabel, + Link, + ModalCloseButton, +} from "@opengovsg/design-system-react" +import * as Cheerio from "cheerio" +import { useEffect } from "react" +import { FormProvider, useForm } from "react-hook-form" +import * as Yup from "yup" + +import { useCspHook } from "hooks/settingsHooks" + +import { isEmbedCodeValid } from "utils/allowedHTML" + +import { EditorEmbedContents } from "types/editPage" + +interface EditorEmbedModalProps { + isOpen: boolean + onClose: () => void + onProceed: (embedCode: EditorEmbedContents) => void + cursorValue: string +} + +export const EditorEmbedModal = ({ + isOpen, + onClose, + onProceed, + cursorValue, +}: EditorEmbedModalProps): JSX.Element => { + const { data: csp } = useCspHook() + + const handleSubmit = (embedCode: EditorEmbedContents) => { + const { value } = embedCode + const $ = Cheerio.load(value) + + if ($("blockquote").hasClass("instagram-media")) { + const postUrl = $(".instagram-media").attr("data-instgrm-permalink") + const url = document.createElement("a") + url.href = postUrl || "" + const code = `` + onProceed({ value: code }) + } else if ($('iframe[src^="https://form.gov.sg"]').length > 0) { + // We only want to keep the