Skip to content

Commit

Permalink
fix: resolved template viewer scroll issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kinxlo committed Jul 26, 2024
1 parent 3f3cf17 commit 3ec80ef
Show file tree
Hide file tree
Showing 30 changed files with 413 additions and 222 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import TemplateViewer from "../../../generate-with-html/preview-template/_component.tsx/TemplateViewer";

const PreviewCard = () => {
return <TemplateViewer />;
// @kinxlo IS CURRENTLY WORKING ON THIS FIX 👍.
return (
<div className="h-full min-h-[700px] w-full max-w-[447px] rounded-[19px] border-[1px] border-border bg-background p-5 transition-all duration-300">
<div className="h-full w-full rounded-[7px] border-[1px] border-border bg-white p-4">
<div className="h-full w-full rounded-[7px] border-[1px] border-border">
hi guys, @Guy in A Chair is currently working on this component
responsivess 👍
</div>
</div>
</div>
);
};

export default PreviewCard;
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const GenerateField = () => {
isButtonVisible={true}
buttonContent="Generate"
onButtonClick={() =>
router.push(
"/dashboard/admin/email/generate-with-html/preview-template",
)
router.push("/admin/email/generate-with-html/preview-template")
}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import React, { useEffect, useRef, useState } from "react";

import { templateOne, templateTwo } from "./template-example";
import { usePathname } from "next/navigation";
import React, { ReactNode, useEffect, useRef, useState } from "react";

interface PreviewComponentProperties {
template?: string;
template?: string | ReactNode;
mode?: "preview" | "edit";
onEdit?: (content: string) => void;
}

const TemplateViewer: React.FC<PreviewComponentProperties> = ({
template = templateTwo,
template,
mode = "preview",
onEdit,
}) => {
const [content, setContent] = useState<string>(template);
const [content, setContent] = useState<string>(template as string);
const contentReference = useRef<HTMLTextAreaElement>(null);
const pathname = usePathname();

useEffect(() => {
setContent(template);
if (typeof template === "string") {
setContent(template);
}
}, [template]);

useEffect(() => {
Expand All @@ -30,20 +32,22 @@ const TemplateViewer: React.FC<PreviewComponentProperties> = ({
event: React.ChangeEvent<HTMLTextAreaElement>,
) => {
const newContent = event.target.value;
setContent(newContent);
onEdit?.(newContent);
if (newContent !== content) {
setContent(newContent);
onEdit?.(newContent);
}
};

return (
<div
data-testid="html-template-viewer"
className="h-full rounded-[19px] border border-[#CBD5E180] p-4"
className="rounded-[19px] border border-[#CBD5E180] p-4"
>
<div
data-testid="scroll-container"
className="relative overflow-y-auto rounded-lg"
className="relative overflow-y-auto rounded-lg lg:max-h-[719px]"
>
<div className="flex h-[700px] w-[98%] items-center justify-center overflow-auto rounded-lg border border-[#CBD5E1] bg-white">
<div className="flex w-[98%] items-center justify-center overflow-auto rounded-lg border border-[#CBD5E1] bg-white p-[1rem]">
{mode === "edit" ? (
<textarea
style={{ scrollbarWidth: "none" }}
Expand All @@ -55,10 +59,16 @@ const TemplateViewer: React.FC<PreviewComponentProperties> = ({
/>
) : (
<div
data-testid="template-content"
dangerouslySetInnerHTML={{ __html: content }}
className="h-full w-fit"
/>
className={
pathname?.includes("preview-template") ? `my-[48px]` : undefined
}
>
<div
data-testid="template-content"
dangerouslySetInnerHTML={{ __html: content }}
className="h-full w-fit"
/>
</div>
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
"use client";

import { useState } from "react";
import { renderToString } from "react-dom/server";

import { Button } from "~/components/common/common-button";
import AccountActivationSuccessful from "~/email/templates/account-activation-successful/image";
import PageHeader from "../../../_components/page-header";
import { templateOne } from "./template-example";
import TemplateViewer from "./TemplateViewer";

const HtmlTemplateViewer = () => {
const [template, setTemplate] = useState<string>(templateOne);
// Define the props for the component
const previewProperties = {
title: "Your Account is Now Active!",
username: "John Doe",
image: "https://imgur.com/3Yymb22.png",
link: "/",
description:
"Congratulations! Your account with Boilerplate is now active and ready to use.",
descriptionOne:
"We're thrilled to have you as part of our community and look forward to helping you make the most out of your experience with us.",
descriptionTwo:
"You can now log in and start exploring all the features and benefits we have to offer. ",
};

// Convert the React component to a string with the props
// eslint-disable-next-line testing-library/render-result-naming-convention
const welcomeEmailString = renderToString(
<AccountActivationSuccessful {...previewProperties} />,
);

const [template, setTemplate] = useState<string>(welcomeEmailString);
const [mode, setMode] = useState<"preview" | "edit">("preview");

const toggleMode = () => {
Expand Down
Loading

0 comments on commit 3ec80ef

Please sign in to comment.