component-library-mustafa-akagunduz
Version:
Air Command System projesi için geliştirilmiş React component kütüphanesi
3 lines (2 loc) • 3.95 kB
JavaScript
import{__awaiter as e}from"../node_modules/tslib/tslib.es6.js";import{jsxs as r,jsx as o}from"react/jsx-runtime";import{useState as a}from"react";import{LuMoon as s,LuSun as l}from"../node_modules/react-icons/lu/index.js";import{Button as i}from"./Button.js";import{Input as n}from"./Input.js";const t=({onLogin:t,onThemeChange:m,onLanguageChange:d,currentTheme:c,currentLanguage:g,isLoading:h=!1,validatePassword:p,t:u})=>{const[_,f]=a({userName:"",password:""}),[N,w]=a({userName:"",password:""}),[b,v]=a(""),[C,R]=a(!1),y=e=>{const{name:r,value:o}=e.target;f(e=>Object.assign(Object.assign({},e),{[r]:o})),N[r]&&w(e=>Object.assign(Object.assign({},e),{[r]:""})),b&&v("")};return r("div",{className:"login-form",children:[r("div",{className:"login-form__header",children:[r("h1",{className:"login-form__title",children:[o("span",{className:"login-form__title-bold",children:"AIR"}),"Command"]}),o("p",{className:"login-form__subtitle",children:u("login.welcome")})]}),r("form",{onSubmit:r=>e(void 0,void 0,void 0,function*(){if(r.preventDefault(),(()=>{const e={userName:"",password:""};return _.userName.trim()||(e.userName=u("login.emailRequired")),_.password.trim()?p(_.password)||(e.password=u("login.passwordTooShort")):e.password=u("login.passwordRequired"),w(e),!e.userName&&!e.password})()){R(!0),v("");try{const e=yield t({userName:_.userName,password:_.password});if(!e.success&&e.error){switch(e.errorType){case"NETWORK_ERROR":v(u("login.checkConnection"));break;case"TIMEOUT_ERROR":v(u("login.tryAgain"));break;case"INVALID_CREDENTIALS":v(u("login.checkCredentials"));break;case"SERVER_ERROR":v(u("login.tryLater"));break;default:v(u("login.loginCredentialsIncorrect"))}}}catch(e){v(u("common.unexpectedError"))}finally{R(!1)}}}),className:"login-form__form",children:[r("div",{className:"login-form__field",children:[o("label",{htmlFor:"userName",className:"login-form__label",children:u("login.email")}),o(n,{type:"text",id:"userName",name:"userName",value:_.userName,onChange:y,placeholder:u("login.emailPlaceholder"),className:"login-form__input",error:!!N.userName,disabled:C}),N.userName&&o("span",{className:"login-form__error",children:N.userName})]}),r("div",{className:"login-form__field",children:[o("label",{htmlFor:"password",className:"login-form__label",children:u("login.password")}),o(n,{type:"password",id:"password",name:"password",value:_.password,onChange:y,placeholder:u("login.passwordPlaceholder"),className:"login-form__input",error:!!N.password,disabled:C}),N.password&&o("span",{className:"login-form__error",children:N.password})]}),b&&r("div",{className:"login-form__login-error",children:[o("svg",{className:"login-form__error-icon",width:"20",height:"19",viewBox:"0 0 20 19",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:o("path",{d:"M2.09977 18.5H17.9002C19.5159 18.5 20.5231 16.7325 19.7153 15.3249L11.8151 1.55571C11.0072 0.148096 8.9928 0.148096 8.18494 1.55571L0.284714 15.3249C-0.523145 16.7325 0.484055 18.5 2.09977 18.5ZM10 11.0915C9.42296 11.0915 8.95083 10.6152 8.95083 10.0331V7.91643C8.95083 7.33434 9.42296 6.85808 10 6.85808C10.577 6.85808 11.0492 7.33434 11.0492 7.91643V10.0331C11.0492 10.6152 10.577 11.0915 10 11.0915ZM11.0492 15.3249H8.95083V13.2082H11.0492V15.3249Z",fill:"#DC2626"})}),o("span",{className:"login-form__error-text",children:b})]}),o(i,{type:"submit",variant:"primary",size:"large",fullWidth:!0,loading:C,disabled:C,children:u("login.loginButton")})]}),o("div",{className:"login-form__footer",children:r("div",{className:"login-form__controls",children:[o("button",{type:"button",onClick:()=>m(),className:"login-form__theme-btn","aria-label":u("light"===c?"theme.dark":"theme.light"),children:o("light"===c?s:l,{})}),o("button",{type:"button",onClick:()=>{d("tr"===g?"en":"tr")},className:"login-form__lang-btn","aria-label":"tr"===g?"English":"Türkçe",children:"tr"===g?"En":"Tr"})]})})]})};export{t as LoginForm};
//# sourceMappingURL=LoginForm.js.map