MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / OnboardingForm

Function OnboardingForm

apps/web/ui/OnboardingForm/index.tsx:21–245  ·  view source on GitHub ↗
({ api }: Props)

Source from the content-addressed store, hash-verified

19}
20
21export default function OnboardingForm({ api }: Props) {
22 const [loading, setLoading] = useState(false);
23 const [channels, setChannels] = useState<string[]>([]);
24 const [emails, setEmails] = useState<string[]>([]);
25 const [suggestion, setSuggestion] = useState<string>('');
26
27 async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
28 e.preventDefault();
29 setLoading(true);
30 try {
31 const target = e.target as typeof e.target & {
32 name: { value: string };
33 slackDomain: { value: string };
34 description: { value: string };
35 };
36 const name = target.name.value;
37 const slackDomain = target.slackDomain.value.toLowerCase();
38 const description = target.description.value;
39
40 const response = await api.createAccount({
41 name,
42 slackDomain,
43 channels,
44 description,
45 members: emails,
46 });
47 if (response.id) {
48 // FIXME: it only works on nextjs
49 window.location.href = `/s/${slackDomain}/configurations`;
50 }
51 } catch (error: any) {
52 Toast.error(error.message || 'Something went wrong');
53 } finally {
54 setLoading(false);
55 }
56 }
57
58 async function addChannel() {
59 const input = document.getElementById(
60 'new-channel-onboarding'
61 ) as HTMLInputElement;
62 if (input.value && input.checkValidity()) {
63 const channel = input.value.toLowerCase();
64 if (channels.includes(channel)) {
65 Toast.error('Channel already added.');
66 } else {
67 setChannels((channels) => [...channels, channel]);
68 input.value = '';
69 }
70 } else {
71 return input.reportValidity();
72 }
73 }
74
75 async function addEmail() {
76 const input = document.getElementById(
77 'new-email-onboarding'
78 ) as HTMLInputElement;

Callers

nothing calls this directly

Calls 6

slugifyFunction · 0.90
removeChannelFunction · 0.85
addChannelFunction · 0.85
removeEmailFunction · 0.85
addEmailFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected