From e0c6badcfd1d16e70cc4b6e00155022e1e0a21ed Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:45:51 +0800 Subject: [PATCH 1/7] fix(updateLinkModal): update link + proper default (#1692) --- .../Editor/components/LinkBubbleMenu.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/layouts/components/Editor/components/LinkBubbleMenu.tsx b/src/layouts/components/Editor/components/LinkBubbleMenu.tsx index ff52117de..031a0cb16 100644 --- a/src/layouts/components/Editor/components/LinkBubbleMenu.tsx +++ b/src/layouts/components/Editor/components/LinkBubbleMenu.tsx @@ -11,6 +11,7 @@ import { } from "@chakra-ui/react" import { Button, FormErrorMessage, Input } from "@opengovsg/design-system-react" import { BubbleMenu } from "@tiptap/react" +import { useEffect } from "react" import { useForm } from "react-hook-form" import { useEditorContext } from "contexts/EditorContext" @@ -20,28 +21,36 @@ const LinkButton = () => { const { editor } = useEditorContext() const { onClose, onOpen, isOpen } = useDisclosure() const { showModal } = useEditorModal() - const { register, watch, formState: { errors, isValid }, + setValue, } = useForm({ mode: "onTouched", defaultValues: { - href: (editor.getAttributes("link").href as string) || "", + href: "", // we don't set default values here since this does not change on component re-open }, }) + + useEffect(() => { + // set default values here instead + const { href } = editor.getAttributes("link") + setValue("href", href) + // only done once per every time the modal is opened + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isOpen]) + const href = watch("href") + const onSubmit = () => { if (href) { editor .chain() - .focus() + .extendMarkRange("link") // NOTE: Force `https` by default .setLink({ href }) .run() - } else { - editor.chain().focus().unsetLink().run() } onClose() } From aa0f11189a18dacaa126c0ed33be8ce1faea8e26 Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:05:20 +0800 Subject: [PATCH 2/7] feat(tiptap): add Instagram embed proper node handler (#1688) --- .../EditorEmbedModal/EditorEmbedModal.tsx | 15 +- src/layouts/EditPage/EditPage.tsx | 2 + .../Editor/extensions/Instagram/Instagram.ts | 308 ++++++++++++++++++ .../extensions/Instagram/InstagramView.tsx | 33 ++ .../Editor/extensions/Instagram/index.ts | 1 + .../components/Editor/extensions/index.ts | 1 + 6 files changed, 347 insertions(+), 13 deletions(-) create mode 100644 src/layouts/components/Editor/extensions/Instagram/Instagram.ts create mode 100644 src/layouts/components/Editor/extensions/Instagram/InstagramView.tsx create mode 100644 src/layouts/components/Editor/extensions/Instagram/index.ts diff --git a/src/components/EditorEmbedModal/EditorEmbedModal.tsx b/src/components/EditorEmbedModal/EditorEmbedModal.tsx index 9ea0b78ce..ad5bd6df7 100644 --- a/src/components/EditorEmbedModal/EditorEmbedModal.tsx +++ b/src/components/EditorEmbedModal/EditorEmbedModal.tsx @@ -18,7 +18,6 @@ import { 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" @@ -45,18 +44,7 @@ export const EditorEmbedModal = ({ 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 { - onProceed(embedCode) - } + onProceed(embedCode) } const methods = useForm({ @@ -92,6 +80,7 @@ export const EditorEmbedModal = ({ cursorValue .replace('
', "") .replace('
', "") + .replace('
', "") // Remove the closing div tag .slice(0, -6) ) diff --git a/src/layouts/EditPage/EditPage.tsx b/src/layouts/EditPage/EditPage.tsx index 2034cf659..f5d2c117a 100644 --- a/src/layouts/EditPage/EditPage.tsx +++ b/src/layouts/EditPage/EditPage.tsx @@ -35,6 +35,7 @@ import { FormSGIframe, Iframe, IsomerImage, + Instagram, } from "layouts/components/Editor/extensions" import { isEmbedCodeValid } from "utils/allowedHTML" @@ -78,6 +79,7 @@ export const EditPage = () => { FormSG, FormSGDiv, FormSGIframe, + Instagram, Markdown, BubbleMenu.configure({ pluginKey: "linkBubble", diff --git a/src/layouts/components/Editor/extensions/Instagram/Instagram.ts b/src/layouts/components/Editor/extensions/Instagram/Instagram.ts new file mode 100644 index 000000000..3b1c0bab6 --- /dev/null +++ b/src/layouts/components/Editor/extensions/Instagram/Instagram.ts @@ -0,0 +1,308 @@ +import { Node } from "@tiptap/core" +import { ReactNodeViewRenderer } from "@tiptap/react" + +import { InstagramView } from "./InstagramView" + +export interface InstagramOption { + HTMLAttributes: { + class: string + } +} + +declare module "@tiptap/core" { + interface Commands { + instagram: { + /** + * Add an Instagram embed + */ + setInstagram: (options: { + postUrl: string + caption: string + }) => ReturnType + } + } +} + +export const Instagram = Node.create({ + name: "instagram", + group: "block", + atom: true, + draggable: true, + defining: true, + priority: 300, + + addAttributes() { + return { + class: { + default: "instagram-media", + }, + "data-instgrm-captioned": { + default: null, + }, + "data-instgrm-permalink": { + default: null, + }, + "data-instgrm-version": { + default: "14", + }, + style: { + default: null, + }, + caption: { + default: "", + parseHTML: (element) => + element.querySelector('p > a[href^="https://www.instagram.com/"]') + ?.textContent ?? "", + }, + permalink: { + default: "", + parseHTML: (element) => element.getAttribute("data-instgrm-permalink"), + }, + } + }, + + parseHTML() { + return [ + { + tag: "blockquote[data-instgrm-permalink]", + }, + ] + }, + + renderHTML({ HTMLAttributes }) { + const { caption, permalink, src, ...rest } = HTMLAttributes + + return [ + "div", + { class: "instagram-wrapper" }, + [ + "blockquote", + rest, + [ + "div", + { style: "padding: 16px;" }, + [ + "a", + { + href: permalink, + style: + "background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;", + }, + [ + "div", + { + style: + "display: flex; flex-direction: row; align-items: center;", + }, + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;", + }, + ], + [ + "div", + { + style: + "display: flex; flex-direction: column; flex-grow: 1; justify-content: center;", + }, + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;", + }, + ], + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;", + }, + ], + ], + ], + ["div", { style: "padding: 19% 0;" }], + [ + "div", + { + style: + "display:block; height:50px; margin:0 auto 12px; width:50px;", + }, + [ + "svg", + { + width: "50px", + height: "50px", + viewBox: "0 0 60 60", + version: "1.1", + xmlns: "https://www.w3.org/2000/svg", + "xmlns:xlink": "https://www.w3.org/1999/xlink", + }, + [ + "g", + { + stroke: "none", + "stroke-width": "1", + fill: "none", + "fill-rule": "evenodd", + }, + [ + "g", + { + transform: "translate(-511.000000, -20.000000)", + fill: "#000000", + }, + [ + "g", + {}, + [ + "path", + { + d: + "M556.869,30.41 C554.814,30.41 553.148,32.076 553.148,34.131 C553.148,36.186 554.814,37.852 556.869,37.852 C558.924,37.852 560.59,36.186 560.59,34.131 C560.59,32.076 558.924,30.41 556.869,30.41 M541,60.657 C535.114,60.657 530.342,55.887 530.342,50 C530.342,44.114 535.114,39.342 541,39.342 C546.887,39.342 551.658,44.114 551.658,50 C551.658,55.887 546.887,60.657 541,60.657 M541,33.886 C532.1,33.886 524.886,41.1 524.886,50 C524.886,58.899 532.1,66.113 541,66.113 C549.9,66.113 557.115,58.899 557.115,50 C557.115,41.1 549.9,33.886 541,33.886 M565.378,62.101 C565.244,65.022 564.756,66.606 564.346,67.663 C563.803,69.06 563.154,70.057 562.106,71.106 C561.058,72.155 560.06,72.803 558.662,73.347 C557.607,73.757 556.021,74.244 553.102,74.378 C549.944,74.521 548.997,74.552 541,74.552 C533.003,74.552 532.056,74.521 528.898,74.378 C525.979,74.244 524.393,73.757 523.338,73.347 C521.94,72.803 520.942,72.155 519.894,71.106 C518.846,70.057 518.197,69.06 517.654,67.663 C517.244,66.606 516.755,65.022 516.623,62.101 C516.479,58.943 516.448,57.996 516.448,50 C516.448,42.003 516.479,41.056 516.623,37.899 C516.755,34.978 517.244,33.391 517.654,32.338 C518.197,30.938 518.846,29.942 519.894,28.894 C520.942,27.846 521.94,27.196 523.338,26.654 C524.393,26.244 525.979,25.756 528.898,25.623 C532.057,25.479 533.004,25.448 541,25.448 C548.997,25.448 549.943,25.479 553.102,25.623 C556.021,25.756 557.607,26.244 558.662,26.654 C560.06,27.196 561.058,27.846 562.106,28.894 C563.154,29.942 563.803,30.938 564.346,32.338 C564.756,33.391 565.244,34.978 565.378,37.899 C565.522,41.056 565.552,42.003 565.552,50 C565.552,57.996 565.522,58.943 565.378,62.101 M570.82,37.631 C570.674,34.438 570.167,32.258 569.425,30.349 C568.659,28.377 567.633,26.702 565.965,25.035 C564.297,23.368 562.623,22.342 560.652,21.575 C558.743,20.834 556.562,20.326 553.369,20.18 C550.169,20.033 549.148,20 541,20 C532.853,20 531.831,20.033 528.631,20.18 C525.438,20.326 523.257,20.834 521.349,21.575 C519.376,22.342 517.703,23.368 516.035,25.035 C514.368,26.702 513.342,28.377 512.574,30.349 C511.834,32.258 511.326,34.438 511.181,37.631 C511.035,40.831 511,41.851 511,50 C511,58.147 511.035,59.17 511.181,62.369 C511.326,65.562 511.834,67.743 512.574,69.651 C513.342,71.625 514.368,73.296 516.035,74.965 C517.703,76.634 519.376,77.658 521.349,78.425 C523.257,79.167 525.438,79.673 528.631,79.82 C531.831,79.965 532.853,80.001 541,80.001 C549.148,80.001 550.169,79.965 553.369,79.82 C556.562,79.673 558.743,79.167 560.652,78.425 C562.623,77.658 564.297,76.634 565.965,74.965 C567.633,73.296 568.659,71.625 569.425,69.651 C570.167,67.743 570.674,65.562 570.82,62.369 C570.966,59.17 571,58.147 571,50 C571,41.851 570.966,40.831 570.82,37.631", + }, + ], + ], + ], + ], + ], + ], + [ + "div", + { style: "padding-top: 8px;" }, + [ + "div", + { + style: + "color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;", + }, + "View this post on Instagram", + ], + ], + ["div", { style: "padding: 12.5% 0;" }], + [ + "div", + { + style: + "display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;", + }, + [ + "div", + {}, + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);", + }, + ], + [ + "div", + { + style: + "background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;", + }, + ], + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);", + }, + ], + ], + [ + "div", + { style: "margin-left: 8px;" }, + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;", + }, + ], + [ + "div", + { + style: + "width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)", + }, + ], + ], + [ + "div", + { style: "margin-left: auto;" }, + [ + "div", + { + style: + "width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);", + }, + ], + [ + "div", + { + style: + "background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);", + }, + ], + [ + "div", + { + style: + "width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);", + }, + ], + ], + ], + [ + "div", + { + style: + "display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;", + }, + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;", + }, + ], + [ + "div", + { + style: + "background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;", + }, + ], + ], + ], + [ + "p", + { + style: + "color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;", + }, + [ + "a", + { + href: permalink, + style: + "color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;", + target: "_blank", + }, + caption, + ], + ], + ], + ], + ["script", { async: true, src: "//www.instagram.com/embed.js" }], + ] + }, + + addNodeView() { + return ReactNodeViewRenderer(InstagramView) + }, +}) diff --git a/src/layouts/components/Editor/extensions/Instagram/InstagramView.tsx b/src/layouts/components/Editor/extensions/Instagram/InstagramView.tsx new file mode 100644 index 000000000..5e54343fc --- /dev/null +++ b/src/layouts/components/Editor/extensions/Instagram/InstagramView.tsx @@ -0,0 +1,33 @@ +import { Box, Text } from "@chakra-ui/react" +import { NodeViewProps, NodeViewWrapper } from "@tiptap/react" + +export const InstagramView = ({ node }: NodeViewProps) => { + return ( + + + Instagram Post + + + {node.attrs.permalink} + + + ) +} diff --git a/src/layouts/components/Editor/extensions/Instagram/index.ts b/src/layouts/components/Editor/extensions/Instagram/index.ts new file mode 100644 index 000000000..599e45e36 --- /dev/null +++ b/src/layouts/components/Editor/extensions/Instagram/index.ts @@ -0,0 +1 @@ +export * from "./Instagram" diff --git a/src/layouts/components/Editor/extensions/index.ts b/src/layouts/components/Editor/extensions/index.ts index c48dbf107..7abec2abb 100644 --- a/src/layouts/components/Editor/extensions/index.ts +++ b/src/layouts/components/Editor/extensions/index.ts @@ -1,3 +1,4 @@ export * from "./Iframe" export * from "./FormSG" export * from "./Image" +export * from "./Instagram" From e3d899734f8d40d537550456ae73d3eb1c1e93ac Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:24:30 +0800 Subject: [PATCH 3/7] fix(images): ability to change img (#1694) --- src/layouts/EditPage/EditPage.tsx | 3 ++ src/layouts/components/Editor/Editor.tsx | 2 + .../Editor/components/ImageBubbleMenu.tsx | 42 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/layouts/components/Editor/components/ImageBubbleMenu.tsx diff --git a/src/layouts/EditPage/EditPage.tsx b/src/layouts/EditPage/EditPage.tsx index f5d2c117a..c89785a09 100644 --- a/src/layouts/EditPage/EditPage.tsx +++ b/src/layouts/EditPage/EditPage.tsx @@ -87,6 +87,9 @@ export const EditPage = () => { BubbleMenu.configure({ pluginKey: "tableBubble", }), + BubbleMenu.configure({ + pluginKey: "imageBubble", + }), Table.configure({ resizable: false, }), diff --git a/src/layouts/components/Editor/Editor.tsx b/src/layouts/components/Editor/Editor.tsx index e0a46a9e5..e13f6f81b 100644 --- a/src/layouts/components/Editor/Editor.tsx +++ b/src/layouts/components/Editor/Editor.tsx @@ -6,6 +6,7 @@ import { EditorContent } from "@tiptap/react" import { useEditorContext } from "contexts/EditorContext" import { LinkBubbleMenu, MenuBar, TableBubbleMenu } from "./components" +import { ImageBubbleMenu } from "./components/ImageBubbleMenu" export const Editor = (props: BoxProps) => { const { editor } = useEditorContext() @@ -22,6 +23,7 @@ export const Editor = (props: BoxProps) => { > + { + const { showModal } = useEditorModal() + + return ( + <> + + + ) +} + +export const ImageBubbleMenu = () => { + const { editor } = useEditorContext() + + return ( + editor.isActive("image")} + editor={editor} + tippyOptions={{ duration: 100 }} + > + + + ) +} From 9e0f4cbb947e988b5675f58577ce0a43149a3ee4 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 23 Nov 2023 12:50:16 +0800 Subject: [PATCH 4/7] Fix: stylesheet (#1696) --- src/utils/siteColorUtils.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/siteColorUtils.js b/src/utils/siteColorUtils.js index 369f04be7..17501f6dc 100644 --- a/src/utils/siteColorUtils.js +++ b/src/utils/siteColorUtils.js @@ -27,7 +27,14 @@ const getStyleSheet = (uniqueTitle) => { const createPageStyleSheet = (repoName, primaryColor, secondaryColor) => { const styleElement = document.createElement("style") - const styleTitle = `${repoName}-style` + const styleTitle = `custom-style` + const existingStyleElement = document.getElementById(styleTitle) + + // Remove existing stylesheet if it exists + if (existingStyleElement) { + existingStyleElement.parentNode.removeChild(existingStyleElement) + } + styleElement.setAttribute("id", styleTitle) styleElement.setAttribute("title", styleTitle) document.head.appendChild(styleElement) From 4174655a9df667fb6246575e96508b3b2cb6136f Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 23 Nov 2023 12:51:39 +0800 Subject: [PATCH 5/7] Fix/is 778 creating media in subfolder in select modal (#1695) * chore: increase height of modal * chore: move getMediaDirectoryName to ts * fix: retrieve passed params in mediaCreationModal * fix: media tab creation modal closes on proceed --- .../DirectorySettingsModal.jsx | 7 ++--- .../MediaCreationModal/MediaCreationModal.tsx | 24 ++++++++------- src/components/media/MediaModal.jsx | 2 +- src/components/media/MediasSelectModal.jsx | 7 +++-- .../directoryHooks/useDeleteDirectoryHook.jsx | 3 +- .../directoryHooks/useUpdateDirectoryHook.jsx | 3 +- src/hooks/directoryHooks/utils.ts | 3 +- src/layouts/screens/DeleteWarningScreen.jsx | 7 ++--- .../screens/DirectorySettingsScreen.jsx | 4 ++- src/layouts/screens/MediaCreationScreen.jsx | 10 ++----- src/services/DirectoryService.jsx | 4 ++- src/utils/legacy.js | 15 ---------- src/utils/media.ts | 29 +++++++++++++++++++ 13 files changed, 66 insertions(+), 52 deletions(-) diff --git a/src/components/DirectorySettingsModal/DirectorySettingsModal.jsx b/src/components/DirectorySettingsModal/DirectorySettingsModal.jsx index 4fb078886..525f67844 100644 --- a/src/components/DirectorySettingsModal/DirectorySettingsModal.jsx +++ b/src/components/DirectorySettingsModal/DirectorySettingsModal.jsx @@ -14,13 +14,10 @@ import { LoadingButton } from "components/LoadingButton" import elementStyles from "styles/isomer-cms/Elements.module.scss" import { getDirectorySettingsType } from "utils/directoryUtils" +import { getMediaDirectoryName } from "utils/media" import { isWriteActionsDisabled } from "utils/reviewRequests" -import { - deslugifyDirectory, - getLastItemType, - getMediaDirectoryName, -} from "utils" +import { deslugifyDirectory, getLastItemType } from "utils" import { DirectorySettingsSchema } from "./DirectorySettingsSchema" diff --git a/src/components/MediaCreationModal/MediaCreationModal.tsx b/src/components/MediaCreationModal/MediaCreationModal.tsx index a5e0c7fba..0eaa97df8 100644 --- a/src/components/MediaCreationModal/MediaCreationModal.tsx +++ b/src/components/MediaCreationModal/MediaCreationModal.tsx @@ -21,13 +21,12 @@ import _ from "lodash" import { useEffect, useState } from "react" import { FileRejection } from "react-dropzone" import { BiCheckCircle, BiSolidErrorCircle } from "react-icons/bi" -import { useParams } from "react-router-dom" import { Attachment } from "components/Attachment" import { useCreateMultipleMedia } from "hooks/mediaHooks/useCreateMultipleMedia" -import { getMediaLabels } from "utils/media" +import { getMediaDirectoryName, getMediaLabels } from "utils/media" import { MediaDirectoryParams } from "types/folders" import { MediaFolderTypes } from "types/media" @@ -280,12 +279,6 @@ const MediaUploadFailedDropzone = ({ ) } -interface MediaCreationModalProps { - onClose: () => void - onProceed: () => void - variant: MediaFolderTypes -} - interface MediaCreationRouteParams extends Omit< MediaDirectoryParams, @@ -295,14 +288,25 @@ interface MediaCreationRouteParams mediaDirectoryName?: string } +interface MediaCreationModalProps { + params: MediaCreationRouteParams + onClose: () => void + onProceed: () => void + variant: MediaFolderTypes +} + export const MediaCreationModal = ({ + params, onClose, onProceed, variant, }: MediaCreationModalProps) => { const { onClose: onModalClose } = useDisclosure() - const params = useParams() - const { siteName, mediaDirectoryName } = params + const { siteName, mediaDirectoryName: rawMediaDirectoryName } = params + const mediaDirectoryName = `${getMediaDirectoryName( + rawMediaDirectoryName || "", + { splitOn: "/" } + )}` const { mutateAsync: uploadFiles, diff --git a/src/components/media/MediaModal.jsx b/src/components/media/MediaModal.jsx index a922837dd..0bbf6f889 100644 --- a/src/components/media/MediaModal.jsx +++ b/src/components/media/MediaModal.jsx @@ -9,7 +9,7 @@ import { MediaAltText } from "components/media/MediaAltText" import MediasSelectModal from "components/media/MediasSelectModal" import { MediaCreationModal } from "components/MediaCreationModal/MediaCreationModal" -import { getMediaDirectoryName } from "utils" +import { getMediaDirectoryName } from "utils/media" const MediaModal = ({ onClose, onProceed, type, showAltTextModal = false }) => { const { diff --git a/src/components/media/MediasSelectModal.jsx b/src/components/media/MediasSelectModal.jsx index b3d3cf57c..cc98c1158 100644 --- a/src/components/media/MediasSelectModal.jsx +++ b/src/components/media/MediasSelectModal.jsx @@ -41,9 +41,9 @@ import { FilePreviewCard, MediaDirectoryCard } from "layouts/Media/components" import mediaStyles from "styles/isomer-cms/pages/Media.module.scss" -import { getMediaLabels } from "utils/media" +import { getMediaDirectoryName, getMediaLabels } from "utils/media" -import { deslugifyDirectory, getMediaDirectoryName } from "utils" +import { deslugifyDirectory } from "utils" const filterMediaByFileName = (medias, filterTerm) => medias.filter((media) => @@ -135,9 +135,10 @@ const MediasSelectModal = ({ size="6xl" scrollBehavior="inside" closeOnOverlayClick={false} + isCentered > - + diff --git a/src/hooks/directoryHooks/useDeleteDirectoryHook.jsx b/src/hooks/directoryHooks/useDeleteDirectoryHook.jsx index 9b52d7bdc..1d9b7504e 100644 --- a/src/hooks/directoryHooks/useDeleteDirectoryHook.jsx +++ b/src/hooks/directoryHooks/useDeleteDirectoryHook.jsx @@ -11,9 +11,10 @@ import { import { ServicesContext } from "contexts/ServicesContext" +import { getMediaDirectoryName } from "utils/media" import { useSuccessToast, useErrorToast } from "utils/toasts" -import { DEFAULT_RETRY_MSG, getMediaDirectoryName } from "utils" +import { DEFAULT_RETRY_MSG } from "utils" // eslint-disable-next-line import/prefer-default-export export function useDeleteDirectoryHook(params, queryParams) { diff --git a/src/hooks/directoryHooks/useUpdateDirectoryHook.jsx b/src/hooks/directoryHooks/useUpdateDirectoryHook.jsx index 619c2d741..1dcad0dad 100644 --- a/src/hooks/directoryHooks/useUpdateDirectoryHook.jsx +++ b/src/hooks/directoryHooks/useUpdateDirectoryHook.jsx @@ -10,9 +10,10 @@ import { import { ServicesContext } from "contexts/ServicesContext" +import { getMediaDirectoryName } from "utils/media" import { useSuccessToast, useErrorToast } from "utils/toasts" -import { DEFAULT_RETRY_MSG, getMediaDirectoryName } from "utils" +import { DEFAULT_RETRY_MSG } from "utils" import { extractUpdateDirectoryInfo } from "./utils" diff --git a/src/hooks/directoryHooks/utils.ts b/src/hooks/directoryHooks/utils.ts index d305d8998..0f98900e1 100644 --- a/src/hooks/directoryHooks/utils.ts +++ b/src/hooks/directoryHooks/utils.ts @@ -1,5 +1,6 @@ +import { getMediaDirectoryName } from "utils/media" + import { DirectoryInfoProps, DirectoryInfoReturn } from "types/directory" -import { getMediaDirectoryName } from "utils" export function extractCreateDirectoryInfo({ data, diff --git a/src/layouts/screens/DeleteWarningScreen.jsx b/src/layouts/screens/DeleteWarningScreen.jsx index 779bb729c..245a3a1f6 100644 --- a/src/layouts/screens/DeleteWarningScreen.jsx +++ b/src/layouts/screens/DeleteWarningScreen.jsx @@ -10,13 +10,10 @@ import { useDeleteDirectoryHook } from "hooks/directoryHooks" import { useGetMediaHook, useDeleteMediaHook } from "hooks/mediaHooks" import { useGetPageHook, useDeletePageHook } from "hooks/pageHooks" +import { getMediaDirectoryName } from "utils/media" import { isWriteActionsDisabled } from "utils/reviewRequests" -import { - getLastItemType, - getMediaDirectoryName, - pageFileNameToTitle, -} from "utils" +import { getLastItemType, pageFileNameToTitle } from "utils" export const DeleteWarningScreen = ({ match, onClose }) => { const [isDeleteChecked, setIsDeleteChecked] = useState(false) diff --git a/src/layouts/screens/DirectorySettingsScreen.jsx b/src/layouts/screens/DirectorySettingsScreen.jsx index b09498c11..609cd76b7 100644 --- a/src/layouts/screens/DirectorySettingsScreen.jsx +++ b/src/layouts/screens/DirectorySettingsScreen.jsx @@ -9,7 +9,9 @@ import { useUpdateDirectoryHook, } from "hooks/directoryHooks" -import { getLastItemType, getMediaDirectoryName } from "utils" +import { getMediaDirectoryName } from "utils/media" + +import { getLastItemType } from "utils" // axios settings axios.defaults.withCredentials = true diff --git a/src/layouts/screens/MediaCreationScreen.jsx b/src/layouts/screens/MediaCreationScreen.jsx index 2aa0ce876..593e70bf1 100644 --- a/src/layouts/screens/MediaCreationScreen.jsx +++ b/src/layouts/screens/MediaCreationScreen.jsx @@ -2,21 +2,15 @@ import PropTypes from "prop-types" import { MediaCreationModal } from "components/MediaCreationModal" -import { useCreateMediaHook } from "hooks/mediaHooks" - export const MediaCreationScreen = ({ match, onClose }) => { - const { params, decodedParams } = match - - const { mutateAsync: createHandler } = useCreateMediaHook(params, { - onSuccess: () => onClose(), - }) + const { decodedParams } = match return ( ) } diff --git a/src/services/DirectoryService.jsx b/src/services/DirectoryService.jsx index f56772fa9..45f6e5747 100644 --- a/src/services/DirectoryService.jsx +++ b/src/services/DirectoryService.jsx @@ -1,4 +1,6 @@ -import { getLastItemType, getMediaDirectoryName } from "../utils" +import { getMediaDirectoryName } from "utils/media" + +import { getLastItemType } from "../utils" export class DirectoryService { constructor({ apiClient }) { diff --git a/src/utils/legacy.js b/src/utils/legacy.js index 888299aaf..c70f44650 100644 --- a/src/utils/legacy.js +++ b/src/utils/legacy.js @@ -289,21 +289,6 @@ export const getLastItemType = (params) => { return lastItemType } -export const getMediaDirectoryName = ( - mediaDirectoryName, - { start = 0, end, splitOn = "%2F", joinOn = "%2F", decode = false } -) => { - const mediaDirectoryArray = mediaDirectoryName.split(splitOn) - const selectedMediaDirectoryArray = mediaDirectoryArray.slice(start, end) - if (decode) { - const decodedSelectedMediaDirectoryArray = selectedMediaDirectoryArray.map( - (v) => decodeURIComponent(v) - ) - return decodedSelectedMediaDirectoryArray.join(joinOn) - } - return selectedMediaDirectoryArray.join(joinOn) -} - export const getNextItemType = (params) => { const lastItemType = getLastItemType(params) if (lastItemType === "siteName") { diff --git a/src/utils/media.ts b/src/utils/media.ts index 5653073ea..cbce66b33 100644 --- a/src/utils/media.ts +++ b/src/utils/media.ts @@ -33,3 +33,32 @@ export const getSelectedMediaDto = (fileData: MediaData) => { return selectedData } + +interface GetMediaDirectoryNameSplitProps { + start?: number + end?: number + splitOn?: string + joinOn?: string + decode?: boolean +} + +export const getMediaDirectoryName = ( + mediaDirectoryName: string, + { + start = 0, + end, + splitOn = "%2F", + joinOn = "%2F", + decode = false, + }: GetMediaDirectoryNameSplitProps +) => { + const mediaDirectoryArray = mediaDirectoryName.split(splitOn) + const selectedMediaDirectoryArray = mediaDirectoryArray.slice(start, end) + if (decode) { + const decodedSelectedMediaDirectoryArray = selectedMediaDirectoryArray.map( + (v) => decodeURIComponent(v) + ) + return decodedSelectedMediaDirectoryArray.join(joinOn) + } + return selectedMediaDirectoryArray.join(joinOn) +} From 3e6efa6dad7c85e7ff73106da53044b439327da3 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 23 Nov 2023 13:39:52 +0800 Subject: [PATCH 6/7] fix: submitting state for react-hook-form (#1693) * fix: submitting state for react-hook-form * chore: remove dependency on isSubmitting --- .../ContactModal/ContactVerificationModal.tsx | 14 ++++++++++++-- src/layouts/Login/LoginPage.tsx | 14 ++++++++++++-- .../components/Comments/SendCommentForm.tsx | 5 +++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/components/Header/ContactModal/ContactVerificationModal.tsx b/src/components/Header/ContactModal/ContactVerificationModal.tsx index b0676fc74..fb4345f28 100644 --- a/src/components/Header/ContactModal/ContactVerificationModal.tsx +++ b/src/components/Header/ContactModal/ContactVerificationModal.tsx @@ -43,7 +43,12 @@ export const ContactVerificationModal = ({ const [mobile, setMobile] = useState("") const handleSendOtp = async ({ mobile: mobileInput }: ContactProps) => { - await sendContactOtp({ mobile: mobileInput }) // Non-2xx responses will be caught by axios and thrown as error + try { + await sendContactOtp({ mobile: mobileInput }) // Non-2xx responses will be caught by axios and thrown as error + } catch (e) { + // Needed for react-hook-form to reset isSubmitting + return + } successToast({ id: "send-otp-success", description: `OTP sent to ${mobileInput}`, @@ -52,7 +57,12 @@ export const ContactVerificationModal = ({ } const handleVerifyOtp = async ({ otp }: ContactOtpProps) => { - await verifyContactOtp({ mobile, otp }) + try { + await verifyContactOtp({ mobile, otp }) + } catch (e) { + // Needed for react-hook-form to reset isSubmitting + return + } onClose() successToast({ id: "verify-otp-success", diff --git a/src/layouts/Login/LoginPage.tsx b/src/layouts/Login/LoginPage.tsx index 0e7ed1b57..0fcd8b3af 100644 --- a/src/layouts/Login/LoginPage.tsx +++ b/src/layouts/Login/LoginPage.tsx @@ -105,7 +105,12 @@ const LoginContent = (): JSX.Element => { const handleSendOtp = async ({ email: emailInput }: LoginProps) => { const trimmedEmail = emailInput.trim() - await sendLoginOtp({ email: trimmedEmail }) // Non-2xx responses will be caught by axios and thrown as error + try { + await sendLoginOtp({ email: trimmedEmail }) // Non-2xx responses will be caught by axios and thrown as error + } catch (e) { + // Needed for react-hook-form to reset isSubmitting + return + } successToast({ id: "send-otp-success", description: `OTP sent to ${trimmedEmail}`, @@ -114,7 +119,12 @@ const LoginContent = (): JSX.Element => { } const handleVerifyOtp = async ({ otp }: OtpProps) => { - await verifyLoginOtp({ email, otp }) + try { + await verifyLoginOtp({ email, otp }) + } catch (e) { + // Needed for react-hook-form to reset isSubmitting + return + } history.replace("/sites") } diff --git a/src/layouts/ReviewRequest/components/Comments/SendCommentForm.tsx b/src/layouts/ReviewRequest/components/Comments/SendCommentForm.tsx index 97799196c..29a166b99 100644 --- a/src/layouts/ReviewRequest/components/Comments/SendCommentForm.tsx +++ b/src/layouts/ReviewRequest/components/Comments/SendCommentForm.tsx @@ -39,6 +39,7 @@ export const SendCommentForm = ({ const { mutateAsync: updateNotifications, error: updateNotificationsError, + isLoading: isUpddatingComments, } = useUpdateComments() const queryClient = useQueryClient() @@ -62,7 +63,7 @@ export const SendCommentForm = ({
@@ -80,7 +81,7 @@ export const SendCommentForm = ({ variant="clear" aria-label="link to send comment" type="submit" - isLoading={formState.isSubmitting} + isLoading={isUpddatingComments} isDisabled={!formState.isValid} /> From 065ba3f40a2a5cf4d8c4f21228f39bcaf1f6c1a6 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 23 Nov 2023 14:14:50 +0800 Subject: [PATCH 7/7] 0.61.0 --- CHANGELOG.md | 34 +++++++++++++++++++++++----------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67eba04f0..0548fb6b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,21 @@ 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.61.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.60.0...v0.61.0) + +- fix: submitting state for react-hook-form [`#1693`](https://github.com/isomerpages/isomercms-frontend/pull/1693) +- Fix/is 778 creating media in subfolder in select modal [`#1695`](https://github.com/isomerpages/isomercms-frontend/pull/1695) +- Fix: stylesheet [`#1696`](https://github.com/isomerpages/isomercms-frontend/pull/1696) +- fix(images): ability to change img [`#1694`](https://github.com/isomerpages/isomercms-frontend/pull/1694) +- feat(tiptap): add Instagram embed proper node handler [`#1688`](https://github.com/isomerpages/isomercms-frontend/pull/1688) +- fix(updateLinkModal): update link + proper default [`#1692`](https://github.com/isomerpages/isomercms-frontend/pull/1692) +- 0.60.0 [`#1690`](https://github.com/isomerpages/isomercms-frontend/pull/1690) +- fix(input): empty input validation [`#1691`](https://github.com/isomerpages/isomercms-frontend/pull/1691) + #### [v0.60.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.59.0...v0.60.0) -- fix(input): empty input validation [`#1691`](https://github.com/isomerpages/isomercms-frontend/pull/1691) +> 21 November 2023 + - is-714/chore: add copy and layout changes [`#1687`](https://github.com/isomerpages/isomercms-frontend/pull/1687) - IS-780 fix(height): fix editor + preview heights [`#1686`](https://github.com/isomerpages/isomercms-frontend/pull/1686) - IS-782-Editor-File-text-always-comes-out-as-file-regardless-of-text [`#1685`](https://github.com/isomerpages/isomercms-frontend/pull/1685) @@ -83,13 +95,13 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - feat(media): introduce enhancement to media pages [`#1628`](https://github.com/isomerpages/isomercms-frontend/pull/1628) - feat(blocks): rollback handler [`#1603`](https://github.com/isomerpages/isomercms-frontend/pull/1603) - 0.54.0 to develop [`#1622`](https://github.com/isomerpages/isomercms-frontend/pull/1622) +- feat(media): introduce new image preview card common component [`#1620`](https://github.com/isomerpages/isomercms-frontend/pull/1620) +- fix(editpage): change query key from object to array [`#1623`](https://github.com/isomerpages/isomercms-frontend/pull/1623) #### [v0.54.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.53.0...v0.54.0) -> 26 October 2023 +> 25 October 2023 -- feat(media): introduce new image preview card common component [`#1620`](https://github.com/isomerpages/isomercms-frontend/pull/1620) -- fix(editpage): change query key from object to array [`#1623`](https://github.com/isomerpages/isomercms-frontend/pull/1623) - Fix/login page layout [`#1619`](https://github.com/isomerpages/isomercms-frontend/pull/1619) - chore: add sgidlogin page story [`#1595`](https://github.com/isomerpages/isomercms-frontend/pull/1595) - IS-614-Make-it-easy-to-view-staging-on-mobile [`#1617`](https://github.com/isomerpages/isomercms-frontend/pull/1617) @@ -106,16 +118,16 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - feat: allow Isomer admins to edit on email-login [`#1604`](https://github.com/isomerpages/isomercms-frontend/pull/1604) - fix(settings): use env var [`#1609`](https://github.com/isomerpages/isomercms-frontend/pull/1609) - release/v0.52.0 [`#1600`](https://github.com/isomerpages/isomercms-frontend/pull/1600) - -#### [v0.52.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.51.1...v0.52.0) - -> 19 October 2023 - - fix: errors indexes [`#1610`](https://github.com/isomerpages/isomercms-frontend/pull/1610) - fix(navbar): fix race condition when retrieving second level data [`#1608`](https://github.com/isomerpages/isomercms-frontend/pull/1608) - fix(navbar): ensure all queries are loaded first [`#1607`](https://github.com/isomerpages/isomercms-frontend/pull/1607) - fix(media): support replacement of media src with spaces [`#1606`](https://github.com/isomerpages/isomercms-frontend/pull/1606) - chore(hooks): add timeout [`#1605`](https://github.com/isomerpages/isomercms-frontend/pull/1605) + +#### [v0.52.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.51.1...v0.52.0) + +> 18 October 2023 + - fix(media): adjust query key to load image in preview on upload [`#1602`](https://github.com/isomerpages/isomercms-frontend/pull/1602) - Feat/sgid govt rollout [`#1594`](https://github.com/isomerpages/isomercms-frontend/pull/1594) - feat(navbar): upgrade navbar to use v2 endpoints [`#1592`](https://github.com/isomerpages/isomercms-frontend/pull/1592) @@ -129,12 +141,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 18 October 2023 - fix(mediasselectmodal): update dir name [`#1596`](https://github.com/isomerpages/isomercms-frontend/pull/1596) +- fix(media): add limit [`#1591`](https://github.com/isomerpages/isomercms-frontend/pull/1591) #### [v0.51.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.50.0...v0.51.0) > 16 October 2023 -- fix(media): add limit [`#1591`](https://github.com/isomerpages/isomercms-frontend/pull/1591) - chore(hooks): remove `useGetMediaFolders` [`#1582`](https://github.com/isomerpages/isomercms-frontend/pull/1582) - feat(homepage): allow user to override changes when there is a conflict [`#1588`](https://github.com/isomerpages/isomercms-frontend/pull/1588) - ref(media): update media hooks + components [`#1581`](https://github.com/isomerpages/isomercms-frontend/pull/1581) @@ -181,13 +193,13 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). > 3 October 2023 +- fix(herocenteredlayout): make dropdown optional [`#1556`](https://github.com/isomerpages/isomercms-frontend/pull/1556) - fix(hero.scss): css fix [`af09212`](https://github.com/isomerpages/isomercms-frontend/commit/af09212f81dbf845eae7579632fecb2a26d3eb1a) #### [v0.47.0](https://github.com/isomerpages/isomercms-frontend/compare/v0.46.0...v0.47.0) > 3 October 2023 -- fix(herocenteredlayout): make dropdown optional [`#1556`](https://github.com/isomerpages/isomercms-frontend/pull/1556) - Fix/text cards design [`#1535`](https://github.com/isomerpages/isomercms-frontend/pull/1535) - chore(cleanup): delete unused styles [`#1548`](https://github.com/isomerpages/isomercms-frontend/pull/1548) - refactor(hero): duplicate changes from template [`#1551`](https://github.com/isomerpages/isomercms-frontend/pull/1551) diff --git a/package-lock.json b/package-lock.json index a7a0f171d..9d7f90c1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isomercms-frontend", - "version": "0.60.0", + "version": "0.61.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isomercms-frontend", - "version": "0.60.0", + "version": "0.61.0", "hasInstallScript": true, "dependencies": { "@braintree/sanitize-url": "^6.0.1", diff --git a/package.json b/package.json index 472f6b10f..80e3c744c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isomercms-frontend", - "version": "0.60.0", + "version": "0.61.0", "private": true, "engines": { "node": ">=16.0.0"