@ateam-ai-mobile/ui 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/TenantPicker.tsx +36 -12
package/dist/index.mjs
CHANGED
|
@@ -1893,12 +1893,13 @@ var styles11 = StyleSheet11.create({
|
|
|
1893
1893
|
// src/TenantPicker.tsx
|
|
1894
1894
|
import { useEffect as useEffect7, useState as useState8 } from "react";
|
|
1895
1895
|
import { View as View13, Text as Text9, Pressable as Pressable7, ActivityIndicator as ActivityIndicator5, StyleSheet as StyleSheet12, Platform as Platform8 } from "react-native";
|
|
1896
|
-
import { ada as ada9, fontSize as fontSize5, borderRadius as borderRadius5, listMyTenants, getTenant as getTenant4 } from "@ateam-ai-mobile/core";
|
|
1896
|
+
import { ada as ada9, fontSize as fontSize5, borderRadius as borderRadius5, listMyTenants, switchTenant, getTenant as getTenant4 } from "@ateam-ai-mobile/core";
|
|
1897
1897
|
import { jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1898
1898
|
var fontFam5 = Platform8.OS === "ios" ? "SF Pro Rounded" : void 0;
|
|
1899
|
-
function TenantPicker({ onSelect, currentTenantId }) {
|
|
1899
|
+
function TenantPicker({ onSwitched, onSelect, currentTenantId }) {
|
|
1900
1900
|
const [tenants, setTenants] = useState8(null);
|
|
1901
1901
|
const [error, setError] = useState8(null);
|
|
1902
|
+
const [switching, setSwitching] = useState8(null);
|
|
1902
1903
|
const active = currentTenantId ?? getTenant4();
|
|
1903
1904
|
useEffect7(() => {
|
|
1904
1905
|
let cancelled = false;
|
|
@@ -1911,6 +1912,23 @@ function TenantPicker({ onSelect, currentTenantId }) {
|
|
|
1911
1912
|
cancelled = true;
|
|
1912
1913
|
};
|
|
1913
1914
|
}, []);
|
|
1915
|
+
const handlePress = async (t) => {
|
|
1916
|
+
if (t.id === active || switching) return;
|
|
1917
|
+
if (onSelect) {
|
|
1918
|
+
onSelect(t);
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
setError(null);
|
|
1922
|
+
setSwitching(t.id);
|
|
1923
|
+
try {
|
|
1924
|
+
const session = await switchTenant(t.id);
|
|
1925
|
+
onSwitched?.(session);
|
|
1926
|
+
} catch (e) {
|
|
1927
|
+
setError(e?.message || "Could not switch team");
|
|
1928
|
+
} finally {
|
|
1929
|
+
setSwitching(null);
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1914
1932
|
if (error) return /* @__PURE__ */ jsx14(Text9, { style: styles12.error, children: error });
|
|
1915
1933
|
if (!tenants) {
|
|
1916
1934
|
return /* @__PURE__ */ jsx14(View13, { style: styles12.loading, children: /* @__PURE__ */ jsx14(ActivityIndicator5, { color: ada9.orange }) });
|
|
@@ -1918,12 +1936,14 @@ function TenantPicker({ onSelect, currentTenantId }) {
|
|
|
1918
1936
|
if (tenants.length === 0) return /* @__PURE__ */ jsx14(Text9, { style: styles12.empty, children: "No teams found for this account." });
|
|
1919
1937
|
return /* @__PURE__ */ jsx14(View13, { style: styles12.list, children: tenants.map((t) => {
|
|
1920
1938
|
const isActive = t.id === active;
|
|
1939
|
+
const isSwitching = switching === t.id;
|
|
1921
1940
|
return /* @__PURE__ */ jsxs11(
|
|
1922
1941
|
Pressable7,
|
|
1923
1942
|
{
|
|
1924
1943
|
accessibilityRole: "button",
|
|
1925
1944
|
accessibilityLabel: `Team ${t.name}${isActive ? ", current" : ""}`,
|
|
1926
|
-
|
|
1945
|
+
disabled: !!switching,
|
|
1946
|
+
onPress: () => handlePress(t),
|
|
1927
1947
|
style: [styles12.row, isActive && styles12.rowActive],
|
|
1928
1948
|
children: [
|
|
1929
1949
|
/* @__PURE__ */ jsx14(View13, { style: styles12.dot }),
|
|
@@ -1931,7 +1951,7 @@ function TenantPicker({ onSelect, currentTenantId }) {
|
|
|
1931
1951
|
/* @__PURE__ */ jsx14(Text9, { style: styles12.name, children: t.name }),
|
|
1932
1952
|
/* @__PURE__ */ jsx14(Text9, { style: styles12.slug, children: t.id })
|
|
1933
1953
|
] }),
|
|
1934
|
-
isActive
|
|
1954
|
+
isSwitching ? /* @__PURE__ */ jsx14(ActivityIndicator5, { color: ada9.orange }) : isActive ? /* @__PURE__ */ jsx14(Text9, { style: styles12.check, children: "\u2713" }) : null
|
|
1935
1955
|
]
|
|
1936
1956
|
},
|
|
1937
1957
|
t.id
|