Skip to content

Commit

Permalink
PaymentPage: Fix localStorage access issue in incognito (#4922)
Browse files Browse the repository at this point in the history
* localStorage isnt available at server and in incognito mode

* Do translation server side for Payment Page
  • Loading branch information
hariombalhara authored Oct 10, 2022
1 parent d7db1ad commit f164724
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/features/ee/payments/components/PaymentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { WEBSITE_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useTheme from "@calcom/lib/hooks/useTheme";
import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/timeFormat";
import { localStorage } from "@calcom/lib/webstorage";
import { Icon } from "@calcom/ui/Icon";

import type { PaymentPageProps } from "../pages/payment";
Expand All @@ -21,11 +22,14 @@ const PaymentPage: FC<PaymentPageProps> = (props) => {
const { t } = useLocale();
const [is24h, setIs24h] = useState(isBrowserLocale24h());
const [date, setDate] = useState(dayjs.utc(props.booking.startTime));
const [timezone, setTimezone] = useState<string | null>(null);
useTheme(props.profile.theme);
const isEmbed = useIsEmbed();
useEffect(() => {
let embedIframeWidth = 0;
setDate(date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()));
const _timezone = localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess();
setTimezone(_timezone);
setDate(date.tz(_timezone));
setIs24h(!!getIs24hClockFromLocalStorage());
if (isEmbed) {
requestAnimationFrame(function fixStripeIframe() {
Expand Down Expand Up @@ -95,9 +99,7 @@ const PaymentPage: FC<PaymentPageProps> = (props) => {
{date.format("dddd, DD MMMM YYYY")}
<br />
{date.format(is24h ? "H:mm" : "h:mma")} - {props.eventType.length} mins{" "}
<span className="text-gray-500">
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
</span>
<span className="text-gray-500">({timezone})</span>
</div>
{props.booking.location && (
<>
Expand Down
5 changes: 5 additions & 0 deletions packages/features/ee/payments/pages/payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { PaymentData } from "@calcom/app-store/stripepayment/lib/server";
import prisma from "@calcom/prisma";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";

import { ssrInit } from "@server/lib/ssr";

export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;

const querySchema = z.object({
uid: z.string(),
});

export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const ssr = await ssrInit(context);

const { uid } = querySchema.parse(context.query);
const rawPayment = await prisma.payment.findFirst({
where: {
Expand Down Expand Up @@ -102,6 +106,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
user,
eventType,
booking,
trpcState: ssr.dehydrate(),
payment,
profile,
},
Expand Down

0 comments on commit f164724

Please sign in to comment.