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

Commit 673ef5e

Browse files
committed
fix: remove time format copy pasta
Refs: TILA-3444
1 parent 031ab35 commit 673ef5e

2 files changed

Lines changed: 17 additions & 51 deletions

File tree

apps/ui/components/calendar/ReservationCalendarControls.tsx

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useEffect, useMemo, useState } from "react";
22
import { useTranslation, type TFunction } from "next-i18next";
33
import styled from "styled-components";
44
import { Button, IconAngleDown, IconAngleUp, IconCross } from "hds-react";
5-
import { maxBy, trim } from "lodash";
6-
import { fromUIDate, toUIDate } from "common/src/common/util";
5+
import { maxBy } from "lodash";
6+
import { fromUIDate } from "common/src/common/util";
77
import { Transition } from "react-transition-group";
88
import {
99
fontBold,
@@ -13,11 +13,12 @@ import {
1313
import { breakpoints } from "common/src/common/style";
1414
import type { ReservationUnitPageQuery } from "@gql/gql-types";
1515
import { truncatedText } from "@/styles/util";
16+
import { getReservationUnitPrice } from "@/modules/reservationUnit";
1617
import {
17-
getReservationUnitPrice,
18-
getTimeString,
19-
} from "@/modules/reservationUnit";
20-
import { capitalize, getSelectedOption } from "@/modules/util";
18+
capitalize,
19+
formatDateTimeRange,
20+
getSelectedOption,
21+
} from "@/modules/util";
2122
import type {
2223
Control,
2324
FieldValues,
@@ -285,19 +286,13 @@ const ReservationCalendarControls = ({
285286
}: Props): JSX.Element => {
286287
const { t } = useTranslation();
287288
const { control, watch, handleSubmit } = reservationForm;
288-
const { start, end } = focusSlot ?? {};
289289
const formDate = watch("date");
290290
const formDuration = watch("duration");
291291
const date = new Date(formDate ?? "");
292292
const dateValue = useMemo(() => fromUIDate(formDate ?? ""), [formDate]);
293-
const focusDate = useMemo(
294-
() => focusSlot?.start ?? dateValue,
295-
[focusSlot, dateValue]
296-
);
297293
const duration = !Number.isNaN(Number(formDuration))
298294
? Number(formDuration)
299295
: reservationUnit.minReservationDuration ?? 0;
300-
const time = watch("time") ?? getTimeString(focusDate);
301296
const [areControlsVisible, setAreControlsVisible] = useState(false);
302297

303298
useEffect(() => {
@@ -306,28 +301,9 @@ const ReservationCalendarControls = ({
306301
}
307302
}, [setShouldCalendarControlsBeVisible, shouldCalendarControlsBeVisible]);
308303

309-
const startDate = t("common:dateWithWeekday", {
310-
date: start && toUIDate(start),
311-
});
312-
313-
const startTime = t("common:timeInForm", {
314-
date: time,
315-
});
316-
317-
const endDate = t("common:dateWithWeekday", {
318-
date: end && toUIDate(end),
319-
});
320-
321-
const endTime = t("common:timeInForm", {
322-
date: end && getTimeString(end),
323-
});
324-
325304
const togglerLabel = (() => {
326-
const dateStr = trim(
327-
`${capitalize(startDate)} ${startTime}${
328-
endDate !== startDate ? ` - ${capitalize(endDate)} ` : "-"
329-
}${endTime}`,
330-
"-"
305+
const dateStr = capitalize(
306+
formatDateTimeRange(t, focusSlot.start, focusSlot.end)
331307
);
332308
const durationStr =
333309
duration != null

apps/ui/pages/reservations/[id]/index.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { GetServerSidePropsContext } from "next";
33
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
44
import styled from "styled-components";
55
import router from "next/router";
6-
import { capitalize, isFinite, trim } from "lodash";
6+
import { capitalize } from "lodash";
77
import {
88
IconArrowRight,
99
IconCalendar,
@@ -29,7 +29,11 @@ import { Container } from "common";
2929
import { useOrder } from "@/hooks/reservation";
3030
import { reservationUnitPath } from "@/modules/const";
3131
import { createApolloClient } from "@/modules/apolloClient";
32-
import { getTranslation, reservationsUrl } from "@/modules/util";
32+
import {
33+
formatDateTimeRange,
34+
getTranslation,
35+
reservationsUrl,
36+
} from "@/modules/util";
3337
import { BlackButton } from "@/styles/util";
3438
import { CenterSpinner } from "@/components/common/common";
3539
import Sanitize from "@/components/common/Sanitize";
@@ -57,7 +61,6 @@ import {
5761
getGenericTerms,
5862
} from "@/modules/serverUtils";
5963
import { base64encode, filterNonNullable } from "common/src/helpers";
60-
import { fromApiDate } from "common/src/common/util";
6164
import { containsField, containsNameField } from "common/src/metaFieldsHelpers";
6265

6366
type Props = Awaited<ReturnType<typeof getServerSideProps>>["props"];
@@ -74,7 +77,7 @@ export async function getServerSideProps(ctx: GetServerSidePropsContext) {
7477
const commonProps = getCommonServerSideProps();
7578
const apolloClient = createApolloClient(commonProps.apiBaseUrl, ctx);
7679

77-
if (isFinite(pk)) {
80+
if (Number.isFinite(pk)) {
7881
const bookingTerms = await getGenericTerms(apolloClient);
7982

8083
// NOTE errors will fallback to 404
@@ -493,21 +496,8 @@ function Reservation({
493496
}
494497

495498
const { begin, end } = reservation;
496-
497-
const beginDate = t("common:dateWithWeekday", { date: fromApiDate(begin) });
498-
const beginTime = t("common:timeWithPrefixInForm", {
499-
date: fromApiDate(begin),
500-
});
501-
const endDate = t("common:dateWithWeekday", { date: fromApiDate(end) });
502-
const endTime = t("common:timeInForm", { date: fromApiDate(end) });
503-
504499
const timeString = capitalize(
505-
trim(
506-
`${beginDate} ${beginTime}-${
507-
endDate !== beginDate ? endDate : ""
508-
}${endTime}`,
509-
" - "
510-
)
500+
formatDateTimeRange(t, new Date(begin), new Date(end))
511501
);
512502

513503
const supportedFields = filterNonNullable(

0 commit comments

Comments
 (0)