From bd0c671444ef204105cb4c9115c8d50243793605 Mon Sep 17 00:00:00 2001 From: Adrian Goh Jun Wei Date: Mon, 2 Dec 2024 17:10:22 +0800 Subject: [PATCH] isom-1687 update site identifier logos (#909) * fix - use logo URL instead * replace with common method * change objectFit to contain * add 1rem padding for image --- apps/studio/src/features/dashboard/SiteList.tsx | 6 ++++-- .../renderers/controls/JsonFormsImageControl.tsx | 9 ++------- apps/studio/src/utils/generateAssetUrl.ts | 7 +++++++ 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 apps/studio/src/utils/generateAssetUrl.ts diff --git a/apps/studio/src/features/dashboard/SiteList.tsx b/apps/studio/src/features/dashboard/SiteList.tsx index 741215f55c..e7b8914201 100644 --- a/apps/studio/src/features/dashboard/SiteList.tsx +++ b/apps/studio/src/features/dashboard/SiteList.tsx @@ -15,6 +15,7 @@ import { Link } from "@opengovsg/design-system-react" import { NoResultIcon } from "~/components/Svg/NoResultIcon" import { withSuspense } from "~/hocs/withSuspense" +import { generateAssetUrl } from "~/utils/generateAssetUrl" import { trpc } from "~/utils/trpc" const Site = ({ @@ -39,10 +40,11 @@ const Site = ({ borderColor="base.divider.medium" width="100%" height="100%" - objectFit="cover" + objectFit="contain" aspectRatio="1/1" backgroundColor="white" fallbackSrc="/isomer-sites-placeholder.png" + padding="1rem" // Leave some space so that logo won't be flush with the border /> { ))} diff --git a/apps/studio/src/features/editing-experience/components/form-builder/renderers/controls/JsonFormsImageControl.tsx b/apps/studio/src/features/editing-experience/components/form-builder/renderers/controls/JsonFormsImageControl.tsx index 4cff03c482..c3aadaa928 100644 --- a/apps/studio/src/features/editing-experience/components/form-builder/renderers/controls/JsonFormsImageControl.tsx +++ b/apps/studio/src/features/editing-experience/components/form-builder/renderers/controls/JsonFormsImageControl.tsx @@ -13,8 +13,8 @@ import { import type { ModifiedAsset } from "~/types/assets" import { JSON_FORMS_RANKING } from "~/constants/formBuilder" import { useEditorDrawerContext } from "~/contexts/EditorDrawerContext" -import { useEnv } from "~/hooks/useEnv" import { getPresignedPutUrlSchema } from "~/schemas/asset" +import { generateAssetUrl } from "~/utils/generateAssetUrl" import { IMAGE_UPLOAD_ACCEPTED_MIME_TYPES, MAX_IMG_FILE_SIZE_BYTES, @@ -37,9 +37,6 @@ export function JsonFormsImageControl({ errors, data, }: ControlProps) { - const { - env: { NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME }, - } = useEnv() const toast = useToast() const { modifiedAssets, setModifiedAssets } = useEditorDrawerContext() const [pendingAsset, setPendingAsset] = useState() @@ -77,9 +74,7 @@ export function JsonFormsImageControl({ async function convertImage(url: string) { const fileName = url.split("/").pop() const fileType = `image/${url.split(".").pop()}` - const imageUrl = url.startsWith("/") - ? `https://${NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME}${url}` - : url + const imageUrl = generateAssetUrl(url) const file = await urlToFile(imageUrl, fileName || "", fileType) setPendingAsset({ path, src: url, file }) } diff --git a/apps/studio/src/utils/generateAssetUrl.ts b/apps/studio/src/utils/generateAssetUrl.ts new file mode 100644 index 0000000000..5cfbfaf782 --- /dev/null +++ b/apps/studio/src/utils/generateAssetUrl.ts @@ -0,0 +1,7 @@ +import { env } from "~/env.mjs" + +export const generateAssetUrl = (url: string): string => { + return url.startsWith("/") + ? `https://${env.NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME}${url}` + : url +}