MCPcopy Create free account
hub / github.com/chiragksharma/BuildFast / useJoinWaitlist

Function useJoinWaitlist

src/hooks/useJoinWaitlist.ts:10–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8}
9
10const useJoinWaitlist = (): UseJoinWaitlistResult => {
11 const [loading, setLoading] = useState(false);
12 const [error, setError] = useState<string | null>(null);
13 const [success, setSuccess] = useState(false);
14
15 const joinWaitlist = async (email: string) => {
16 setLoading(true);
17 setError(null);
18 setSuccess(false);
19
20 try {
21 const response = await fetch('/api/join-waitlist', {
22 method: 'POST',
23 headers: {
24 'Content-Type': 'application/json',
25 },
26 body: JSON.stringify({ email }),
27 });
28
29 if (!response.ok) {
30 const errorData = await response.json();
31 throw new Error(errorData.error || 'Failed to join waitlist');
32 }
33
34 setSuccess(true);
35 } catch (error) {
36 if (error instanceof Error) {
37 setError(error.message);
38 } else {
39 setError('An unknown error occurred');
40 }
41 }finally {
42 setLoading(false);
43 }
44 };
45
46 return { joinWaitlist, loading, error, success };
47};
48
49export default useJoinWaitlist;

Callers 1

ButtonLeadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected