Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
style(ts): extend FormEvents in the login router
Browse files Browse the repository at this point in the history
  • Loading branch information
mu-hun committed Nov 11, 2019
1 parent cc0c3d3 commit 4a8e900
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/@types/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FormEvent } from 'react'

export interface TypeForm extends FormEvent<HTMLFormElement> {}
7 changes: 4 additions & 3 deletions src/routes/Fetch.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { useState, FormEvent, useEffect, Fragment } from 'react'
import React, { useState, useEffect, Fragment } from 'react'

import { fetchAndSet, isCodeFF } from '../control'
import { Input } from '../view/Input'
import { saveToken } from '../utils'
import { Redirect } from 'react-router-dom'
import { TypeForm } from '../@types/events'

interface FormElements extends HTMLFormElement {
student_no: HTMLInputElement
student_pw: HTMLInputElement
}

interface FormTarget extends FormEvent<HTMLFormElement> {
interface FormTarget extends TypeForm {
target: FormElements
}

Expand All @@ -34,7 +35,7 @@ const App = () => {
<div id="form">
<p>학번 및 비밀번호를 입력해주세요!</p>
<form onSubmit={onSubmit}>
<Input name="student_no" type="username" />
<Input name="student_no" type="number" />
<Input name="student_pw" type="password" />
<button type="submit">Submit</button>
</form>
Expand Down
17 changes: 12 additions & 5 deletions src/routes/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import React, { FormEvent, useState, Fragment } from 'react'
import React, { useState, Fragment } from 'react'

import { Input } from '../view/Input'
import { submitID } from '../control'
import { TypeForm } from '../@types/events'

interface FormElements extends HTMLFormElement {
mailid: HTMLInputElement
}

interface FormTarget extends TypeForm {
target: FormElements
}

const App: React.FC = () => {
const [flag, setFlag] = useState<boolean>()
const onSubmit = async (event: FormEvent) => {
const onSubmit = async (event: FormTarget) => {
event.preventDefault()
// @ts-ignore
const { value }: { value: string } = event.target[0]
setFlag(await submitID(value))
setFlag(await submitID(event.target.mailid.value))
}
return (
<Fragment>
Expand Down

0 comments on commit 4a8e900

Please sign in to comment.