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.

4.4 KB
Raw Blame
import { Component, For, Show } from 'solid-js';
import { Button } from '@/components/shared/Button';
import { FormSelect } from '@/components/shared/FormSelect';
import { OrganizationRoleBadge } from '@/components/shared/OrganizationBadges';
import { PulseDataGrid } from '@/components/shared/PulseDataGrid';
import { ORGANIZATION_MEMBER_ROLE_OPTIONS } from '@/utils/organizationRolePresentation';
import { DEFAULT_ORG_SCOPE } from '@/utils/orgScope';
import { formatOrgDate, normalizeRole } from '@/utils/orgUtils';
import { getOrganizationAccessEmptyState } from '@/utils/organizationSettingsPresentation';
import Trash2 from 'lucide-solid/icons/trash-2';
import type { OrganizationMember, OrganizationRole } from '@/api/orgs';
import type { useOrganizationAccessPanelState } from './useOrganizationAccessPanelState';

interface OrganizationAccessMembersSectionProps {
  currentUser?: string;
  state: ReturnType<typeof useOrganizationAccessPanelState>;
}

export const OrganizationAccessMembersSection: Component<OrganizationAccessMembersSectionProps> = (
  props,
) => (
  <Show when={props.state.org()}>
    {(currentOrg) => (
      <PulseDataGrid
        class="mt-4"
        data={props.state.members()}
        columns={[
          {
            key: 'userId',
            label: 'User',
            render: (member) => <span class="text-base-content">{member.userId}</span>,
          },
          {
            key: 'role',
            label: 'Role',
            render: (member) => {
              const role = normalizeRole(member.role);
              const isOwner = () => member.userId === currentOrg().ownerUserId;
              return (
                <Show
                  when={props.state.canManageCurrentOrg() && currentOrg().id !== DEFAULT_ORG_SCOPE}
                  fallback={<OrganizationRoleBadge role={role} />}
                >
                  <FormSelect
                    label={`Role for ${member.userId}`}
                    labelClass="sr-only"
                    fieldBaseClass="contents"
                    value={role}
                    onChange={(event) => {
                      void props.state.updateRole(
                        member,
                        event.currentTarget.value as OrganizationRole,
                      );
                    }}
                    disabled={
                      props.state.saving() ||
                      (isOwner() && props.currentUser !== currentOrg().ownerUserId)
                    }
                    selectBaseClass="rounded-md border border-border bg-surface px-2 py-1 text-xs text-base-content shadow-xs focus:border-blue-500 focus:outline-hidden focus:ring-2 focus:ring-blue-500 disabled:cursor-not-allowed disabled:opacity-60"
                  >
                    <For
                      each={ORGANIZATION_MEMBER_ROLE_OPTIONS.filter(
                        (option) =>
                          option.value !== 'owner' ||
                          props.currentUser === currentOrg().ownerUserId,
                      )}
                    >
                      {(option) => <option value={option.value}>{option.label}</option>}
                    </For>
                  </FormSelect>
                </Show>
              );
            },
          },
          {
            key: 'addedAt',
            label: 'Added',
            hiddenOnMobile: true,
            render: (member) => <span class="text-muted">{formatOrgDate(member.addedAt)}</span>,
          },
          {
            key: 'actions',
            label: 'Actions',
            align: 'right',
            render: (member: OrganizationMember) => {
              const isOwner = () => member.userId === currentOrg().ownerUserId;
              return (
                <Show when={props.state.canManageCurrentOrg() && !isOwner()}>
                  <Button
                    variant="dangerGhost"
                    size="xs"
                    class="gap-1"
                    onClick={() => {
                      void props.state.removeMember(member);
                    }}
                    disabled={props.state.saving()}
                  >
                    <Trash2 class="w-3.5 h-3.5" />
                    Remove
                  </Button>
                </Show>
              );
            },
          },
        ]}
        keyExtractor={(member) => member.userId}
        emptyState={getOrganizationAccessEmptyState()}
        desktopMinWidth="700px"
      />
    )}
  </Show>
);