|
| 1 | +import { href, Outlet, useLocation } from "react-router" |
| 2 | +import { Button } from "~/components/ui/button" |
| 3 | +import { Link } from "~/library/link" |
| 4 | +import { cn } from "~/utils/css" |
| 5 | + |
| 6 | +const useGetCurrentPage = () => { |
| 7 | + // Used to retrieve the url |
| 8 | + const location = useLocation() |
| 9 | + // Gets the current path name (url) |
| 10 | + const url = location.pathname |
| 11 | + return { |
| 12 | + // Ends with login? We are on the login page |
| 13 | + isLoginPage: url.endsWith("/login"), |
| 14 | + // Ends with register? We are on the register page |
| 15 | + isRegisterPage: url.endsWith("/register"), |
| 16 | + // Ends with forgot password? we are on the forgot password page |
| 17 | + isForgotPasswordPage: url.endsWith("/forgot-password"), |
| 18 | + } |
| 19 | +} |
| 20 | +export default function LoginLayout() { |
| 21 | + const { isForgotPasswordPage, isLoginPage, isRegisterPage } = useGetCurrentPage() |
| 22 | + |
| 23 | + const key = isLoginPage ? "Login" : "Register" |
| 24 | + return ( |
| 25 | + <div className="relative z-10 flex min-h-screen w-full items-start justify-center overflow-hidden md:items-center"> |
| 26 | + <div className="relative z-10 flex h-screen w-full flex-col-reverse bg-white drop-shadow-2xl md:h-[75vh] md:w-11/12 md:flex-row lg:w-2/3"> |
| 27 | + <div |
| 28 | + className={cn( |
| 29 | + // Color of the box, add what you want! |
| 30 | + "bg-gradient-to-br from-10% from-indigo-500 via-30% via-sky-500 to-90% to-emerald-500", |
| 31 | + "z-20 flex h-full w-full origin-left scale-x-100 flex-col items-center justify-center p-4 px-8 transition-all md:w-1/2 lg:px-20", |
| 32 | + // On register page this box will be on the right side |
| 33 | + isRegisterPage && "md:translate-x-full", |
| 34 | + // On forgot password page this block will be hidden |
| 35 | + isForgotPasswordPage && " scale-x-0" |
| 36 | + )} |
| 37 | + > |
| 38 | + <div className="flex flex-col items-center gap-4"> |
| 39 | + <h1 className="!text-6xl text-center text-black">{key} Title</h1> |
| 40 | + <p className="font-semibold text-black">{key} Description</p> |
| 41 | + |
| 42 | + <Link to={isLoginPage ? href("/register") : href("/login")}> |
| 43 | + <Button>{key === "Login" ? "Register" : "Login"}</Button> |
| 44 | + </Link> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + |
| 48 | + <div |
| 49 | + className={cn( |
| 50 | + "z-10 w-full p-8 transition-transform md:w-1/2 lg:p-0", |
| 51 | + isRegisterPage && "md:-translate-x-full", |
| 52 | + isForgotPasswordPage && "-translate-x-1/2" |
| 53 | + )} |
| 54 | + > |
| 55 | + <Outlet /> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + ) |
| 60 | +} |
0 commit comments