Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Link survey mobile view #2493

Merged
merged 12 commits into from
Apr 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ export const PreviewSurvey = ({
/>
</Modal>
) : (
<div className="w-full px-3">
<div className="h-full w-full">
<div className="absolute left-5 top-5">
{!styling.isLogoHidden && product.logo?.url && (
<ClientLogo environmentId={environment.id} product={product} previewSurvey />
)}
</div>
<div className="no-scrollbar z-10 w-full max-w-md overflow-y-auto rounded-lg border border-transparent">
<div className="flex h-full items-end">
<SurveyInline
survey={survey}
isBrandingEnabled={product.linkSurveyBranding}
Expand Down
8 changes: 6 additions & 2 deletions apps/web/app/s/[surveyId]/components/LinkSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default function LinkSurvey({
if (window.self === window.top) {
setAutofocus(true);
}
// For safari on mobile devices, scroll is a bit off due to dynamic height of address bar, so on inital load, we scroll to the bottom
window.scrollTo({
top: document.body.scrollHeight,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down Expand Up @@ -181,9 +185,9 @@ export default function LinkSurvey({
};

return (
<div className="flex h-screen items-center justify-center">
<div className="flex h-screen items-center justify-center" style={{ height: "90svh" }}>
{!determineStyling().isLogoHidden && product.logo?.url && <ClientLogo product={product} />}
<ContentWrapper className="w-11/12 p-0 md:max-w-md">
<ContentWrapper className="w-full p-0 md:max-w-md">
{isPreview && (
<div className="fixed left-0 top-0 flex w-full items-center justify-between bg-slate-600 p-2 px-4 text-center text-sm text-white shadow-sm">
<div />
Expand Down
2 changes: 1 addition & 1 deletion packages/surveys/src/components/general/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export const Survey = ({
<AutoCloseWrapper survey={survey} onClose={onClose}>
<div
className={cn(
"no-scrollbar rounded-custom bg-survey-bg flex h-full w-full flex-col justify-between px-6 pb-3 pt-6",
"no-scrollbar md:rounded-custom bg-survey-bg rounded-t-custom flex h-full w-full flex-col justify-between rounded-b-none px-6 py-6 md:pb-3 md:pt-6",
isCardBorderVisible ? "border-survey-border border" : "",
survey.type === "link" ? "fb-survey-shadow" : ""
)}>
Expand Down
23 changes: 22 additions & 1 deletion packages/surveys/src/components/general/SurveyInline.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { useEffect, useState } from "preact/hooks";

import { SurveyInlineProps } from "@formbricks/types/formbricksSurveys";

import { Survey } from "./Survey";

export function SurveyInline(props: SurveyInlineProps) {
const [isMobile, setIsMobile] = useState(window.innerWidth < 768); // Assuming 768px as a breakpoint for mobile

useEffect(() => {
const handleResize = () => {
setIsMobile(window.innerWidth < 768);
};

window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);

return (
<div id="fbjs" className="formbricks-form h-full w-full">
<Survey {...props} />
{isMobile ? (
<div className="flex h-screen w-full flex-col justify-end overflow-hidden">
<div className="max-h-[90vh] overflow-auto">
<Survey {...props} />
</div>
</div>
) : (
<Survey {...props} />
)}
</div>
);
}
2 changes: 1 addition & 1 deletion packages/ui/ClientLogo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ClientLogoProps {
export const ClientLogo = ({ environmentId, product, previewSurvey = false }: ClientLogoProps) => {
return (
<div
className={cn(previewSurvey ? "" : "left-5 top-5 md:left-7 md:top-7", "group absolute z-0 rounded-lg")}
className={cn(previewSurvey ? "" : "left-5 top-5 md:left-7 md:top-7", "group fixed z-0 rounded-lg")}
style={{ backgroundColor: product.logo?.bgColor }}>
{previewSurvey && environmentId && (
<Link
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/Survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export const SurveyInline = (props: Omit<SurveyInlineProps, "containerId">) => {
loadScript();
}, [containerId, props, renderInline]);

return <div id={containerId} className="h-full w-full" />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test this well? Feels like it'd break the layout in other places ;)

return <div id={containerId} className="w-full" />;
};
Loading