Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
animate login form
ameer2468a94c72aa16e9
diff --git a/apps/web/app/login/form.tsx b/apps/web/app/login/form.tsxindex 7e3ab7f73..e01e08bf6 100644--- a/apps/web/app/login/form.tsx+++ b/apps/web/app/login/form.tsx@@ -2,14 +2,15 @@import { getSpace } from "@/actions/workspace/get-space";import { NODE_ENV } from "@cap/env";-import { Button, Input, Label } from "@cap/ui";+import { Button, Input, Label, LogoBadge } from "@cap/ui";import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { AnimatePresence, motion } from "framer-motion";import { LucideArrowUpRight, LucideMail } from "lucide-react";import { signIn } from "next-auth/react";import Link from "next/link";import { useSearchParams } from "next/navigation";-import { useEffect, useState } from "react";+import { Suspense, useEffect, useState } from "react";import { toast } from "react-hot-toast";import { trackEvent } from "../utils/analytics";@@ -102,74 +103,243 @@ export function LoginForm() {};return (- <>- <div className="flex flex-col space-y-3">- <form- onSubmit={async (e) => {- e.preventDefault();- if (!email) return;+ <div className="flex justify-center items-center w-full h-screen">+ <div className="overflow-hidden relative w-[calc(100%-2%)] p-[28px] max-w-[472px] space-y-[28px] bg-gray-100 border border-gray-200 rounded-2xl">+ <motion.div+ key="back-button"+ initial={{ opacity: 0, display: "none" }}+ animate={{+ opacity: showOrgInput ? 1 : 0,+ display: showOrgInput ? "flex" : "none",+ transition: { duration: 0.2 },+ }}+ onClick={() => setShowOrgInput(false)}+ className="flex absolute top-5 left-5 z-20 hover:bg-gray-100 gap-2 items-center py-1.5 px-3 text-gray-500 bg-gray-50 rounded-full border border-gray-200 transition-colors duration-300 cursor-pointer "+ >+ <FontAwesomeIcon className="w-2" icon={faArrowLeft} />+ <p className="text-xs text-inherit">Back</p>+ </motion.div>+ <Link href="/">+ <LogoBadge className="w-[72px] mx-auto" />+ </Link>+ <div className="flex flex-col justify-center items-center text-left">+ <h1 className="text-2xl font-semibold">Sign in to Cap</h1>+ <p className="text-[16px] text-gray-400">+ Beautiful screen recordings, owned by you.+ </p>+ </div>+ <div className="flex flex-col space-y-3">+ <Suspense+ fallback={+ <>+ <Button disabled={true} variant="primary" />+ <Button disabled={true} variant="secondary" />+ <Button disabled={true} variant="destructive" />+ <div className="mx-auto w-3/4 h-5 bg-gray-100 rounded-lg" />+ </>+ }+ >+ <div className="flex flex-col space-y-3">+ <AnimatePresence mode="wait" initial={false}>+ {showOrgInput ? (+ <motion.div+ key="sso"+ initial={{ x: 450, opacity: 0, filter: "blur(10px)" }}+ animate={{ x: 0, opacity: 1, filter: "blur(0px)" }}+ exit={{ x: 450, opacity: 0, filter: "blur(10px)" }}+ transition={{ duration: 0.2, type: "spring", bounce: 0.2 }}+ >+ <LoginWithSSO+ showOrgInput={showOrgInput}+ setShowOrgInput={setShowOrgInput}+ handleSpaceLookup={handleSpaceLookup}+ spaceId={spaceId}+ setSpaceId={setSpaceId}+ spaceName={spaceName}+ />+ </motion.div>+ ) : (+ <motion.form+ key="email"+ initial={{ x: -450, opacity: 0, filter: "blur(10px)" }}+ animate={{ x: 0, opacity: 1, filter: "blur(0px)" }}+ exit={{ x: -450, opacity: 0, filter: "blur(10px)" }}+ transition={{ duration: 0.2, type: "spring", bounce: 0.2 }}+ onSubmit={async (e) => {+ e.preventDefault();+ if (!email) return;- setLoading(true);- trackEvent("auth_started", {- method: "email",- is_signup: !oauthError,- });- signIn("email", {- email,- redirect: false,- ...(next && next.length > 0 ? { callbackUrl: next } : {}),- })- .then((res) => {- setLoading(false);- if (res?.ok && !res?.error) {+ setLoading(true);+ trackEvent("auth_started", {+ method: "email",+ is_signup: !oauthError,+ });+ signIn("email", {+ email,+ redirect: false,+ ...(next && next.length > 0+ ? { callbackUrl: next }+ : {}),+ })+ .then((res) => {+ setLoading(false);+ if (res?.ok && !res?.error) {+ setEmail("");+ setEmailSent(true);+ trackEvent("auth_email_sent", {+ email_domain: email.split("@")[1],+ });+ toast.success("Email sent - check your inbox!");+ } else {+ toast.error("Error sending email - try again?");+ }+ })+ .catch((err) => {+ setEmailSent(false);+ setLoading(false);+ toast.error("Error sending email - try again?");+ });+ }}+ className="flex flex-col space-y-3"+ >+ <NormalLogin+ setShowOrgInput={setShowOrgInput}+ email={email}+ emailSent={emailSent}+ setEmail={setEmail}+ loading={loading}+ oauthError={oauthError}+ handleGoogleSignIn={handleGoogleSignIn}+ />+ </motion.form>+ )}+ </AnimatePresence>+ <p className="text-xs text-center text-gray-400">+ By typing your email and clicking continue, you acknowledge that+ you have both read and agree to Cap's{" "}+ <Link+ href="/terms"+ target="_blank"+ className="text-xs font-semibold text-gray-500 hover:text-blue-300"+ >+ Terms of Service+ </Link>{" "}+ and{" "}+ <Link+ href="/privacy"+ target="_blank"+ className="text-xs font-semibold text-gray-500 hover:text-blue-300"+ >+ Privacy Policy+ </Link>+ .+ </p>+ </div>+ {emailSent && (+ <button+ className="pt-3 mx-auto text-sm text-gray-500 underline hover:text-gray-400"+ onClick={() => {+ setEmailSent(false);setEmail("");- setEmailSent(true);- trackEvent("auth_email_sent", {- email_domain: email.split("@")[1],- });- toast.success("Email sent - check your inbox!");- } else {- toast.error("Error sending email - try again?");- }- })- .catch((err) => {- setEmailSent(false);- setLoading(false);- toast.error("Error sending email - try again?");- });+ setLoading(false);+ }}+ >+ Click to restart sign in process+ </button>+ )}+ </Suspense>+ </div>+ </div>+ </div>+ );+}++const LoginWithSSO = ({+ setShowOrgInput,+ handleSpaceLookup,+ spaceId,+ setSpaceId,+ spaceName,+}: {+ showOrgInput: boolean;+ setShowOrgInput: (show: boolean) => void;+ handleSpaceLookup: (e: React.FormEvent) => void;+ spaceId: string;+ setSpaceId: (spaceId: string) => void;+ spaceName: string | null;+}) => {+ return (+ <>+ <form onSubmit={handleSpaceLookup} className="relative space-y-2">+ <div>+ <Label htmlFor="spaceId">Space ID</Label>+ <Input+ id="spaceId"+ value={spaceId}+ onChange={(e) => setSpaceId(e.target.value)}+ className="w-full max-w-full"+ />+ </div>+ {spaceName && (+ <p className="text-sm text-gray-500">Signing in to: {spaceName}</p>+ )}+ <div>+ <Button type="submit" variant="dark" className="w-full max-w-full">+ Continue with SSO+ </Button>+ </div>+ </form>+ </>+ );+};++const NormalLogin = ({+ setShowOrgInput,+ email,+ emailSent,+ setEmail,+ loading,+ oauthError,+ handleGoogleSignIn,+}: {+ setShowOrgInput: (show: boolean) => void;+ email: string;+ emailSent: boolean;+ setEmail: (email: string) => void;+ loading: boolean;+ oauthError: boolean;+ handleGoogleSignIn: () => void;+}) => {+ return (+ <>+ <div className="flex flex-col space-y-3">+ <Input+ id="email"+ name="email"+ autoFocus+ type="email"+ placeholder={emailSent ? "" : "[email protected]"}+ autoComplete="email"+ required+ value={email}+ disabled={emailSent}+ onChange={(e) => {+ setEmail(e.target.value);}}- className="flex flex-col space-y-3"+ />+ <Button+ variant="primary"+ type="submit"+ disabled={loading || emailSent}+ icon={<LucideMail size={16} />}>- {showOrgInput === false && (- <>- <div className="flex flex-col space-y-3">- <Input- id="email"- name="email"- autoFocus- type="email"- placeholder={emailSent ? "" : "[email protected]"}- autoComplete="email"- required- value={email}- disabled={emailSent}- onChange={(e) => {- setEmail(e.target.value);- }}- />- <Button- variant="primary"- type="submit"- disabled={loading || emailSent}- icon={<LucideMail size={16} />}- >- {emailSent- ? NODE_ENV === "development"- ? "Email sent to your terminal"- : "Email sent to your inbox"- : "Login with email"}- </Button>- {/* {NODE_ENV === "development" && (+ {emailSent+ ? NODE_ENV === "development"+ ? "Email sent to your terminal"+ : "Email sent to your inbox"+ : "Login with email"}+ </Button>+ {/* {NODE_ENV === "development" && (<div className="flex justify-center items-center px-6 py-3 mt-3 bg-red-600 rounded-xl"><p className="text-lg text-white"><span className="font-bold text-white">@@ -179,136 +349,59 @@ export function LoginForm() {</p></div>)} */}- </div>- </>- )}- {showOrgInput === false && (- <div className="flex gap-4 items-center">- <span className="flex-1 h-px bg-gray-200" />- <p className="text-sm text-center text-gray-400">OR</p>- <span className="flex-1 h-px bg-gray-200" />- </div>- )}- {showOrgInput === false && (- <div className="flex flex-col gap-3 justify-center items-center">- {!oauthError && (- <>- {showOrgInput === false && (- <Button- variant="red"- className="flex justify-center items-center space-x-2 w-full text-sm"- onClick={handleGoogleSignIn}- disabled={loading}- >- <svg- width="15"- height="16"- viewBox="0 0 15 16"- fill="none"- className="mr-1"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="M15 8.1754C15 12.4546 12.0215 15.5 7.62295 15.5C3.40574 15.5 0 12.1492 0 8C0 3.85081 3.40574 0.5 7.62295 0.5C9.67623 0.5 11.4037 1.24093 12.7346 2.4627L10.6598 4.4254C7.9457 1.84879 2.89857 3.78427 2.89857 8C2.89857 10.6159 5.02254 12.7359 7.62295 12.7359C10.6414 12.7359 11.7725 10.6069 11.9508 9.50302H7.62295V6.92339H14.8801C14.9508 7.30746 15 7.67641 15 8.1754Z"- fill="white"- />- </svg>- Login with Google- </Button>- )}- </>- )}-- {oauthError && (- <div className="p-4 mb-4 bg-red-600 rounded-lg">- <p className="text-sm text-gray-50">- It looks like you've previously used this email to sign up- via email login. Please enter your email below to receive a- sign in link.- </p>- </div>- )}- <Button- variant="white"- className="w-full"- onClick={() => setShowOrgInput(true)}- disabled={loading}- >- <LucideArrowUpRight size={20} />- Login with SAML SSO- </Button>- </div>- )}- </form>- {showOrgInput && (+ </div>+ <div className="flex gap-4 items-center my-4">+ <span className="flex-1 h-px bg-gray-200" />+ <p className="text-sm text-center text-gray-400">OR</p>+ <span className="flex-1 h-px bg-gray-200" />+ </div>+ <div className="flex flex-col gap-3 justify-center items-center">+ {!oauthError && (<>- <div- onClick={() => setShowOrgInput(false)}- className="flex absolute top-2 left-6 gap-2 items-center text-gray-500 transition-colors duration-300 cursor-pointer hover:text-gray-400"+ <Button+ variant="red"+ className="flex justify-center items-center space-x-2 w-full text-sm"+ onClick={handleGoogleSignIn}+ disabled={loading}>- <FontAwesomeIcon className="w-3" icon={faArrowLeft} />- <p className="text-sm text-inherit">Back</p>- </div>- <form onSubmit={handleSpaceLookup} className="space-y-2">- <div>- <Label htmlFor="spaceId">Space ID</Label>- <Input- id="spaceId"- value={spaceId}- onChange={(e) => setSpaceId(e.target.value)}- className="w-full max-w-full"+ <svg+ width="15"+ height="16"+ viewBox="0 0 15 16"+ fill="none"+ className="mr-1"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M15 8.1754C15 12.4546 12.0215 15.5 7.62295 15.5C3.40574 15.5 0 12.1492 0 8C0 3.85081 3.40574 0.5 7.62295 0.5C9.67623 0.5 11.4037 1.24093 12.7346 2.4627L10.6598 4.4254C7.9457 1.84879 2.89857 3.78427 2.89857 8C2.89857 10.6159 5.02254 12.7359 7.62295 12.7359C10.6414 12.7359 11.7725 10.6069 11.9508 9.50302H7.62295V6.92339H14.8801C14.9508 7.30746 15 7.67641 15 8.1754Z"+ fill="white"/>- </div>- {spaceName && (- <p className="text-sm text-gray-500">- Signing in to: {spaceName}- </p>- )}- <div>- <Button- type="submit"- variant="dark"- className="w-full max-w-full"- >- Continue with SSO- </Button>- </div>- </form>+ </svg>+ Login with Google+ </Button></>)}- <p className="text-xs text-center text-gray-400">- By typing your email and clicking continue, you acknowledge that you- have both read and agree to Cap's{" "}- <Link- href="/terms"- target="_blank"- className="text-xs font-semibold text-gray-500 hover:text-blue-300"- >- Terms of Service- </Link>{" "}- and{" "}- <Link- href="/privacy"- target="_blank"- className="text-xs font-semibold text-gray-500 hover:text-blue-300"- >- Privacy Policy- </Link>- .- </p>- </div>- {emailSent && (- <button- className="pt-3 mx-auto text-sm text-gray-500 underline hover:text-gray-400"- onClick={() => {- setEmailSent(false);- setEmail("");- setLoading(false);- }}++ {oauthError && (+ <div className="p-4 mb-4 bg-red-600 rounded-lg">+ <p className="text-sm text-gray-50">+ It looks like you've previously used this email to sign up via+ email login. Please enter your email below to receive a sign in+ link.+ </p>+ </div>+ )}+ <Button+ variant="white"+ type="button"+ className="w-full"+ onClick={() => setShowOrgInput(true)}+ disabled={loading}>- Click to restart sign in process- </button>- )}+ <LucideArrowUpRight size={20} />+ Login with SAML SSO+ </Button>+ </div></>);-}+};diff --git a/apps/web/app/login/page.tsx b/apps/web/app/login/page.tsxindex 0b609a9cf..b77e9f99d 100644--- a/apps/web/app/login/page.tsx+++ b/apps/web/app/login/page.tsx@@ -1,44 +1,11 @@import { getCurrentUser } from "@cap/database/auth/session";-import { Button, LogoBadge } from "@cap/ui";-import Link from "next/link";import { redirect } from "next/navigation";-import { Suspense } from "react";import { LoginForm } from "./form";export default async function LoginPage() {const session = await getCurrentUser();-if (session) {redirect("/dashboard");}-- return (- <div className="flex justify-center items-center w-full h-screen">- <div className="overflow-hidden relative w-[calc(100%-2%)] p-[28px] max-w-[472px] space-y-[28px] bg-gray-100 border border-gray-200 rounded-2xl">- <Link href="/">- <LogoBadge className="w-[72px] mx-auto" />- </Link>- <div className="flex flex-col justify-center items-center text-left">- <h1 className="text-2xl font-semibold">Sign in to Cap</h1>- <p className="text-[16px] text-gray-400">- Beautiful screen recordings, owned by you.- </p>- </div>- <div className="flex flex-col space-y-3">- <Suspense- fallback={- <>- <Button disabled={true} variant="primary" />- <Button disabled={true} variant="secondary" />- <Button disabled={true} variant="destructive" />- <div className="mx-auto w-3/4 h-5 bg-gray-100 rounded-lg" />- </>- }- >- <LoginForm />- </Suspense>- </div>- </div>- </div>- );+ return <LoginForm />;}