tenant-table.tsx


Overview

The tenant-table.tsx file defines a React functional component named TenantTable. This component displays a list of tenants associated with the current user in a tabular format using the Ant Design Table component. The table includes tenant details such as name, email, last update date, and context-sensitive action buttons allowing the user to agree to or refuse tenant invitations or quit a tenant.

This file primarily manages data presentation and user interactions related to tenant membership status, leveraging various custom hooks to fetch data and handle user actions. It is a UI component designed to be embedded in user settings or tenant management pages within a larger application.


Detailed Explanation

TenantTable Component

const TenantTable = () => { ... }

Description

TenantTable is a React functional component that renders a table listing tenants. It fetches tenant data and user information via custom hooks, formats dates, and conditionally displays action buttons based on the tenant's role and the logged-in user's identity.

Hooks Used

Table Columns

The columns are defined using Ant Design's TableProps<ITenant>['columns'] type, ensuring type safety for the tenant data structure.

Column

Data Index

Description

Special Rendering

Name

nickname

Tenant's display name

Raw text

Email

email

Tenant's email address

Raw text

Update Date

update_date

The last update timestamp for the tenant record

Rendered using formatDate(value) util function for readable formatting

Action

Contextual action buttons based on tenant role and user identity

Conditional rendering of buttons (Agree, Refuse, Quit)

Action Column Logic

Return Value

The component returns an Ant Design Table component configured with:


Interfaces and Types

ITenant

Imported from @/interfaces/database/user-setting

Represents the tenant data object structure with at least the following properties used here:

TableProps

From antd — used to type the columns array for the Ant Design table.

TenantRole

Enum imported from ../constants defining roles like:


Important Implementation Details


Usage Example

This component is typically used in a user settings or admin panel where a user can view and manage their tenant memberships.

import TenantTable from './tenant-table';

const TenantSettingsPage = () => {
  return (
    <div>
      <h1>Tenant Management</h1>
      <TenantTable />
    </div>
  );
};

Interaction with Other System Parts

This modular design ensures the component can be embedded and reused within various parts of the tenant/user management UI without direct coupling to backend implementations.


Mermaid Component Diagram

componentDiagram
    component TenantTable {
        +Render Table<ITenant>
        +Uses useListTenant()
        +Uses useFetchUserInfo()
        +Uses useHandleAgreeTenant()
        +Uses useHandleQuitUser()
        +Uses useTranslation()
    }

    component Table {
        +columns
        +dataSource
        +rowKey
        +loading
    }

    TenantTable --> Table : renders
    TenantTable --> useListTenant : fetch tenants data
    TenantTable --> useFetchUserInfo : fetch user data
    TenantTable --> useHandleAgreeTenant : agree/refuse invite handlers
    TenantTable --> useHandleQuitUser : quit tenant handler
    TenantTable --> useTranslation : i18n text
    TenantTable --> formatDate : format update_date

Summary

tenant-table.tsx is a self-contained React component responsible for displaying tenant membership data in a table and providing user actions relevant to tenant invitations and participation. It leverages hooks for data management, utility functions for formatting, and Ant Design components for UI rendering. Its design promotes clean separation of concerns, reusability, and localization support within tenant/user management features of the application.