Distributor CRM
A CRM for truck dealers: stock ready at the factory, the pace of their own sales, and commercial offers to clients in one click.
- B2B CRM for a dealer network
- Next.js 16 / TypeScript / Supabase / PostgreSQL + RLS / TanStack Table / React PDF / Zod / Vitest
Problem
Dealers could not see which machines were ready at the factory and learned about stock over the phone. Commercial offers were assembled by hand, and the record of who was offered what got lost, so there was nothing to measure their own sales pace with.
Solution
A private CRM where every dealer sees factory stock with statuses and only their own clients and offers. A commercial offer is generated from the unit card as a PDF with the dealer's details and lands in a journal at once — the journal is what sales analytics is built from.
- 5
- unit statuses
- 2
- access levels: dealer and HQ
- 2
- PDF kinds: offer and brochure
- 30
- database migrations
Roles
Every role has its own menu, its own slice of data and its own limits. Here is what was built for each.
Dealer Manager
- Sees factory stock: available, reserved, in transit, on order
- Reserves a unit with a reservation deadline
- Generates offers with their own company details and contacts
- Sees only the clients and offers of their own organisation
HQ Admin
- Keeps the records: adds units, changes statuses, archives sold ones
- Manages dealers and users, can revoke access instantly
- Sees the offers of every dealer
- Edits the catalogue of chassis and bodies
Modules
- Stock
- A table of units with filters kept in the URL: ID, model, body type, wheel formula, VIN, year, colour, location, status, reservation deadline
- Unit card
- Chassis plus body, specifications, photos, warranty, internal price, a print version
- Commercial offers
- A PDF with the dealer's logo and details; specifications are frozen at creation; a journal with client, company, contacts, price and manager
- Dealers and access
- Organisations with legal details and onboarding, users with job titles, an access kill-switch
- Documents and rates
- A document library, exchange rates updated automatically for prices in euro and hryvnia
Integrations
- Supabase Auth
- Email and password sign-in, session refreshed in the proxy
- PostgreSQL RLS
- A dealer reads only their organisation's rows; HQ sees everything
- Supabase Storage
- A private bucket for PDFs, served through short-lived signed URLs
- React PDF
- Offers and brochures are generated on the server
- Cron
- Scheduled exchange-rate updates
- Спільна база з сайтом
- The marketing site reads the same catalogue and shows only what is in stock
Architecture
- Next.js 16 App Router: server actions for changes, a TanStack Table grid, filter state in the URL
- One Supabase database for two apps: the CRM owns the schema, the marketing site only reads
- A “chassis + body = product” model; a stock unit points to a product
- Database-level RLS: helper functions resolve the current user's organisation and role
- Private storage for PDFs with signed URLs
- Every response is closed to indexing; access only after sign-in
Engineering decisions
- Dealer separation lives in the database, not the interface: another dealer's offers will not come back even from a direct query
- Specifications in an offer are frozen as a snapshot: a document sent to a client does not change when the catalogue is updated
- PDFs with prices and contacts sit in a private bucket and are served through short-lived links
- The print form is designed on its own instead of being a screen capture
- The kill-switch is immediate: the role is checked together with the user's active flag
- The offer journal is the source of analytics: sales pace is counted from what the manager already does
What was delivered
- Factory stock table
- Statuses and reservations with a deadline
- Unit card with print
- PDF offers with dealer details
- Offer and client journal
- Data separation between dealers
- Dealer and access management
- Document library
- Exchange rates
- Archive of sold units
Need something similar?
Start a project