|
| 1 | +import { useState } from 'react'; |
| 2 | +import { loginFields } from "./constants/formFields"; |
| 3 | +import FormAction from "./FormAction"; |
| 4 | +import FormExtra from "./FormExtra"; |
| 5 | +import Input from "./Input"; |
| 6 | + |
| 7 | +const fields=loginFields; |
| 8 | +let fieldsState = {}; |
| 9 | +fields.forEach(field=>fieldsState[field.id]=''); |
| 10 | + |
| 11 | +export default function Login(){ |
| 12 | + const [loginState,setLoginState]=useState(fieldsState); |
| 13 | + |
| 14 | + const handleChange=(e)=>{ |
| 15 | + setLoginState({...loginState,[e.target.id]:e.target.value}) |
| 16 | + } |
| 17 | + |
| 18 | + const handleSubmit=(e)=>{ |
| 19 | + e.preventDefault(); |
| 20 | + authenticateUser(); |
| 21 | + } |
| 22 | + |
| 23 | + //Handle Login API Integration here |
| 24 | + const authenticateUser = () =>{ |
| 25 | + |
| 26 | + |
| 27 | + // let loginFields={ |
| 28 | + // email:loginState['email-address'], |
| 29 | + // password:loginState['password'] |
| 30 | + // }; |
| 31 | + |
| 32 | + // const endpoint=`https://api.loginradius.com/identity/v2/auth/login?apikey=${apiKey}&apisecret=${apiSecret}`; |
| 33 | + // fetch(endpoint, |
| 34 | + // { |
| 35 | + // method:'POST', |
| 36 | + // headers: { |
| 37 | + // 'Content-Type': 'application/json' |
| 38 | + // }, |
| 39 | + // body:JSON.stringify(loginFields) |
| 40 | + // }).then(response=>response.json()) |
| 41 | + // .then(data=>{ |
| 42 | + // //API Success from LoginRadius Login API |
| 43 | + // }) |
| 44 | + // .catch(error=>console.log(error)) |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + return( |
| 49 | + <form className="mt-8 space-y-6" onSubmit={handleSubmit}> |
| 50 | + <div className="-space-y-px"> |
| 51 | + { |
| 52 | + fields.map(field=> |
| 53 | + <Input |
| 54 | + key={field.id} |
| 55 | + handleChange={handleChange} |
| 56 | + value={loginState[field.id]} |
| 57 | + labelText={field.labelText} |
| 58 | + labelFor={field.labelFor} |
| 59 | + id={field.id} |
| 60 | + name={field.name} |
| 61 | + type={field.type} |
| 62 | + isRequired={field.isRequired} |
| 63 | + placeholder={field.placeholder} |
| 64 | + /> |
| 65 | + |
| 66 | + ) |
| 67 | + } |
| 68 | + </div> |
| 69 | + |
| 70 | + <FormExtra/> |
| 71 | + <FormAction handleSubmit={handleSubmit} text="Login"/> |
| 72 | + |
| 73 | + </form> |
| 74 | + ) |
| 75 | +} |
| 76 | + |
0 commit comments