Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

2.8 KB
Raw Blame
import { Component, Show } from 'solid-js';
import SettingsPanel from '@/components/shared/SettingsPanel';
import { Button } from '@/components/shared/Button';
import {
  ORGANIZATION_SETTINGS_UNAVAILABLE_CLASS as ORGANIZATION_SETTINGS_PANEL_UNAVAILABLE_CLASS,
  ORGANIZATION_SETTINGS_UNAVAILABLE_MESSAGE as ORGANIZATION_SETTINGS_PANEL_UNAVAILABLE_MESSAGE,
} from '@/utils/organizationSettingsPresentation';
import { BillingAdminOrganizationsTable } from './BillingAdminOrganizationsTable';
import { useBillingAdminPanelState } from './useBillingAdminPanelState';

export const BillingAdminPanel: Component = () => {
  const state = useBillingAdminPanelState();

  return (
    <Show
      when={state.hostedEnabled()}
      fallback={
        <div class={ORGANIZATION_SETTINGS_PANEL_UNAVAILABLE_CLASS}>
          {ORGANIZATION_SETTINGS_PANEL_UNAVAILABLE_MESSAGE}
        </div>
      }
    >
      <SettingsPanel
        title="Billing Admin"
        action={
          <Button
            variant="secondary"
            size="sm"
            class="w-full sm:w-auto"
            onClick={() => {
              void state.refreshOrganizations();
            }}
            disabled={state.loadingOrgs()}
          >
            Refresh
          </Button>
        }
        bodyClass="space-y-4"
      >
        <Show when={state.orgsError()}>
          <div
            role="alert"
            class="rounded-md border border-red-200 dark:border-red-900/25 bg-red-50 dark:bg-red-900/25 p-3 text-sm text-red-800 dark:text-red-200"
          >
            {state.orgsError()}
          </div>
        </Show>

        <Show when={!state.orgsError()}>
          <div class="mt-4" aria-busy={state.loadingOrgs()}>
            <BillingAdminOrganizationsTable
              orgs={state.orgs()}
              isLoading={state.loadingOrgs()}
              billingByOrgID={state.billingByOrgID()}
              billingLoadingByOrgID={state.billingLoadingByOrgID()}
              billingErrorByOrgID={state.billingErrorByOrgID()}
              canManageBilling={state.canManageBilling()}
              savingByOrgID={state.savingByOrgID()}
              expandedOrgID={state.expandedOrgID()}
              onToggleOrganization={(orgID) => {
                void state.toggleExpandedOrganization(orgID);
              }}
              onSuspendOrganization={(orgID) => {
                void state.updateSubscriptionState(orgID, 'suspended');
              }}
              onActivateOrganization={(orgID) => {
                void state.updateSubscriptionState(orgID, 'active');
              }}
              onReloadOrganization={(orgID) => {
                void state.reloadOrganization(orgID);
              }}
            />
          </div>
        </Show>
      </SettingsPanel>
    </Show>
  );
};

export default BillingAdminPanel;