Format with prettier. Use screen mode for invitation import - dialog mode is broken.

This commit is contained in:
2026-03-23 10:15:48 +00:00
parent 7fd89c5663
commit b475b23beb
47 changed files with 1718 additions and 1098 deletions

View File

@@ -1,20 +1,20 @@
/**
* Invitation utility functions.
*
*
* Pure functions for parsing and formatting invitation data.
* These functions have no React dependencies and can be used
* in both TUI and CLI contexts.
*/
import type { Invitation } from '../services/invitation.js';
import type { XOTemplate } from '@xo-cash/types';
import type { Invitation } from "../services/invitation.js";
import type { XOTemplate } from "@xo-cash/types";
/**
* Color names for invitation states.
* These are semantic color names that can be mapped to actual colors
* by the consuming application (TUI or CLI).
*/
export type StateColorName = 'info' | 'warning' | 'success' | 'error' | 'muted';
export type StateColorName = "info" | "warning" | "success" | "error" | "muted";
/**
* Input data extracted from invitation commits.
@@ -61,7 +61,7 @@ export interface FormattedInvitationItem {
/**
* Get the current state/status of an invitation.
*
*
* @param invitation - The invitation to get state for
* @returns The status string
*/
@@ -71,34 +71,34 @@ export function getInvitationState(invitation: Invitation): string {
/**
* Get the semantic color name for an invitation state.
*
*
* @param state - The invitation state string
* @returns A semantic color name
*/
export function getStateColorName(state: string): StateColorName {
switch (state) {
case 'created':
case 'published':
return 'info';
case 'pending':
return 'warning';
case 'ready':
case 'signed':
case 'complete':
case 'broadcast':
case 'completed':
return 'success';
case 'expired':
case 'error':
return 'error';
case "created":
case "published":
return "info";
case "pending":
return "warning";
case "ready":
case "signed":
case "complete":
case "broadcast":
case "completed":
return "success";
case "expired":
case "error":
return "error";
default:
return 'muted';
return "muted";
}
}
/**
* Extract all inputs from invitation commits.
*
*
* @param invitation - The invitation to extract inputs from
* @returns Array of input data
*/
@@ -118,11 +118,13 @@ export function getInvitationInputs(invitation: Invitation): InvitationInput[] {
/**
* Extract all outputs from invitation commits.
*
*
* @param invitation - The invitation to extract outputs from
* @returns Array of output data
*/
export function getInvitationOutputs(invitation: Invitation): InvitationOutput[] {
export function getInvitationOutputs(
invitation: Invitation,
): InvitationOutput[] {
const outputs: InvitationOutput[] = [];
for (const commit of invitation.data.commits || []) {
for (const output of commit.data?.outputs || []) {
@@ -139,11 +141,13 @@ export function getInvitationOutputs(invitation: Invitation): InvitationOutput[]
/**
* Extract all variables from invitation commits.
*
*
* @param invitation - The invitation to extract variables from
* @returns Array of variable data
*/
export function getInvitationVariables(invitation: Invitation): InvitationVariable[] {
export function getInvitationVariables(
invitation: Invitation,
): InvitationVariable[] {
const variables: InvitationVariable[] = [];
for (const commit of invitation.data.commits || []) {
for (const variable of commit.data?.variables || []) {
@@ -160,14 +164,17 @@ export function getInvitationVariables(invitation: Invitation): InvitationVariab
/**
* Get the user's role from commits (the role they have accepted).
*
*
* @param invitation - The invitation to check
* @param userEntityId - The user's entity identifier
* @returns The role identifier if found, null otherwise
*/
export function getUserRole(invitation: Invitation, userEntityId: string | null): string | null {
export function getUserRole(
invitation: Invitation,
userEntityId: string | null,
): string | null {
if (!userEntityId) return null;
for (const commit of invitation.data.commits || []) {
if (commit.entityIdentifier === userEntityId) {
// Check inputs for role
@@ -189,32 +196,32 @@ export function getUserRole(invitation: Invitation, userEntityId: string | null)
/**
* Format an invitation for display in a list.
*
*
* @param invitation - The invitation to format
* @param template - Optional template for additional info (name)
* @returns Formatted item data for display
*/
export function formatInvitationListItem(
invitation: Invitation,
template?: XOTemplate | null
template?: XOTemplate | null,
): FormattedInvitationItem {
// Validate that we have the minimum required data
const invitationId = invitation?.data?.invitationIdentifier;
const actionId = invitation?.data?.actionIdentifier;
if (!invitationId || !actionId) {
return {
label: '',
status: 'error',
statusColor: 'error',
label: "",
status: "error",
statusColor: "error",
isValid: false,
};
}
const state = getInvitationState(invitation);
const templateName = template?.name ?? 'Unknown';
const templateName = template?.name ?? "Unknown";
const shortId = formatInvitationId(invitationId, 8);
return {
label: `[${state}] ${templateName}-${actionId} (${shortId})`,
status: state,
@@ -225,7 +232,7 @@ export function formatInvitationListItem(
/**
* Format an invitation ID for display (truncated).
*
*
* @param id - The full invitation ID
* @param maxLength - Maximum length for display
* @returns Truncated ID string
@@ -238,7 +245,7 @@ export function formatInvitationId(id: string, maxLength: number = 16): string {
/**
* Get all unique entity identifiers from an invitation's commits.
*
*
* @param invitation - The invitation to check
* @returns Array of unique entity identifiers
*/
@@ -254,12 +261,15 @@ export function getInvitationParticipants(invitation: Invitation): string[] {
/**
* Check if a user is a participant in an invitation.
*
*
* @param invitation - The invitation to check
* @param userEntityId - The user's entity identifier
* @returns True if the user has made at least one commit
*/
export function isUserParticipant(invitation: Invitation, userEntityId: string | null): boolean {
export function isUserParticipant(
invitation: Invitation,
userEntityId: string | null,
): boolean {
if (!userEntityId) return false;
return getInvitationParticipants(invitation).includes(userEntityId);
}