Skip to content

🎥 Make videos programmatically with React

fully functional

Patric Salvisberg0384d2b07cb4
diff --git a/packages/docs/src/pages/4/index.tsx b/packages/docs/src/pages/4/index.tsx
index d77e637698..f2b104dd79 100644
--- a/packages/docs/src/pages/4/index.tsx
+++ b/packages/docs/src/pages/4/index.tsx
@@ -1,14 +1,112 @@
+/* eslint-disable no-alert */
+import { useMemo } from "react";
+import { useCallback, useState } from "react";
import React from "react";
import Layout from "@theme/Layout";
import Head from "@docusaurus/Head";
import { Seo } from "../../components/Seo";
+import styles from "./v4.module.css";
+import { BlueButton } from "../../../components/layout/Button";
+import { CoolInput } from "../../../components/TextInput";
+import { Spacer } from "../../../components/layout/Spacer";
+
+const V4: React.FC = () => {
+ const [email, setEmail] = useState<string>(null);
+ const [loading, setLoading] = useState<boolean>(false);
+ const [subscribed, setSubscribed] = useState<boolean>(false);
+ const [error, setError] = useState<string | null>(null);
+
+ const buttonLabel = useMemo(() => {
+ if (subscribed) {
+ return "Subscribed!";
+ }
+
+ return loading ? "submitting..." : "submit";
+ }, [loading, subscribed]);
+ const isValidEmail = (inputMail: string) =>
+ /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(inputMail);
+
+ const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
+ (e) => {
+ setEmail(e.target.value);
+ },
+ []
+ );
+
+ const onSubmit: React.FormEventHandler = useCallback(
+ async (e) => {
+ try {
+ e.preventDefault();
+ setSubscribed(false);
+ setError(null);
+
+ if (isValidEmail(email)) {
+ setLoading(true);
+ const res = await fetch(
+ "https://companies.remotion.dev/api/launch-4",
+ {
+ method: "POST",
+ body: JSON.stringify({ email }),
+ headers: { "content-type": "application/json" },
+ }
+ );
+ const json = await res.json();
+ if (json.success) {
+ setSubscribed(true);
+ } else {
+ setLoading(false);
+ alert("Something went wrong. Please try again later.");
+ }
+ } else {
+ setError("Invalid Email");
+ }
+ } catch (err) {
+ setLoading(false);
+ alert("Something went wrong. Please try again later");
+ console.error(err);
+ }
+ },
+ [email]
+ );
-const v4: React.FC = () => {
return (
<Layout>
<Head>{Seo.renderTitle("Remotion V4")}</Head>
+ <div className={styles.container}>
+ <div className={styles.wrapper}>
+ <p className={styles.title}>V4 Launch</p>
+
+ <div className={styles.panel}>
+ <p>
+ Get a newsletter with all the imporant information when Remotion
+ V4 launches!
+ </p>
+ <CoolInput
+ type="email"
+ autoComplete="none"
+ onChange={onChange}
+ placeholder="Your email adress"
+ style={{ width: "100%" }}
+ />
+ <Spacer />
+ <Spacer />
+
+ <BlueButton
+ type="submit"
+ fullWidth
+ onClick={onSubmit}
+ loading={loading}
+ disabled={loading || subscribed}
+ size="bg"
+ >
+ {buttonLabel}
+ </BlueButton>
+ {error}
+ </div>
+ </div>
+ </div>
</Layout>
);
};
-export default v4;
+export default V4;
diff --git a/packages/docs/src/pages/4/v4.module.css b/packages/docs/src/pages/4/v4.module.css
new file mode 100644
index 0000000000..7957037cc1
--- /dev/null
+++ b/packages/docs/src/pages/4/v4.module.css
@@ -0,0 +1,30 @@
+.container {
+ position: "relative";
+}
+
+.wrapper {
+ max-width: 1000px;
+ margin: auto;
+ padding-top: 60px;
+ padding-left: 20px;
+ padding-right: 20px;
+ display: flex;
+ flex-direction: column;
+}
+
+.panel {
+ background-color: var(--ifm-background-color);
+ box-shadow: var(--box-shadow);
+ padding: 10px;
+ border-radius: 15px;
+ flex: 1;
+ padding-bottom: 10px;
+ display: flex;
+ flex-direction: column;
+}
+
+.title {
+ font-size: 1.2rem;
+ margin-bottom: 0;
+ font-weight: bold;
+}