Skip to content

Commit 4599ff8

Browse files
fix(frontend): temporay fix for demo cy-482
1 parent 8b1bbb2 commit 4599ff8

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

apps/frontend/src/pages/plan-style-overview/components/plan-actions/plan-actions.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback } from "react";
1+
import { useCallback, useEffect, useState } from "react";
22
import { Link } from "react-router-dom";
33

44
import {
@@ -17,6 +17,7 @@ import { useLocation } from "~/libs/hooks/hooks.js";
1717
import styles from "./styles.module.css";
1818

1919
type Properties = {
20+
handleConfirmCalendarDownload?: () => void;
2021
isAuthenticated: boolean;
2122
isDownloading: boolean;
2223
onChooseStyle: () => void;
@@ -26,21 +27,42 @@ type Properties = {
2627
};
2728

2829
const PlanActions: React.FC<Properties> = ({
30+
handleConfirmCalendarDownload,
2931
isAuthenticated,
3032
isDownloading,
3133
onChooseStyle,
3234
onDownload,
3335
onEdit,
3436
onGoToDashboard,
3537
}: Properties) => {
38+
const RESPONSIVE_BREAKPOINT = 768;
3639
const location = useLocation();
40+
const [isMobile, setIsMobile] = useState<boolean>(false);
41+
42+
useEffect(() => {
43+
const checkMobile = (): void => {
44+
setIsMobile(window.innerWidth <= RESPONSIVE_BREAKPOINT);
45+
};
46+
47+
checkMobile();
48+
window.addEventListener("resize", checkMobile);
49+
50+
return (): void => {
51+
window.removeEventListener("resize", checkMobile);
52+
};
53+
}, []);
54+
3755
const handleEditClick = useCallback((): void => {
3856
onEdit();
3957
}, [onEdit]);
4058

4159
const handleDownloadClick = useCallback((): void => {
42-
onDownload();
43-
}, [onDownload]);
60+
if (isMobile && typeof handleConfirmCalendarDownload === "function") {
61+
handleConfirmCalendarDownload();
62+
} else {
63+
onDownload();
64+
}
65+
}, [onDownload, isMobile, handleConfirmCalendarDownload]);
4466

4567
const handleGoToDashboardClick = useCallback((): void => {
4668
onGoToDashboard();

apps/frontend/src/pages/plan-style-overview/components/plan-style-category/plan-style-category.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from "react";
1+
import { useCallback, useEffect, useState } from "react";
22
import { LuCalendarArrowDown } from "react-icons/lu";
33

44
import {
@@ -28,6 +28,7 @@ const PlanStyleCategory: React.FC<Properties> = ({
2828
onSelect,
2929
selectedCategory,
3030
}: Properties) => {
31+
const RESPONSIVE_BREAKPOINT = 768;
3132
const handleSelectPdf = useCallback((): void => {
3233
onSelect(PlanCategoryId.PDF);
3334
}, [onSelect]);
@@ -40,11 +41,27 @@ const PlanStyleCategory: React.FC<Properties> = ({
4041
onSelect(PlanCategoryId.DESKTOP);
4142
}, [onSelect]);
4243

44+
const [isMobile, setIsMobile] = useState<boolean>(false);
45+
46+
useEffect(() => {
47+
const checkMobile = (): void => {
48+
setIsMobile(window.innerWidth <= RESPONSIVE_BREAKPOINT);
49+
};
50+
51+
checkMobile();
52+
window.addEventListener("resize", checkMobile);
53+
54+
return (): void => {
55+
window.removeEventListener("resize", checkMobile);
56+
};
57+
}, []);
58+
4359
return (
4460
<div className={styles["header-buttons"]}>
4561
<Button
4662
className={styles["header-buttons-button"]}
4763
icon={<FileIcon aria-hidden="true" />}
64+
isDisabled={isMobile}
4865
label="PDF"
4966
onClick={handleSelectPdf}
5067
size="small"
@@ -56,6 +73,7 @@ const PlanStyleCategory: React.FC<Properties> = ({
5673
className={styles["header-buttons-button"]}
5774
icon={<SmartphoneIcon aria-hidden="true" />}
5875
iconOnlySize="large"
76+
isDisabled={isMobile}
5977
label="Mobile Wallpaper"
6078
onClick={handleSelectMobile}
6179
size="small"
@@ -66,6 +84,7 @@ const PlanStyleCategory: React.FC<Properties> = ({
6684
<Button
6785
className={styles["header-buttons-button"]}
6886
icon={<MonitorIcon aria-hidden="true" />}
87+
isDisabled={isMobile}
6988
label="Desktop Wallpaper"
7089
onClick={handleSelectDesktop}
7190
size="small"
@@ -81,7 +100,7 @@ const PlanStyleCategory: React.FC<Properties> = ({
81100
styles["download-button"],
82101
)}
83102
icon={<LuCalendarArrowDown aria-hidden="true" />}
84-
isDisabled={Boolean(actionButtonDisabled)}
103+
isDisabled={isMobile || Boolean(actionButtonDisabled)}
85104
label={actionButtonLabel}
86105
onClick={onActionButtonClick}
87106
size="small"

apps/frontend/src/pages/plan-style-overview/plan-style-overview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ const PlanStyleOverview: React.FC = () => {
184184

185185
<div className={styles["actions-section"]}>
186186
<PlanActions
187+
handleConfirmCalendarDownload={handleOpenCalendarModal}
187188
isAuthenticated={isAuthenticated}
188189
isDownloading={pdfExportStatus === DataStatus.PENDING}
189190
onChooseStyle={handleChooseStyle}

0 commit comments

Comments
 (0)