Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: my units calendar now shows the reservation name with prefix #1161

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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