Skip to content

Commit

Permalink
fix: application view hydration error
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Oct 22, 2024
1 parent 1c4334d commit 9f54174
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
36 changes: 20 additions & 16 deletions apps/ui/components/application/ViewInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AccordionWithState as Accordion } from "../common/Accordion";
import { ApplicationEventList } from "./ApplicationEventList";
import TermsBox from "common/src/termsbox/TermsBox";
import Sanitize from "../common/Sanitize";
import ClientOnly from "common/src/ClientOnly";

type Node = NonNullable<ApplicationViewQuery["application"]>;
export function ViewInner({
Expand Down Expand Up @@ -41,22 +42,25 @@ export function ViewInner({
<ApplicantInfoPreview application={application} />
</Accordion>
<ApplicationEventList application={application} />
{tos && (
<TermsBox
id="preview.acceptTermsOfUse"
heading={t("reservationUnit:termsOfUse")}
body={<Sanitize html={getTranslation(tos, "text")} />}
/>
)}
{tos2 && (
<TermsBox
id="preview.acceptServiceSpecificTerms"
heading={t("application:preview.reservationUnitTerms")}
body={<Sanitize html={getTranslation(tos2, "text")} />}
/* TODO TermsBox has accepted and checkbox we could use but for now leaving the single
* page specfici checkbox to accept all terms */
/>
)}
{/* NOTE TermsBox has hydration issues */}
<ClientOnly>
{tos && (
<TermsBox
id="preview.acceptTermsOfUse"
heading={t("reservationUnit:termsOfUse")}
body={<Sanitize html={getTranslation(tos, "text")} />}
/>
)}
{tos2 && (
<TermsBox
id="preview.acceptServiceSpecificTerms"
heading={t("application:preview.reservationUnitTerms")}
body={<Sanitize html={getTranslation(tos2, "text")} />}
/* TODO TermsBox has accepted and checkbox we could use but for now leaving the single
* page specfici checkbox to accept all terms */
/>
)}
</ClientOnly>
{acceptTermsOfUse != null && setAcceptTermsOfUse != null && (
<CheckboxContainer>
<Checkbox
Expand Down
11 changes: 8 additions & 3 deletions apps/ui/components/common/Sanitize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ const config = {
},
};

const Sanitize = ({ html, style }: Props): JSX.Element | null =>
html ? (
function Sanitize({ html, style }: Props): JSX.Element | null {
if (!html) {
return null;
}

return (
<StyledContent
style={style}
dangerouslySetInnerHTML={{
__html: sanitizeHtml(html, config),
}}
/>
) : null;
);
}

export default Sanitize;

0 comments on commit 9f54174

Please sign in to comment.