@@ -1,3 +1,103 @@
1+"use client";
2+
3+import Link from "next/link";
4+import { useRouter } from "next/navigation";
5+import { useCallback, useState } from "react";
6+import { useLocalStorage } from "usehooks-ts";
7+
8+import { pacifico } from "@/components/pacifico-font";
9+import PrimaryButton from "@/components/primary-button";
10+import slugify from "@/lib/slugify";
11+
112 export default function NewStreamPage() {
2- return <div>We need a title for the stream</div>;
13+ // TODO: Allow user to forget their stored details
14+ const [appId, setAppId] = useLocalStorage("app-id", "");
15+ const [token, setToken] = useLocalStorage("token", "");
16+ const [title, setTitle] = useLocalStorage("title", "");
17+ const [error, setError] = useState("");
18+ const router = useRouter();
19+
20+ const handleChange = useCallback(
21+ (e: React.ChangeEvent<HTMLInputElement>) => {
22+ const name: string = e.target.name;
23+
24+ if (name === "app-id") setAppId(e.target.value);
25+ if (name === "token") setToken(e.target.value);
26+ if (name === "title") setTitle(e.target.value);
27+
28+ // Clear the error if it exists after a new change
29+ if (error) setError("");
30+ },
31+ [error, setAppId, setToken, setTitle],
32+ );
33+
34+ const handleNextClick = useCallback(() => {
35+ if (!appId || !token || !title) setError("All fields are required.");
36+ else {
37+ const slug = slugify(title);
38+ router.push("/" + slug);
39+ }
40+ }, [appId, token, title, router]);
41+
42+ return (
43+ <div className="flex flex-col items-center gap-8">
44+ <h3
45+ className={`text-2xl font-bold p-16 text-rose-300 ${pacifico.className}`}
46+ >
47+ Please fill in the details bellow
48+ </h3>
49+ <div className="w-1/2 flex flex-col gap-4">
50+ <label>
51+ Tell us your App ID from AgoraIO (get one{" "}
52+ <Link
53+ className="text-rose-600 active:text-rose-300 visited:text-rose-800"
54+ target="_blank"
55+ href="https://console.agora.io/v2/project-management"
56+ >
57+ here
58+ </Link>
59+ )
60+ </label>
61+ <input
62+ className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
63+ name="app-id"
64+ type="text"
65+ value={appId}
66+ onChange={handleChange}
67+ placeholder="Your app id here..."
68+ />
69+ </div>
70+
71+ <div className="w-1/2 flex flex-col gap-4">
72+ <label>Tell us your AgoraIO token</label>
73+ <input
74+ className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
75+ name="token"
76+ type="text"
77+ value={token}
78+ onChange={handleChange}
79+ placeholder="Your token here..."
80+ />
81+ </div>
82+
83+ <div className="w-1/2 flex flex-col gap-4">
84+ <label>What is your steam title?</label>
85+ <input
86+ className="text-stone-200 bg-stone-800 rounded-xl p-4 w-full placeholder:text-stone-700"
87+ name="title"
88+ type="text"
89+ value={title}
90+ onChange={handleChange}
91+ placeholder="Your token here..."
92+ />
93+ </div>
94+
95+ <div className="w-1/2 flex flex-col gap-4">
96+ <button onClick={handleNextClick}>
97+ <PrimaryButton>Next</PrimaryButton>
98+ </button>
99+ {error && <p className="text-rose-600">{error}</p>}
100+ </div>
101+ </div>
102+ );
3103 }