Skip to content

Commit 63cd4fb

Browse files
authored
Merge pull request #483 from BinaryStudioAcademy/482-fix-export-button-for-demo
fix(frontend): temporay fix for demo cy-482
2 parents 20196aa + 00217c5 commit 63cd4fb

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
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: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ import {
3636
import styles from "./styles.module.css";
3737

3838
const PlanStyleOverview: React.FC = () => {
39+
const RESPONSIVE_BREAKPOINT = 768;
40+
const [isMobile, setIsMobile] = useState<boolean>(false);
41+
useEffect(() => {
42+
const checkMobile = (): void => {
43+
setIsMobile(window.innerWidth <= RESPONSIVE_BREAKPOINT);
44+
};
45+
46+
checkMobile();
47+
window.addEventListener("resize", checkMobile);
48+
49+
return (): void => {
50+
window.removeEventListener("resize", checkMobile);
51+
};
52+
}, []);
3953
const user = useAppSelector((state) => state.auth.user);
4054
const currentPlan = useAppSelector(({ plan }) => plan.plan);
4155
const isAuthenticated = Boolean(user);
@@ -152,17 +166,25 @@ const PlanStyleOverview: React.FC = () => {
152166
}
153167

154168
return (
155-
<div className={getClassNames("grid-pattern", styles["page-container"])}>
169+
<div
170+
className={getClassNames(
171+
"grid-pattern",
172+
styles["page-container"],
173+
isMobile && styles["mobile-padding-top"],
174+
)}
175+
>
156176
<AppHeader />
157-
<div className={styles["header-section"]}>
158-
<PlanStyleCategory
159-
actionButtonDisabled={isCalendarDownloading}
160-
actionButtonLabel="Calendar File"
161-
onActionButtonClick={handleOpenCalendarModal}
162-
onSelect={handleCategorySelect}
163-
selectedCategory={selectedCategory}
164-
/>
165-
</div>
177+
{!isMobile && (
178+
<div className={styles["header-section"]}>
179+
<PlanStyleCategory
180+
actionButtonDisabled={isCalendarDownloading}
181+
actionButtonLabel="Calendar File"
182+
onActionButtonClick={handleOpenCalendarModal}
183+
onSelect={handleCategorySelect}
184+
selectedCategory={selectedCategory}
185+
/>
186+
</div>
187+
)}
166188
<div className="flow-loose-xl">
167189
<div className={getClassNames(styles["container"])}>
168190
<div className={getClassNames("wrapper", styles["plan-content"])}>
@@ -184,6 +206,7 @@ const PlanStyleOverview: React.FC = () => {
184206

185207
<div className={styles["actions-section"]}>
186208
<PlanActions
209+
handleConfirmCalendarDownload={handleOpenCalendarModal}
187210
isAuthenticated={isAuthenticated}
188211
isDownloading={pdfExportStatus === DataStatus.PENDING}
189212
onChooseStyle={handleChooseStyle}

apps/frontend/src/pages/plan-style-overview/styles.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
padding-bottom: var(--space-xl);
77
}
88

9+
.mobile-padding-top {
10+
padding-top: 38px;
11+
}
12+
913
.container {
1014
position: relative;
1115
display: flex;

0 commit comments

Comments
 (0)