Skip to content

feat(cars): catálogo de reserva, agendamento manual no admin e correç…#394

Merged
rbxyz merged 1 commit into
mainfrom
388-intranet---regua-de-emocoes---correcoes
Jun 23, 2026
Merged

feat(cars): catálogo de reserva, agendamento manual no admin e correç…#394
rbxyz merged 1 commit into
mainfrom
388-intranet---regua-de-emocoes---correcoes

Conversation

@rbxyz

@rbxyz rbxyz commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

…ões de filial

  • Reserva (/cars): exibe o catálogo de veículos direto (sem gate de filtro); ao reservar, pede o intervalo explícito (início + devolução) e aponta Disponível/Ocupado via nova query vehicleRent.checkAvailability.
  • Admin: agendamento manual em nome de outro usuário (vehicleRent.createForUser)
    • componente ManualRentForm; badge "Sem filial" nos veículos legados.
  • Corrige edição de veículo: empresa/filial agora vêm preenchidas (empresa derivada da filial salva, sem corrida de efeitos).
  • Backfill de filial para veículos legados quando o mapeamento é inequívoco.
  • Calendário de /cars: cada reserva ganha cor própria estendida por todo o intervalo (start → possibleEnd).

Summary by CodeRabbit

Release Notes

  • New Features

    • Admins can now create manual vehicle reservations on behalf of other users.
    • Enhanced vehicle calendar displays reservations across multiple days with improved visual indicators.
    • Real-time availability checking prevents double-booking conflicts during reservation.
    • Vehicles page now filters by company and branch for easier browsing.
    • Legacy vehicle records now have branch information automatically populated.
  • Version

    • Updated to v1.50.1

…ões de filial

- Reserva (/cars): exibe o catálogo de veículos direto (sem gate de filtro);
  ao reservar, pede o intervalo explícito (início + devolução) e aponta
  Disponível/Ocupado via nova query vehicleRent.checkAvailability.
- Admin: agendamento manual em nome de outro usuário (vehicleRent.createForUser)
  + componente ManualRentForm; badge "Sem filial" nos veículos legados.
- Corrige edição de veículo: empresa/filial agora vêm preenchidas (empresa
  derivada da filial salva, sem corrida de efeitos).
- Backfill de filial para veículos legados quando o mapeamento é inequívoco.
- Calendário de /cars: cada reserva ganha cor própria estendida por todo o
  intervalo (start → possibleEnd).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: elo.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@rbxyz
rbxyz merged commit 1f53f55 into main Jun 23, 2026
1 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a79ec82-46fb-4bff-81a3-72a356486598

📥 Commits

Reviewing files that changed from the base of the PR and between 794804a and 44846ab.

📒 Files selected for processing (10)
  • package.json
  • prisma/migrations/20260622120000_backfill_vehicle_filial/migration.sql
  • src/app/(authenticated)/admin/vehicles/page.tsx
  • src/app/(authenticated)/cars/page.tsx
  • src/components/admin/vehicles/manual-rent-form.tsx
  • src/components/admin/vehicles/vehicle-form.tsx
  • src/components/vehicles/rent-form.tsx
  • src/components/vehicles/vehicle-calendar.tsx
  • src/schemas/vehicle-rent.schema.ts
  • src/server/api/routers/vehicle-rent.ts

📝 Walkthrough

Walkthrough

This PR adds an admin manual rent scheduling feature (new ManualRentForm, createForUser backend procedure, createVehicleRentForUserSchema), extends RentForm with real-time availability checking via a new checkAvailability endpoint, refactors the Cars page to a catalog-based reservation flow, fixes VehicleForm's empresa/filial derivation, adds multi-day spanning and deterministic coloring to the vehicle calendar, and includes a data migration to backfill legacy filialId values.

Changes

Vehicle Rental Enhancements

Layer / File(s) Summary
Schema and backend: createRentForUser helper, checkAvailability, createForUser procedure
src/schemas/vehicle-rent.schema.ts, src/server/api/routers/vehicle-rent.ts
Adds createVehicleRentForUserSchema and CreateVehicleRentForUserInput; extracts shiftRentDate() and CreateRentFields; adds createRentForUser() transaction helper with conflict detection; adds checkAvailability procedure returning structured availability; adds createForUser admin mutation with hasAdminAccess gating; refactors create to delegate to the shared helper.
ManualRentForm component and admin vehicles page integration
src/components/admin/vehicles/manual-rent-form.tsx, src/app/(authenticated)/admin/vehicles/page.tsx
New ManualRentForm with user search, empresa/filial filtering, vehicle selection, scheduling toggle, datetime pickers, and trip details, wired to createForUser; admin vehicles page adds a Dialog/CalendarPlus trigger for this form; filial display updated to show a destructive "Sem filial" badge when absent.
RentForm: availability checking, validation refactor, and UI indicators
src/components/vehicles/rent-form.tsx
Adds now state for immediate start defaults; derives intervalStart/hasInterval to drive checkAvailability query; maps isOccupied/isAvailable; refactors handleSubmit with create vs edit validation rules; blocks submission on conflict; adds availability indicator badges; disables submit on isOccupied or checkingAvailability.
Cars page: catalog-based reservation flow
src/app/(authenticated)/cars/page.tsx
Removes date/time filter state and query parameterization; adds reserveVehicle state; changes vehicles query to always fetch available cars; replaces date/time UI with EmpresaFilialFilter catalog and reserve buttons; adds a Dialog wrapping RentForm; adds view-only card for non-reserve users; adds auxiliary catalog link.
VehicleForm: derived effectiveEmpresaId from filialId
src/components/admin/vehicles/vehicle-form.tsx
Replaces useEffect-based empresa/filial sync with derived empresaFromFilial and effectiveEmpresaId; updates filiais memo, Empresa select value, and Filial select disabled/placeholder to use the derived effective company.
Vehicle calendar: multi-day spanning and deterministic colors
src/components/vehicles/vehicle-calendar.tsx
Adds RESERVATION_COLORS palette and colorForReservation() hash; introduces spanningByDay memo expanding reservations across their full interval; switches grid to spanningByDay; reworks pill rendering with interval-aware rounding/borders and start-day/Sunday label visibility.
FilialId backfill migration and version bump
prisma/migrations/.../migration.sql, package.json
SQL migration backfills vehicles.filialId for legacy records via enterprise→filial mapping, only when unambiguous (COUNT = 1); version bumped from 1.47.0 to 1.50.1.

Sequence Diagram(s)

sequenceDiagram
  participant Admin as Admin User
  participant AdminPage as Admin Vehicles Page
  participant ManualRentForm as ManualRentForm
  participant vehicleRentRouter as vehicleRentRouter
  participant DB as Database

  Admin->>AdminPage: clicks "Novo Agendamento"
  AdminPage->>ManualRentForm: opens Dialog
  Admin->>ManualRentForm: searches user, selects vehicle, sets dates
  ManualRentForm->>vehicleRentRouter: createForUser(userId, vehicleId, dates, details)
  vehicleRentRouter->>vehicleRentRouter: hasAdminAccess check
  vehicleRentRouter->>DB: validate target userId
  vehicleRentRouter->>DB: $transaction — conflict check + create vehicleRent
  DB-->>vehicleRentRouter: vehicleRent record
  vehicleRentRouter-->>ManualRentForm: success
  ManualRentForm-->>AdminPage: onSuccess → close Dialog + refetch
Loading
sequenceDiagram
  participant User as User
  participant RentForm as RentForm
  participant vehicleRentRouter as vehicleRentRouter
  participant DB as Database

  User->>RentForm: selects vehicle + dates
  RentForm->>vehicleRentRouter: checkAvailability(vehicleId, start, end)
  vehicleRentRouter->>DB: query overlapping unfinished rents
  DB-->>vehicleRentRouter: conflict or null
  vehicleRentRouter-->>RentForm: available / occupied + reason
  RentForm->>RentForm: show availability badge (loading/occupied/available)
  alt Vehicle is occupied
    User->>RentForm: clicks submit
    RentForm->>RentForm: show "Veículo ocupado" toast, block submit
  else Vehicle is available
    User->>RentForm: clicks submit
    RentForm->>vehicleRentRouter: create(startDate, endDate, ...)
    vehicleRentRouter-->>RentForm: vehicleRent created
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • GRHInvDev/elo#154: Both PRs modify src/components/vehicles/vehicle-calendar.tsx; the retrieved PR changes the reservation data shape consumed by the calendar, while this PR changes how those reservations are expanded and rendered across multiple days with deterministic coloring.

Poem

🐇 A calendar that spans the days,
Now colors reservations in bright arrays.
The admin books a ride with flair,
While availability floats in the air.
No conflicts slip past—the bunny checks twice,
And filials backfilled make the data nice! 🗓️

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 388-intranet---regua-de-emocoes---correcoes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant