Skip to content

Commit

Permalink
Refactor logic for 'Pickup' and 'No Interest' modals
Browse files Browse the repository at this point in the history
Move the logic into PhysicalListDetails and use the result of getReadyForPickup().length > 0 as a boolean to determine whether the buttons and modals should be rendered.
  • Loading branch information
kasperbirch1 committed Nov 10, 2023
1 parent 12e12ee commit 67257ce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
setAccepted(false);
};

const isReservationNotReadyForLoan =
reservationForModal &&
readyToLoanReservations.some(
({ faust }) => faust !== reservationForModal.faust
);

return (
<>
<div className="status-userprofile">
Expand Down Expand Up @@ -331,7 +325,6 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
modalId={`${reservationDetails}${String(modalReservationDetailsId)}`}
>
<ReservationDetails
isPossibleToChangeReservationDetails={isReservationNotReadyForLoan}
openReservationDeleteModal={openReservationDeleteModal}
faust={reservationForModal.faust}
identifier={reservationForModal.identifier}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import ReservationFormListItem from "../../../../components/reservation/Reservat
import NoInterestAfterModal from "../../../../components/reservation/forms/NoInterestAfterModal";
import { RequestStatus } from "../../../../core/utils/types/request";
import { formatDate } from "../../../../core/utils/helpers/date";
import { getReadyForPickup } from "../../utils/helpers";

interface PhysicalListDetailsProps {
reservation: ReservationType;
isPossibleToChangeReservationDetails?: boolean | null;
}

const PhysicalListDetails: FC<PhysicalListDetailsProps & MaterialProps> = ({
reservation,
reservation: {
numberInQueue,
pickupBranch,
Expand All @@ -45,8 +46,7 @@ const PhysicalListDetails: FC<PhysicalListDetailsProps & MaterialProps> = ({
dateOfReservation,
pickupNumber,
reservationId
},
isPossibleToChangeReservationDetails = true
}
}) => {
const config = useConfig();
const t = useText();
Expand Down Expand Up @@ -78,6 +78,8 @@ const PhysicalListDetails: FC<PhysicalListDetailsProps & MaterialProps> = ({
blacklistBranches
);

const isReadyForPickup = getReadyForPickup([reservation]).length > 0;

const saveChanges = () => {
setReservationStatus("pending");
if (!reservationId || !selectedBranch) {
Expand Down Expand Up @@ -141,11 +143,9 @@ const PhysicalListDetails: FC<PhysicalListDetailsProps & MaterialProps> = ({
changeHandler={openModal("pickup")}
buttonAriaLabel={t("changePickupLocationText")}
subText={pickupNumber ?? ""}
isPossibleToChangeReservationDetails={
isPossibleToChangeReservationDetails
}
isPossibleToChangeReservationDetails={!isReadyForPickup}
/>
{isPossibleToChangeReservationDetails && (
{!isReadyForPickup && (
<PickupModal
branches={whitelistBranches}
defaultBranch={pickupBranch}
Expand All @@ -169,11 +169,9 @@ const PhysicalListDetails: FC<PhysicalListDetailsProps & MaterialProps> = ({
}
changeHandler={openModal("interestPeriod")}
buttonAriaLabel={t("changeInterestPeriodText")}
isPossibleToChangeReservationDetails={
isPossibleToChangeReservationDetails
}
isPossibleToChangeReservationDetails={!isReadyForPickup}
/>
{isPossibleToChangeReservationDetails && (
{!isReadyForPickup && (
<NoInterestAfterModal
selectedInterest={selectedInterest ?? 90}
setSelectedInterest={setSelectedInterest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import { useConfig } from "../../../../core/utils/config";
export interface ReservationDetailsProps {
reservation: ReservationType;
openReservationDeleteModal: (deleteReservation: ReservationType) => void;
isPossibleToChangeReservationDetails?: boolean | null;
}

const ReservationDetails: FC<ReservationDetailsProps & MaterialProps> = ({
reservation,
material,
openReservationDeleteModal,
isPossibleToChangeReservationDetails
openReservationDeleteModal
}) => {
const t = useText();
const config = useConfig();
Expand Down Expand Up @@ -79,14 +77,7 @@ const ReservationDetails: FC<ReservationDetailsProps & MaterialProps> = ({
)}
<div className="modal-details__list">
{isDigital && <DigitalListDetails reservation={reservation} />}
{!isDigital && (
<PhysicalListDetails
reservation={reservation}
isPossibleToChangeReservationDetails={
isPossibleToChangeReservationDetails
}
/>
)}
{!isDigital && <PhysicalListDetails reservation={reservation} />}
</div>
{reservation.reservationId && allowUserRemoveReadyReservations && (
<ReservationDetailsButton
Expand Down
2 changes: 1 addition & 1 deletion src/components/reservation/ReservationFormListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ReservationFormListItemProps {
subText?: string;
changeHandler?: () => void;
buttonAriaLabel?: string;
isPossibleToChangeReservationDetails?: boolean | null;
isPossibleToChangeReservationDetails?: boolean;
}

const ReservationFormListItem: React.FC<ReservationFormListItemProps> = ({
Expand Down

0 comments on commit 67257ce

Please sign in to comment.