Skip to content

Commit d8e5097

Browse files
authored
isom-1678 dynamic blocks for muis fix (#922)
* update CSP to use env.NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME * fix: replace useQuery with useState and useEffect * npm run format:fix * add error state * add errorMessage to schema * add error state UI + use twVariant * update stories * fix - separate error and loading state * add errorMessage to studio default block * format * update preview-tw * fix - screen wide component
1 parent bcf4c53 commit d8e5097

File tree

10 files changed

+301
-118
lines changed

10 files changed

+301
-118
lines changed

apps/studio/next.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ const ContentSecurityPolicy = `
7474
https://*.wogaa.sg
7575
https://placehold.co
7676
https://cdn.growthbook.io
77-
${env.NODE_ENV === "production" ? "https://isomer-user-content.by.gov.sg" : "https://*.by.gov.sg"}
77+
${
78+
!!env.NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME
79+
? `https://${env.NEXT_PUBLIC_S3_ASSETS_DOMAIN_NAME}`
80+
: "https://*.by.gov.sg"
81+
}
7882
https://via.intercom.io
7983
https://api.intercom.io
8084
https://api.au.intercom.io

apps/studio/public/assets/css/preview-tw.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4929,6 +4929,10 @@ video {
49294929
padding-bottom: 5rem;
49304930
}
49314931

4932+
.md\:pb-3 {
4933+
padding-bottom: 0.75rem;
4934+
}
4935+
49324936
.md\:pt-16 {
49334937
padding-top: 4rem;
49344938
}
@@ -5139,6 +5143,10 @@ video {
51395143
align-items: flex-start;
51405144
}
51415145

5146+
.lg\:items-end {
5147+
align-items: flex-end;
5148+
}
5149+
51425150
.lg\:justify-start {
51435151
justify-content: flex-start;
51445152
}
@@ -5147,6 +5155,10 @@ video {
51475155
justify-content: flex-end;
51485156
}
51495157

5158+
.lg\:justify-center {
5159+
justify-content: center;
5160+
}
5161+
51505162
.lg\:justify-between {
51515163
justify-content: space-between;
51525164
}
@@ -5219,6 +5231,11 @@ video {
52195231
padding-right: 2rem;
52205232
}
52215233

5234+
.lg\:py-0 {
5235+
padding-top: 0px;
5236+
padding-bottom: 0px;
5237+
}
5238+
52225239
.lg\:py-16 {
52235240
padding-top: 4rem;
52245241
padding-bottom: 4rem;

apps/studio/src/components/PageEditor/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ export const DEFAULT_BLOCKS: Record<
209209
],
210210
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
211211
label: "View all dates",
212+
errorMessage: [
213+
{
214+
type: "text",
215+
text: "Oops! Having trouble loading the data. Try refreshing — that usually does the trick!",
216+
},
217+
],
212218
},
213219
}
214220

package-lock.json

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
"@govtechsg/sgds-react": "^2.5.1",
108108
"@headlessui/react": "^2.1.2",
109109
"@sinclair/typebox": "^0.33.12",
110-
"@tanstack/react-query": "^4.36.1",
111110
"date-fns": "^4.1.0",
112111
"interweave": "^13.1.0",
113112
"interweave-ssr": "^2.0.0",

packages/components/src/interfaces/complex/DynamicDataBanner.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Static } from "@sinclair/typebox"
22
import { Type } from "@sinclair/typebox"
33

44
import type { IsomerSiteProps, LinkComponentType } from "~/types"
5+
import { TextSchema } from "../native/Text"
56

67
export const DYNAMIC_DATA_BANNER_TYPE = "dynamicdatabanner"
78

@@ -47,6 +48,10 @@ export const DynamicDataBannerSchema = Type.Object(
4748
maxItems: NUMBER_OF_DATA,
4849
},
4950
),
51+
errorMessage: Type.Array(TextSchema, {
52+
title: "Error message",
53+
description: "The error message to display if the data is not loaded",
54+
}),
5055
label: Type.Optional(
5156
Type.String({
5257
title: "Link text",

packages/components/src/templates/next/components/complex/DynamicDataBanner/DynamicDataBanner.stories.tsx

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,129 @@ import type { Meta, StoryObj } from "@storybook/react"
22

33
import { withChromaticModes } from "@isomer/storybook-config"
44

5-
import { DynamicDataBannerUI } from "./DynamicDataBannerClient"
5+
import { DynamicDataBanner } from "./DynamicDataBanner"
6+
import { getSingaporeDateYYYYMMDD } from "./utils"
67

7-
const meta: Meta<typeof DynamicDataBannerUI> = {
8+
const meta: Meta<typeof DynamicDataBanner> = {
89
title: "Next/Components/DynamicDataBanner",
9-
component: DynamicDataBannerUI,
10+
component: DynamicDataBanner,
1011
parameters: {
1112
layout: "fullscreen",
1213
chromatic: withChromaticModes(["mobile", "tablet", "desktop"]),
1314
},
15+
args: {
16+
site: {
17+
siteName: "Isomer Next",
18+
siteMap: {
19+
id: "1",
20+
title: "Home",
21+
permalink: "/",
22+
lastModified: "",
23+
layout: "homepage",
24+
summary: "",
25+
},
26+
theme: "isomer-next",
27+
isGovernment: true,
28+
logoUrl: "https://www.isomer.gov.sg/images/isomer-logo.svg",
29+
navBarItems: [],
30+
footerItems: {
31+
privacyStatementLink: "https://www.isomer.gov.sg/privacy",
32+
termsOfUseLink: "https://www.isomer.gov.sg/terms",
33+
siteNavItems: [],
34+
},
35+
lastUpdated: "1 Jan 2021",
36+
search: {
37+
type: "searchSG",
38+
clientId: "",
39+
},
40+
},
41+
apiEndpoint: "https://jsonplaceholder.com/muis_prayers_time",
42+
title: "hijriDate",
43+
data: [
44+
{
45+
label: "Subuh",
46+
key: "subuh",
47+
},
48+
{
49+
label: "Syuruk",
50+
key: "syuruk",
51+
},
52+
{
53+
label: "Zohor",
54+
key: "zohor",
55+
},
56+
{
57+
label: "Asar",
58+
key: "asar",
59+
},
60+
{
61+
label: "Maghrib",
62+
key: "maghrib",
63+
},
64+
{
65+
label: "Ishak",
66+
key: "isyak",
67+
},
68+
],
69+
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
70+
label: "View all dates",
71+
errorMessage: [
72+
{
73+
text: "Not seeing the prayer times? ",
74+
type: "text",
75+
},
76+
{
77+
text: "Report an issue",
78+
type: "text",
79+
marks: [
80+
{ type: "bold" },
81+
{
82+
type: "link",
83+
attrs: {
84+
href: "https://www.form.gov.sg/some-link",
85+
},
86+
},
87+
],
88+
},
89+
],
90+
},
1491
}
1592

1693
export default meta
17-
type Story = StoryObj<typeof DynamicDataBannerUI>
94+
type Story = StoryObj<typeof DynamicDataBanner>
1895

1996
export const Default: Story = {
20-
args: {
21-
title: "1 Rejab 1446H",
22-
data: [
23-
{ label: "Subuh", value: "5:43am" },
24-
{ label: "Syuruk", value: "7:07am" },
25-
{ label: "Zohor", value: "1:09pm" },
26-
{ label: "Asar", value: "4.33pm" },
27-
{ label: "Maghrib", value: "7.10pm" },
28-
{ label: "Isyak", value: "8.25pm" },
97+
parameters: {
98+
mockData: [
99+
{
100+
url: "https://jsonplaceholder.com/muis_prayers_time",
101+
method: "GET",
102+
status: 200,
103+
response: {
104+
[getSingaporeDateYYYYMMDD()]: {
105+
hijriDate: "17 Jamadilawal 1442H",
106+
subuh: "5:44am",
107+
syuruk: "7:08am",
108+
zohor: "1:10pm",
109+
asar: "4:34pm",
110+
maghrib: "7:11pm",
111+
isyak: "8:25pm",
112+
},
113+
},
114+
},
115+
],
116+
},
117+
}
118+
119+
export const Error: Story = {
120+
parameters: {
121+
mockData: [
122+
{
123+
url: "https://jsonplaceholder.com/muis_prayers_time",
124+
method: "GET",
125+
status: 500,
126+
response: {},
127+
},
29128
],
30-
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
31-
label: "View all dates",
32129
},
33130
}

packages/components/src/templates/next/components/complex/DynamicDataBanner/DynamicDataBanner.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DynamicDataBannerProps } from "~/interfaces"
2-
import { getReferenceLinkHref } from "~/utils"
2+
import { getReferenceLinkHref, getTextAsHtml } from "~/utils"
3+
import BaseParagraph from "../../internal/BaseParagraph/BaseParagraph"
34
import { DynamicDataBannerClient } from "./DynamicDataBannerClient"
45

56
export const DynamicDataBanner = ({
@@ -8,6 +9,7 @@ export const DynamicDataBanner = ({
89
data,
910
url,
1011
label,
12+
errorMessage,
1113
site,
1214
LinkComponent,
1315
}: DynamicDataBannerProps) => {
@@ -18,7 +20,17 @@ export const DynamicDataBanner = ({
1820
data={data}
1921
url={getReferenceLinkHref(url, site.siteMap, site.assetsBaseUrl)}
2022
label={label}
21-
LinkComponent={LinkComponent}
23+
errorMessageBaseParagraph={
24+
<BaseParagraph
25+
content={getTextAsHtml({
26+
site,
27+
content: errorMessage,
28+
})}
29+
className="prose-body-sm [&:not(:first-child)]:mt-0 [&:not(:last-child)]:mb-0"
30+
site={site}
31+
LinkComponent={LinkComponent}
32+
/>
33+
}
2234
/>
2335
)
2436
}

0 commit comments

Comments
 (0)