Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
133 lines
3.8 KiB
TypeScript
133 lines
3.8 KiB
TypeScript
/**
|
|
* Invite-by-email form. Collects an email and a role, then hands the request to
|
|
* the parent: an existing account is added straight to the members list; an
|
|
* email without an account becomes a pending invite with a shareable join link.
|
|
* Owns its own submitting/error state and only renders for callers allowed to
|
|
* manage members.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import {
|
|
ActivityIndicator,
|
|
Pressable,
|
|
StyleSheet,
|
|
Text,
|
|
TextInput,
|
|
View,
|
|
} from "react-native";
|
|
|
|
import type { InviteMemberRequest, WorkspaceRole } from "@/lib/types";
|
|
|
|
import { describeError } from "@/components/me/errors";
|
|
import { colors } from "@/components/me/theme";
|
|
|
|
import { RolePicker } from "./RolePicker";
|
|
|
|
interface InviteMemberFormProps {
|
|
/** Performs the invite; resolves once the new member is in the list. */
|
|
onInvite: (body: InviteMemberRequest) => Promise<void>;
|
|
}
|
|
|
|
/** Minimal email shape check — the backend is the source of truth. */
|
|
function isLikelyEmail(value: string): boolean {
|
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
}
|
|
|
|
export function InviteMemberForm({ onInvite }: InviteMemberFormProps) {
|
|
const [email, setEmail] = useState("");
|
|
const [role, setRole] = useState<WorkspaceRole>("member");
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const canSubmit = !!email.trim() && !submitting;
|
|
|
|
const onSubmit = async () => {
|
|
const trimmed = email.trim();
|
|
if (!isLikelyEmail(trimmed)) {
|
|
setError("Enter a valid email address.");
|
|
return;
|
|
}
|
|
setSubmitting(true);
|
|
setError(null);
|
|
try {
|
|
await onInvite({ email: trimmed, role });
|
|
setEmail("");
|
|
setRole("member");
|
|
} catch (err) {
|
|
setError(describeError(err, "Failed to invite member."));
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<View style={styles.card}>
|
|
<Text style={styles.label}>Invite by email</Text>
|
|
<TextInput
|
|
style={styles.input}
|
|
value={email}
|
|
onChangeText={(text) => {
|
|
setEmail(text);
|
|
if (error) setError(null);
|
|
}}
|
|
placeholder="teammate@example.com"
|
|
placeholderTextColor={colors.muted}
|
|
autoCapitalize="none"
|
|
autoCorrect={false}
|
|
keyboardType="email-address"
|
|
spellCheck={false}
|
|
editable={!submitting}
|
|
/>
|
|
<Text style={styles.subLabel}>Role</Text>
|
|
<RolePicker selected={role} onSelect={setRole} disabled={submitting} />
|
|
{error ? <Text style={styles.error}>{error}</Text> : null}
|
|
<Pressable
|
|
style={[styles.button, !canSubmit && styles.buttonDisabled]}
|
|
onPress={onSubmit}
|
|
disabled={!canSubmit}
|
|
accessibilityRole="button"
|
|
accessibilityLabel="Send invite"
|
|
accessibilityState={{ disabled: !canSubmit }}
|
|
>
|
|
{submitting ? (
|
|
<ActivityIndicator color={colors.textPrimary} />
|
|
) : (
|
|
<Text style={styles.buttonText}>Send invite</Text>
|
|
)}
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
card: {
|
|
backgroundColor: colors.card,
|
|
borderColor: colors.border,
|
|
borderWidth: 1,
|
|
borderRadius: 12,
|
|
padding: 14,
|
|
gap: 10,
|
|
},
|
|
label: { color: colors.textSecondary, fontSize: 13, fontWeight: "600" },
|
|
subLabel: { color: colors.muted, fontSize: 12, fontWeight: "600" },
|
|
input: {
|
|
backgroundColor: colors.bg,
|
|
borderColor: colors.border,
|
|
borderWidth: 1,
|
|
borderRadius: 10,
|
|
color: colors.textPrimary,
|
|
fontSize: 15,
|
|
paddingHorizontal: 12,
|
|
paddingVertical: 10,
|
|
},
|
|
error: { color: colors.error, fontSize: 13 },
|
|
button: {
|
|
backgroundColor: colors.primary,
|
|
borderRadius: 10,
|
|
paddingVertical: 13,
|
|
alignItems: "center",
|
|
},
|
|
buttonDisabled: { opacity: 0.5 },
|
|
buttonText: { color: colors.textPrimary, fontWeight: "700", fontSize: 15 },
|
|
});
|