Skip to content
This repository was archived by the owner on May 19, 2026. It is now read-only.

refactor: migrate event creation flow to use centralized eventStore#77

Merged
DungxND merged 1 commit into
mainfrom
fix/event-create-err
Apr 16, 2026
Merged

refactor: migrate event creation flow to use centralized eventStore#77
DungxND merged 1 commit into
mainfrom
fix/event-create-err

Conversation

@DungxND
Copy link
Copy Markdown
Member

@DungxND DungxND commented Apr 16, 2026

  • Removed the event-create-store.ts file and replaced its functionality with a new eventStore.
  • Updated event detail types to remove is_seat_pickable property.
  • Refactored seatmap and shows creation pages to utilize the new eventStore for session management.
  • Enhanced seatmap creation logic to handle draft data more effectively.
  • Implemented PUT method for updating shows while preserving existing sections and seats.
  • Cleaned up unused code and improved overall structure for better maintainability.

Mô tả

Sửa lỗi khi tạo sự kiện mới do logic chưa đúng đắn.
Cải thiện lại UI và logic render seat map.

Closes #57

Loại thay đổi

  • 🐛 Bug fix
  • ♻️ Refactor

Screenshots / Demo

Checklist

  • Code chạy không lỗi (bun run dev)
  • TypeScript check pass (bun run check)
  • Lint pass (bun run lint)
  • Đã format code (bun run format)
  • Đã test thủ công chức năng
  • Commit message đúng convention (feat:, fix:, chore:,...)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added visual seatmap preview on event detail pages with interactive zoom and pan controls.
    • Added detailed section view displaying seat layouts, availability, and status information.
    • Enabled editing of shows after initial creation.
  • Improvements

    • Simplified section configuration UI by removing the seat selection toggle option.
    • Made prefix field available for all section types with context-specific guidance.
    • Enhanced section management with automatic reordering when removing sections.

- Removed the event-create-store.ts file and replaced its functionality with a new eventStore.
- Updated event detail types to remove is_seat_pickable property.
- Refactored seatmap and shows creation pages to utilize the new eventStore for session management.
- Enhanced seatmap creation logic to handle draft data more effectively.
- Implemented PUT method for updating shows while preserving existing sections and seats.
- Cleaned up unused code and improved overall structure for better maintainability.
@DungxND DungxND merged commit 26aee65 into main Apr 16, 2026
1 of 2 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ab82ec55-36c4-47d7-a2d1-39f92f046806

📥 Commits

Reviewing files that changed from the base of the PR and between 9004394 and ed719e1.

📒 Files selected for processing (19)
  • src/lib/components/admin/event/SectionDetail.svelte
  • src/lib/components/admin/event/SectionItem.svelte
  • src/lib/components/admin/seatmap/SeatmapBuilder.svelte
  • src/lib/components/admin/seatmap/SeatmapProperties.svelte
  • src/lib/components/admin/seatmap/TicketInventory.svelte
  • src/lib/components/customer/event/SeatmapPreview.svelte
  • src/lib/server/db/schema.ts
  • src/lib/server/services/event.service.ts
  • src/lib/server/services/seat.service.ts
  • src/lib/shared/schemas/event.schema.ts
  • src/lib/stores/event-create-store.svelte.ts
  • src/lib/stores/event-create-store.ts
  • src/lib/types/event-detail.ts
  • src/lib/utils/section-defaults.ts
  • src/routes/(admin)/admin/events/[id]/+page.svelte
  • src/routes/(admin)/admin/events/create/+page.svelte
  • src/routes/(admin)/admin/events/create/seatmap/+page.svelte
  • src/routes/(admin)/admin/events/create/shows/+page.svelte
  • src/routes/api/events/create/shows/+server.ts

📝 Walkthrough

Walkthrough

This PR removes the is_seat_pickable field throughout the codebase, adds a new Svelte 5 reactive store for event-creation state management, introduces new seatmap preview and section detail display components, and adds show-update capabilities to the service layer alongside schema/type consolidations.

Changes

Cohort / File(s) Summary
New Event Components
src/lib/components/admin/event/SectionDetail.svelte, src/lib/components/customer/event/SeatmapPreview.svelte
Added SectionDetail for rendering individual section UI (with assigned/general modes, seat grids, status pills, and availability tracking) and SeatmapPreview for read-only SVG seatmap visualization on customer-facing pages with zoom/pan, LOD rendering, and conversion helpers from admin/event-detail shapes.
Store Refactoring
src/lib/stores/event-create-store.svelte.ts (new), src/lib/stores/event-create-store.ts (removed)
Replaced old module-level sessionStorage helpers with a Svelte 5 reactive store class (EventCreateStore) using $state runes, providing singleton instance and backward-compatible named exports for event identity and draft persistence.
Service Layer Updates
src/lib/server/services/event.service.ts
Added new updateShows(adminId, data) method for transactional show editing (update existing, insert new, delete excess shows while preserving sections/seats). Modified insertSectionsWithSeats to always set isSeatPickable = true and getEventDetail to omit is_seat_pickable from response.
Schemas & Types
src/lib/shared/schemas/event.schema.ts, src/lib/types/event-detail.ts, src/lib/server/db/schema.ts, src/lib/utils/section-defaults.ts, src/lib/server/services/seat.service.ts
Removed is_seat_pickable from baseSectionSchema, EventDetailSection, draft validation, and service response mappings; added backward-compatibility is_seat_pickable?: boolean to SectionFormData; added rectangular stage layout item type (stage, obstacle, entrance) with width, height, rotation properties; updated schema comment only (no column removal).
Admin Section UI Components
src/lib/components/admin/event/SectionItem.svelte, src/lib/components/admin/seatmap/SeatmapBuilder.svelte, src/lib/components/admin/seatmap/SeatmapProperties.svelte, src/lib/components/admin/seatmap/TicketInventory.svelte
Removed is_seat_pickable toggle UI and auto-assignment logic from section editors; updated TicketInventory.removeSection to reassign sort_order, changed section-type change to force seat_config.cols = 1 and clear disabled_seats instead of toggling pickable, and extended prefix field to all section types with type-specific tooltips.
Event Management Pages
src/routes/(admin)/admin/events/[id]/+page.svelte, src/routes/(admin)/admin/events/create/shows/+page.svelte, src/routes/(admin)/admin/events/create/seatmap/+page.svelte, src/routes/(admin)/admin/events/create/+page.svelte
Updated all create/edit pages to use new eventStore singleton, refactored show edit flow to use PUT /api/events/create/shows, added SeatmapPreview and SectionDetail to event detail page, enhanced validation and error handling for section fields (prefix uniqueness, numeric conversions), and improved draft persistence with store methods.
API Endpoint
src/routes/api/events/create/shows/+server.ts
Added PUT handler calling eventService.updateShows(); existing POST handler comments updated for clarity on create vs. edit semantics.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin User
    participant UI as Shows Edit UI
    participant API as PUT /api/events/create/shows
    participant Service as eventService.updateShows()
    participant DB as Database (Transaction)
    
    Admin->>UI: Submit updated shows list
    UI->>API: PUT request with shows array
    API->>Service: updateShows(adminId, data)
    
    Service->>DB: BEGIN TRANSACTION
    Service->>DB: Validate event ownership & status
    Service->>DB: SELECT existing shows by id
    
    alt Update existing show
        Service->>DB: UPDATE eventShow (by index)
    else Insert new show
        Service->>DB: INSERT new eventShow
    end
    
    Service->>DB: Track kept show IDs
    Service->>DB: DELETE excess shows & cascade seats/seatSections
    Service->>DB: COMMIT TRANSACTION
    
    DB-->>Service: Transaction complete
    Service-->>API: Return updated shows metadata
    API-->>UI: json({ data: [...shows] })
    UI->>UI: Update local state, notify user
    
    Note over Admin,DB: Sections & seats preserved for updated shows
Loading
sequenceDiagram
    participant User as Customer
    participant EventPage as Event Detail Page
    participant Store as SeatmapPreview Component
    participant SVG as SVG Canvas
    
    User->>EventPage: Load event detail
    EventPage->>Store: Render SeatmapPreview with mapConfig, stageLayout, sections
    
    Store->>Store: Initialize container ResizeObserver
    Store->>Store: Set up zoom/pan state, tooltip tracking
    Store->>SVG: Render stage elements & section polygons
    
    alt Zoom Level ≥ threshold (assigned sections)
        Store->>SVG: Render individual seat dots (LOD detail)
    else Zoom < threshold
        Store->>SVG: Render section label, availability %, price tag
    end
    
    User->>SVG: Scroll/wheel to zoom
    Store->>Store: Update zoom level (bounded)
    Store->>SVG: Re-render with LOD
    
    User->>SVG: Hover over section
    Store->>Store: Update tooltip (section name, price, available)
    Store->>SVG: Show tooltip overlay
    
    Note over User,SVG: Interactive pan/zoom with responsive LOD rendering
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

The diff spans multiple architectural layers (store, service, schemas, UI components) with heterogeneous changes ranging from field removals to new complex components (SeatmapPreview with 658 lines and stateful SVG rendering). While many changes are straightforward removals or wiring updates, the new show-update transaction logic, reactive store implementation, intricate seatmap preview with LOD rendering, and validation enhancements across multiple pages require careful reasoning for correctness and integration consistency.

Possibly related PRs

Suggested reviewers

  • NguyenVanThanhTung

Poem

🐰 A store anew in Svelte's delight,
with reactive hops and state so right!
Gone is pickable, let seats stand tall—
preview and detail answer the call.
Shows dance in updates, a transaction's song,
TixTac's grand stage grows ever more strong! 🎭✨

✨ 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 fix/event-create-err

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Infra] Cập nhật hệ thống để hỗ trợ tuỳ chỉnh sâu cho sự kiện chuyên nghiệp

1 participant