This repository has been archived by the owner on Feb 11, 2024. It is now read-only.
forked from thgrund/muxy-frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from toplap/feat/title-description
Add Stream `description` field
- Loading branch information
Showing
6 changed files
with
333 additions
and
209 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,118 @@ | ||
import React, { ReactElement, useState } from 'react'; | ||
import React, { ReactElement, useState } from "react"; | ||
|
||
interface Props { | ||
eventUrl: string, | ||
startsAt: string, | ||
endsAt: string | ||
eventUrl: string; | ||
startsAt: string; | ||
endsAt: string; | ||
} | ||
|
||
function PerformanceCreateForm({eventUrl, startsAt, endsAt}: Props): ReactElement { | ||
const [name, setName] = useState<string>(""); | ||
const [email, setEmail] = useState<string>(""); | ||
const [description, setDescription] = useState<string>(""); | ||
const [streamkey, setStreamKey] = useState<string>(""); | ||
const [location, setLocation] = useState<string>(""); | ||
const muxyApiKey: string = (process.env.REACT_APP_MUXY_API_KEY as string); | ||
const muxyUrl: string = (process.env.REACT_APP_MUXY_URL as string); | ||
function PerformanceCreateForm({ | ||
eventUrl, | ||
startsAt, | ||
endsAt, | ||
}: Props): ReactElement { | ||
const [name, setName] = useState<string>(""); | ||
const [email, setEmail] = useState<string>(""); | ||
const [title, setTitle] = useState<string>(""); | ||
const [description, setDescription] = useState<string>(""); | ||
const [streamkey, setStreamKey] = useState<string>(""); | ||
const [location, setLocation] = useState<string>(""); | ||
const muxyApiKey: string = process.env.REACT_APP_MUXY_API_KEY as string; | ||
const muxyUrl: string = process.env.REACT_APP_MUXY_URL as string; | ||
|
||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
fetch(`${muxyUrl}/streams/`, { | ||
method: "post", | ||
headers: new Headers({ | ||
Authorization: `Api-Key ${muxyApiKey}`, | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}), | ||
body: JSON.stringify({ | ||
publisher_name: name, | ||
publisher_email: email, | ||
description: description, | ||
location: location, | ||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
event: eventUrl, // This needs to come from the muxy event (isn't available right now) | ||
starts_at: startsAt, // This needs to be calculated before | ||
ends_at: endsAt, // This needs to be calculated before | ||
}), | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
setStreamKey(data.key); | ||
}) | ||
.catch(console.error); | ||
} | ||
const handleSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
fetch(`${muxyUrl}/streams/`, { | ||
method: "post", | ||
headers: new Headers({ | ||
Authorization: `Api-Key ${muxyApiKey}`, | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}), | ||
body: JSON.stringify({ | ||
publisher_name: name, | ||
publisher_email: email, | ||
title: title, | ||
description: description, | ||
location: location, | ||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
event: eventUrl, // This needs to come from the muxy event (isn't available right now) | ||
starts_at: startsAt, // This needs to be calculated before | ||
ends_at: endsAt, // This needs to be calculated before | ||
}), | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
setStreamKey(data.key); | ||
}) | ||
.catch(console.error); | ||
}; | ||
|
||
return ( | ||
<> | ||
{streamkey && ( | ||
<div> | ||
<p>You have successfully registered for the event. Your streamkey is <b>{streamkey}</b> </p> | ||
<p>You should have received this as an email too. </p> | ||
<p>Save this key well, you will need it for the event and also to delete your slot again. </p> | ||
<p>When this page is reloaded, the key will no longer be displayed. </p> | ||
</div> | ||
)} | ||
{!streamkey && ( | ||
<form className="PerformanceCreateForm" onSubmit={handleSubmit}> | ||
<input id="name" type="text" placeholder="Name" value={name} | ||
onChange={e => setName(e.target.value)} required /> | ||
<input id="email" type="text" placeholder="E-Mail" value={email} | ||
onChange={e => setEmail(e.target.value)} required /> | ||
<input id="description" type="text" placeholder="Description" value={description} | ||
onChange={e => setDescription(e.target.value)} required /> | ||
<input id="location" type="text" placeholder="Location" value={location} | ||
onChange={e => setLocation(e.target.value)} required /> | ||
<input type="submit" className="card-button" value="Rave On"/> | ||
</form> | ||
)} | ||
</> | ||
); | ||
return ( | ||
<> | ||
{streamkey && ( | ||
<div> | ||
<p> | ||
You have successfully registered for the event. Your streamkey is{" "} | ||
<b>{streamkey}</b>{" "} | ||
</p> | ||
<p>You should have received this as an email too. </p> | ||
<p> | ||
Save this key well, you will need it for the event and also to | ||
delete your slot again.{" "} | ||
</p> | ||
<p> | ||
When this page is reloaded, the key will no longer be displayed.{" "} | ||
</p> | ||
</div> | ||
)} | ||
{!streamkey && ( | ||
<form className="PerformanceCreateForm" onSubmit={handleSubmit}> | ||
<input | ||
id="name" | ||
type="text" | ||
placeholder="Name" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
required | ||
/> | ||
<input | ||
id="email" | ||
type="text" | ||
placeholder="E-Mail" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
<input | ||
id="title" | ||
type="text" | ||
placeholder="Title" | ||
value={title} | ||
onChange={(e) => setTitle(e.target.value)} | ||
required | ||
/> | ||
<textarea | ||
id="description" | ||
placeholder="Description (used for archive videos)" | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
rows={3} | ||
maxLength={1000} | ||
/> | ||
<input | ||
id="location" | ||
type="text" | ||
placeholder="Location" | ||
value={location} | ||
onChange={(e) => setLocation(e.target.value)} | ||
required | ||
/> | ||
<input type="submit" className="card-button" value="Rave On" /> | ||
</form> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default PerformanceCreateForm; |
Oops, something went wrong.