UNPKG

@basictech/cli

Version:

Basic CLI for creating & managing your projects

164 lines 5.77 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import React from 'react'; import { render, Box, Text } from 'ink'; import { Table } from '../components/Table.js'; import { Spinner } from '../components/Spinner.js'; import { TeamForm } from '../components/TeamForm.js'; import { ApiClient } from '../lib/api.js'; import { AuthService } from '../lib/auth.js'; import { isOnline, openBrowser, copyToClipboard } from '../lib/platform.js'; import { MESSAGES } from '../lib/constants.js'; function TeamsApp() { const [state, setState] = React.useState({ loading: true, teams: [], error: null }); React.useEffect(() => { async function loadTeams() { try { // Check if online if (!(await isOnline())) { setState(prev => ({ ...prev, loading: false, error: MESSAGES.OFFLINE })); return; } // Check if logged in const authService = AuthService.getInstance(); const token = await authService.getToken(); if (!token) { setState(prev => ({ ...prev, loading: false, error: MESSAGES.LOGGED_OUT })); return; } // Fetch teams const apiClient = ApiClient.getInstance(); const teams = await apiClient.getTeams(); setState({ loading: false, teams, error: null }); } catch (error) { setState({ loading: false, teams: [], error: error instanceof Error ? error.message : 'Failed to load teams' }); } } loadTeams(); }, []); const handleCopy = async (row) => { try { await copyToClipboard(row.id); } catch (error) { // Silent fail - notification already shown by Table component } }; const handleOpen = async (row) => { try { await openBrowser(`https://app.basic.tech/team/${row.slug}`); } catch (error) { // Silent fail - browser opening is best effort } }; const handleExit = () => { process.exit(0); }; const handleNew = () => { // Re-render with the new team form render(_jsx(NewTeamApp, {})); }; if (state.loading) { return _jsx(Spinner, { text: "Loading teams..." }); } if (state.error) { return _jsx(Text, { color: "red", children: state.error }); } const columns = [ { title: 'ID', width: 38, key: 'id' }, { title: 'Name', width: 25, key: 'name' }, { title: 'Role', width: 20, key: 'role_name' } ]; const rows = state.teams.map(team => ({ id: team.id, name: team.name, role_name: team.role_name || 'Member', slug: team.slug })); return (_jsx(Table, { columns: columns, rows: rows, onCopy: handleCopy, onOpen: handleOpen, onExit: handleExit, onNew: handleNew, helpText: { copyAction: "'c' to copy team ID", openAction: "'o' to open in browser", newAction: "'n' to create a new team" } })); } function NewTeamApp() { const [state, setState] = React.useState({ loading: false, error: null, success: false, teamName: '', teamSlug: '' }); const handleSubmit = async (data) => { setState(prev => ({ ...prev, loading: true, error: null })); try { // Check if online if (!(await isOnline())) { setState(prev => ({ ...prev, loading: false, error: MESSAGES.OFFLINE })); return; } // Check if logged in const authService = AuthService.getInstance(); const token = await authService.getToken(); if (!token) { setState(prev => ({ ...prev, loading: false, error: MESSAGES.LOGGED_OUT })); return; } // Create team const apiClient = ApiClient.getInstance(); await apiClient.createTeam(data.teamName, data.teamSlug); setState({ loading: false, error: null, success: true, teamName: data.teamName, teamSlug: data.teamSlug }); // Exit after 2 seconds setTimeout(() => { process.exit(0); }, 2000); } catch (error) { setState(prev => ({ ...prev, loading: false, error: error instanceof Error ? error.message : 'Failed to create team' })); } }; if (state.loading) { return _jsx(Spinner, { text: "Creating team..." }); } if (state.success) { return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "green", children: ["\u2705 Team \"", state.teamName, "\" created successfully!"] }), _jsxs(Text, { children: ["Team slug: ", state.teamSlug] })] })); } if (state.error) { return _jsx(Text, { color: "red", children: state.error }); } return (_jsx(TeamForm, { title: "Create New Team", onSubmit: handleSubmit, onCancel: () => process.exit(0) })); } export async function TeamsCommand(action) { if (action === 'new') { // Render team creation form render(_jsx(NewTeamApp, {})); } else { // Default: render teams list render(_jsx(TeamsApp, {})); } } //# sourceMappingURL=teams.js.map