Intercode SaaS Kit
  • Welcome to SaaS Starter Kit
  • Getting Started
    • Technology stack
    • Database Setup
    • Local Environment Setup
  • Basics
    • Dependencies
    • App architecture
    • Deployment
    • App roles
    • Endpoints List
      • Auth
      • Two Factor Auth
      • Businesses
      • Demo
      • Email
      • Export Document
      • Email Files
      • Files Demo
      • Leads
      • Orders
      • Payments
      • Subscriptions
      • Teams
      • Team Memberships
      • User Admin
  • Animation and Styles
    • Framer Motion
    • Ant Design and Styles
  • Pages
    • Auth
      • Working with PassportJS
      • Two-Factor Auth
      • OAuth Providers
    • Leads
    • Businesses
    • Team management
      • Ownership
    • Profile
    • User Settings
      • App Tour
    • App Settings
      • Lead Statuses
    • Dashboard
      • Lead volume widget
      • Doughnut chart widget
      • Recent leads table widget
      • Lead count over period widget
    • Demo
  • Features
    • Impersonation
    • Subscriptions (Stripe)
    • Search
    • Sentry
    • Captcha
    • Audit Logs
    • Internationalization
  • External integrations
    • Mailer
    • Google oAuth2
    • Facebook oAuth2
    • S3 compatible storage (AWS, MinIO)
Powered by GitBook
On this page
  1. Pages
  2. Dashboard

Recent leads table widget

ui/src/components/adminDashboard/widgets/RecentLeadsTableWidget

RecentLeadsTableWidget displaying 5 most recent leads for selected businesses and for choosen date range. It works like other widget and written like default table.

Table displays next information about lead:

  • Full name

  • Email

  • Photo

  • State

  • Status

  • Date added (createdAt)

  • Date updated (updatedAt)

Backend

On backend we have findFiveRecentLeads function which return us 5 entities which were created recently:

async findFiveRecentLeads(startDate: string, endDate: string, businessesIds: number[], teamId: string) {
        const start = dayjs(startDate);
        const end = dayjs(endDate);

        if (!start.isValid() || !end.isValid()) {
            throw new BadRequestException('Invalid date format');
        }

        const startOfDay = start.startOf('day').toDate();
        const endOfDay = end.endOf('day').toDate();

        const query = this.leadsRepository
            .createQueryBuilder('lead')
            .leftJoinAndSelect('lead.business', 'business')
            .leftJoinAndSelect('lead.status', 'status');

        query.andWhere('lead.teamId = :teamId', { teamId });

        query.andWhere('lead.createdAt BETWEEN :startOfDay AND :endOfDay', { startOfDay, endOfDay });

        query
            .andWhere('business.id IN (:...businessesIds)', { businessesIds })
            .orderBy('lead.createdAt', 'DESC')
            .take(5);

        const recentLeads = await query.getMany();

        return recentLeads;
    }

To achieve required result we filter leads createdAt, teamId, business columns and then we sort records by createdAt and take 5 top records.

PreviousDoughnut chart widgetNextLead count over period widget

Last updated 6 months ago