@accounter/client
Version:
2 lines (1 loc) • 2.11 kB
JavaScript
import{r as n,ip as g,o as f,E as p,G as b,j as e,W as v,Z as o,_ as l,$ as c,a0 as i,I as d,a2 as m,B as w,a8 as N,R as y,t as x,ac as u}from"./index-DRqooPz9.js";const S=N({username:u().min(2).max(50),password:u().min(2).max(50)});function F(){const{authService:a}=n.useContext(g);n.useEffect(()=>{a.logout()},[a]);const h=f(),s=p({resolver:b(S),defaultValues:{username:"",password:""}});function j(r){try{a.login(r.username,r.password).then(t=>{h(y.HOME)}),x.success("Success",{description:"You have successfully logged in."})}catch(t){console.error(t),x.error("Error",{description:"Invalid credentials. Please try again."})}}return e.jsxs("div",{className:"w-full flex flex-col justify-center items-center h-screen lg:grid lg:min-h-[200px] lg:grid-cols-2 xl:min-h-screen",children:[e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(v,{...s,children:e.jsxs("form",{onSubmit:s.handleSubmit(j),className:"space-y-8 w-[300px]",children:[e.jsxs("div",{className:"grid gap-2 text-center",children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Accounter"}),e.jsx("h1",{className:"text-3xl font-bold",children:"Login"}),e.jsx("p",{className:"text-balance text-muted-foreground",children:"Enter your credentials to login."})]}),e.jsx(o,{control:s.control,name:"username",render:({field:r})=>e.jsxs(l,{children:[e.jsx(c,{children:"Username"}),e.jsx(i,{children:e.jsx(d,{placeholder:"Username",...r})}),e.jsx(m,{})]})}),e.jsx(o,{control:s.control,name:"password",render:({field:r})=>e.jsxs(l,{children:[e.jsx(c,{children:"Password"}),e.jsx(i,{children:e.jsx(d,{placeholder:"Password",type:"password",...r})}),e.jsx(m,{})]})}),e.jsx(w,{disabled:s.formState.isSubmitting||!s.formState.isValid,className:"w-full font-semibold",type:"submit",children:"Login"})]})})}),e.jsx("div",{className:"hidden bg-muted lg:block bg-black rounded-tl-3xl rounded-bl-3xl",children:e.jsx("div",{className:"flex flex-row justify-center items-center h-screen",children:e.jsx("img",{src:"../../icons/guild-logo.svg",alt:"nature",className:"w-[100px] h-[100px] object-cover"})})})]})}export{F as LoginPage};