Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit a682f6d

Browse files
committed
fix: application mobile layout breaking
1 parent 693f979 commit a682f6d

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

apps/admin-ui/src/helpers/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/// Plain js / ts helper functions
22
import { ReservationType, Type } from "common/types/gql-types";
3-
43
import { addSeconds } from "date-fns";
54

5+
export { truncate } from "common/src/helpers";
6+
67
export * from "./date";
78

89
export type CollisionInterval = {
@@ -57,6 +58,3 @@ export const reservationToInterval = (
5758
type: x.type ?? undefined,
5859
};
5960
};
60-
61-
export const truncate = (val: string, maxLen: number): string =>
62-
val.length > maxLen ? `${val.substring(0, maxLen - 1)}…` : val;

apps/ui/components/application/Page2.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import styled from "styled-components";
66
import { useFormContext } from "react-hook-form";
77
import type { ApplicationEventSchedulePriority } from "common/types/common";
88
import { Priority, type ApplicationNode } from "common/types/gql-types";
9-
import { filterNonNullable, getLocalizationLang } from "common/src/helpers";
9+
import {
10+
filterNonNullable,
11+
getLocalizationLang,
12+
truncate,
13+
} from "common/src/helpers";
1014
import type {
1115
ApplicationSectionFormValue,
1216
ApplicationEventScheduleFormType,
@@ -43,6 +47,9 @@ type DailyOpeningHours =
4347
}[]
4448
| null;
4549

50+
// Mobile layout breaks if the select options are too long
51+
const MAX_SELECT_OPTION_LENGTH = 28;
52+
4653
const StyledNotification = styled(Notification)`
4754
margin-top: var(--spacing-m);
4855
`;
@@ -252,10 +259,15 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
252259
const resUnits = filterNonNullable(
253260
resUnitOptions.map((n) => n?.reservationUnit)
254261
);
255-
const reservationUnitOptions = resUnits.map((n) => ({
256-
value: n?.pk ?? 0,
257-
label: getTranslationSafe(n, "name", getLocalizationLang(i18n.language)),
258-
}));
262+
const reservationUnitOptions = resUnits
263+
.map((n) => ({
264+
value: n?.pk ?? 0,
265+
label: getTranslationSafe(n, "name", getLocalizationLang(i18n.language)),
266+
}))
267+
.map(({ value, label }) => ({
268+
value,
269+
label: truncate(label, MAX_SELECT_OPTION_LENGTH),
270+
}));
259271
// TODO why is this done like this?
260272
const openingHours = filterNonNullable(
261273
resUnits.find((n) => n.pk === reservationUnitPk)?.applicationRoundTimeSlots

apps/ui/components/application/TimePreview.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const WeekWrapper = styled.div`
2020
const Label = styled.div`
2121
${fontBold};
2222
padding-right: 4px;
23+
max-width: 10ch;
24+
width: 100%;
2325
`;
2426

2527
function Weekdays({

packages/common/src/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ export function base64encode(str: string) {
5050
}
5151
return Buffer.from(str, "binary").toString("base64");
5252
}
53+
54+
export const truncate = (val: string, maxLen: number): string =>
55+
val.length > maxLen ? `${val.substring(0, maxLen - 1)}…` : val;

0 commit comments

Comments
 (0)