Skip to content

Commit

Permalink
Set more precise types on requestsAndReservations
Browse files Browse the repository at this point in the history
`requests`was not inferred correctly.
  • Loading branch information
spaceo committed Nov 28, 2023
1 parent 54db1a9 commit 2e8005b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useMemo, useState } from "react";
import { UseMutateFunction, useQueryClient } from "react-query";
import { useQueryClient } from "react-query";
import Modal from "../../../../core/utils/modal";
import { useText } from "../../../../core/utils/text";
import DeleteReservationContent from "./delete-reservation-content";
Expand All @@ -9,34 +9,21 @@ import {
useDeleteV1UserReservationsIdentifier
} from "../../../../core/publizon/publizon";
import { useMultipleRequestsWithStatus } from "../../../../core/utils/useRequestsWithStatus";
import { requestsAndReservations } from "./helper";
import {
OperationDigital,
OperationPhysical,
ParamsDigital,
ParamsPhysical,
requestsAndReservations
} from "./helper";
import ModalMessage from "../../../../components/message/modal-message/ModalMessage";
import { DeleteReservationsParams } from "../../../../core/fbs/model";
import { ApiResult } from "../../../../core/publizon/model";
import {
reservationId,
ReservationType
} from "../../../../core/utils/types/reservation-type";
import { getModalIds } from "../../../../core/utils/helpers/modal-helpers";

type ParamsDigital = {
identifier: string;
};
type ParamsPhysical = {
params?: DeleteReservationsParams;
};
type OperationDigital = UseMutateFunction<
ApiResult | null,
unknown,
ParamsDigital,
unknown
>;
type OperationPhysical = UseMutateFunction<
void | null,
unknown,
ParamsPhysical,
unknown
>;
interface DeleteReservationModalProps {
modalId: string;
reservations: ReservationType[];
Expand Down Expand Up @@ -64,7 +51,7 @@ const DeleteReservationModal: FC<DeleteReservationModalProps> = ({

const { requests, reservationsPhysical, reservationsDigital } = useMemo(
() =>
requestsAndReservations<OperationPhysical, OperationDigital>({
requestsAndReservations({
operations: {
digital: deleteDigitalReservation,
physical: deletePhysicalReservation
Expand Down
36 changes: 33 additions & 3 deletions src/apps/reservation-list/modal/delete-reservation/helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import { UseMutateFunction } from "react-query";
import { DeleteReservationsParams } from "../../../../core/fbs/model";
import { UseTextFunction } from "../../../../core/utils/text";
import { RequestStatus } from "../../../../core/utils/types/request";
import {
ReservationType,
isDigitalReservation,
isPhysicalReservation
} from "../../../../core/utils/types/reservation-type";
import { ApiResult } from "../../../../core/publizon/model";

export type ParamsDigital = {
identifier: string;
};
export type ParamsPhysical = {
params?: DeleteReservationsParams;
};
export type OperationDigital = UseMutateFunction<
ApiResult | null,
unknown,
ParamsDigital,
unknown
>;
export type OperationPhysical = UseMutateFunction<
void | null,
unknown,
ParamsPhysical,
unknown
>;
type Request = {
params: { params: { reservationid: number[] } } | { identifier: string };
operation: OperationPhysical | OperationDigital;
};

export const getReservationsToDelete = (reservations: ReservationType[]) => {
if (!reservations.length) {
Expand Down Expand Up @@ -62,13 +88,17 @@ export const getDeleteButtonLabel = ({
});
};

export const requestsAndReservations = <TOperationPhysical, TOperationDigital>({
export const requestsAndReservations = ({
reservations,
operations
}: {
reservations: ReservationType[];
operations: { physical: TOperationPhysical; digital: TOperationDigital };
}) => {
operations: { physical: OperationPhysical; digital: OperationDigital };
}): {
requests: Request[];
reservationsPhysical: number[];
reservationsDigital: string[];
} => {
const { physical: reservationsPhysical, digital: reservationsDigital } =
getReservationsToDelete(reservations);

Expand Down

0 comments on commit 2e8005b

Please sign in to comment.