Skip to content

Commit

Permalink
fix: my units calendar now shows the reservation name with prefix
Browse files Browse the repository at this point in the history
- makes translation function a required parameter in getReserveeName
  • Loading branch information
vincit-matu committed May 7, 2024
1 parent 43738b2 commit af80bc1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions apps/admin-ui/src/component/my-units/ReservationUnitCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "common/src/helpers";
import { RELATED_RESERVATION_STATES } from "common/src/const";
import { ReservationUnitWithAffectingArgs } from "common/src/queries/fragments";
import { TFunction } from "next-i18next";

type Props = {
begin: string;
Expand All @@ -50,14 +51,16 @@ const Container = styled.div`
const getEventTitle = ({
reservationUnitPk,
reservation,
t,
}: {
reservationUnitPk: number;
reservation: ReservationNode;
t: TFunction;
}) => {
const reservationUnit = reservation.reservationUnit?.[0];
const isOtherReservationUnit = reservationUnitPk !== reservationUnit?.pk;

const reserveeName = getReserveeName(reservation);
const reserveeName = getReserveeName(reservation, t);
if (isOtherReservationUnit) {
const reservationUnitName = reservationUnit?.nameFi ?? "";

Expand All @@ -67,10 +70,15 @@ const getEventTitle = ({
return [reserveeName, ""];
};

const constructEventTitle = (res: ReservationNode, resUnitPk: number) => {
const constructEventTitle = (
res: ReservationNode,
resUnitPk: number,
t: TFunction
) => {
const [reservee, unit] = getEventTitle({
reservationUnitPk: resUnitPk,
reservation: res,
t,
});
if (unit.length > 0) {
return `${reservee} (${unit})`;
Expand Down Expand Up @@ -124,7 +132,7 @@ export function ReservationUnitCalendar({
const events = reservations.map((reservation) => {
const isBlocked = reservation.type === ReservationTypeChoice.Blocked;
const title = !isBlocked
? constructEventTitle(reservation, reservationUnitPk)
? constructEventTitle(reservation, reservationUnitPk, t)
: t("MyUnits.Calendar.legend.closed");
return {
title,
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/component/my-units/UnitCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function getEventTitle({
}

return event && event?.pk !== event?.reservationUnit?.[0]?.pk
? getReserveeName(event)
? getReserveeName(event, t)
: title;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/component/reservations/requested/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const getTranslationKeyForCustomerTypeChoice = (

export const getReserveeName = (
reservation: ReservationNode,
t?: TFunction,
t: TFunction,
length = 50
): string => {
let prefix = "";
Expand Down

0 comments on commit af80bc1

Please sign in to comment.