Commit 224fe704 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

ixed

     availability-to-reservation handoff: resource ID and computed end time now transfer correctly via URL params
parent fbbee187
Loading
Loading
Loading
Loading
+18 −6
Changes for src/features/availability/AvailabilitySearchPage.tsx: 18 added lines, 6 removed lines.
Original line number Diff line number Diff line
import { useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import MenuItem from '@mui/material/MenuItem';
@@ -29,6 +29,7 @@ interface Props {

export function AvailabilitySearchPage({ onWindowSelect }: Props = {}) {
  const [searchParams] = useSearchParams();
  const navigate = useNavigate();

  const [poolId,            setPoolId]            = useState(searchParams.get('poolId') ?? '');
  const [membershipId,      setMembershipId]      = useState('');
@@ -71,8 +72,9 @@ export function AvailabilitySearchPage({ onWindowSelect }: Props = {}) {
        ...(requestedDuration.toMillis() > 0 ? { requestedDuration } : {}),
        ...(capacityAmount ? { capacityAmount } : {}),
      };
      const data = membershipId
        ? await resourceSearch.mutateAsync({ ...q, membershipId })
      const selectedMembership = memberships?.content.find(m => m.id === membershipId);
      const data = selectedMembership
        ? await resourceSearch.mutateAsync({ ...q, membershipId: selectedMembership.tmf639Id })
        : await poolSearch.mutateAsync(q);
      setResults(data);
    } finally {
@@ -85,6 +87,16 @@ export function AvailabilitySearchPage({ onWindowSelect }: Props = {}) {
      onWindowSelect(w);
    } else {
      setSelectedWindow(w);
      const toTs = requestedDuration.toMillis() > 0
        ? w.start.plus(requestedDuration).toISO()!
        : w.end.toISO()!;
      const params = new URLSearchParams({
        ...(poolId       ? { poolId }       : {}),
        ...(membershipId ? { membershipId } : {}),
        from: w.start.toISO()!,
        to:   toTs,
      });
      navigate(`/reservations?${params}`);
    }
  }

@@ -127,7 +139,7 @@ export function AvailabilitySearchPage({ onWindowSelect }: Props = {}) {
              >
                <MenuItem value="">— Any resource —</MenuItem>
                {memberships?.content.map(m => (
                  <MenuItem key={m.id} value={m.tmf639Id}>{m.tmf639Name ?? m.tmf639Id}</MenuItem>
                  <MenuItem key={m.id} value={m.id}>{m.tmf639Name ?? m.tmf639Id}</MenuItem>
                ))}
              </TextField>
            )}
@@ -203,11 +215,11 @@ export function AvailabilitySearchPage({ onWindowSelect }: Props = {}) {
                    <TableCell align="right">
                      <Button
                        size="small"
                        variant={selectedWindow === w ? 'contained' : 'outlined'}
                        variant="outlined"
                        aria-label={`select window ${i}`}
                        onClick={() => handleWindowSelect(w)}
                      >
                        {selectedWindow === w ? 'Selected' : 'Select'}
                        {onWindowSelect ? 'Select' : 'Book'}
                      </Button>
                    </TableCell>
                  </TableRow>
+3 −2
Changes for src/features/reservations/FirmReservationForm.tsx: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -17,14 +17,15 @@ interface Props {
  initialPoolId?: string;
  initialStart?: string;
  initialEnd?: string;
  initialMembershipId?: string;
}

export function FirmReservationForm({ initialPoolId = '', initialStart = '', initialEnd = '' }: Props) {
export function FirmReservationForm({ initialPoolId = '', initialStart = '', initialEnd = '', initialMembershipId = '' }: Props) {
  const firmMutation   = useCreateFirm();
  const cancelMutation = useCancelReservation();

  const [poolId,       setPoolId]       = useState(initialPoolId);
  const [membershipId, setMembershipId] = useState('');
  const [membershipId, setMembershipId] = useState(initialMembershipId);
  const [startDt,      setStartDt]      = useState<DateTime | null>(
    initialStart ? DateTime.fromISO(initialStart) : null,
  );
+3 −2
Changes for src/features/reservations/HoldRequestForm.tsx: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -17,13 +17,14 @@ interface Props {
  initialPoolId?: string;
  initialStart?: string;
  initialEnd?: string;
  initialMembershipId?: string;
}

export function HoldRequestForm({ initialPoolId = '', initialStart = '', initialEnd = '' }: Props) {
export function HoldRequestForm({ initialPoolId = '', initialStart = '', initialEnd = '', initialMembershipId = '' }: Props) {
  const holdMutation = useRequestHold();

  const [poolId,        setPoolId]        = useState(initialPoolId);
  const [membershipId,  setMembershipId]  = useState('');
  const [membershipId,  setMembershipId]  = useState(initialMembershipId);
  const [startDt,       setStartDt]       = useState<DateTime | null>(
    initialStart ? DateTime.fromISO(initialStart) : null,
  );
+3 −2
Changes for src/features/reservations/ReservationsPage.tsx: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ export function ReservationsPage() {
  const initialPoolId      = params.get('poolId')       ?? '';
  const initialStart       = params.get('from')         ?? '';
  const initialEnd         = params.get('to')           ?? '';
  const initialMembershipId = params.get('membershipId') ?? '';

  return (
    <Box sx={{ p: 2 }}>
@@ -22,8 +23,8 @@ export function ReservationsPage() {
        <Tab label="Hold Request" />
        <Tab label="Firm Reservation" />
      </Tabs>
      {tab === 0 && <HoldRequestForm initialPoolId={initialPoolId} initialStart={initialStart} initialEnd={initialEnd} />}
      {tab === 1 && <FirmReservationForm initialPoolId={initialPoolId} initialStart={initialStart} initialEnd={initialEnd} />}
      {tab === 0 && <HoldRequestForm initialPoolId={initialPoolId} initialStart={initialStart} initialEnd={initialEnd} initialMembershipId={initialMembershipId} />}
      {tab === 1 && <FirmReservationForm initialPoolId={initialPoolId} initialStart={initialStart} initialEnd={initialEnd} initialMembershipId={initialMembershipId} />}
    </Box>
  );
}