From 9756c6cfc805f664f56bcec292dbd6036caffffb Mon Sep 17 00:00:00 2001 From: koudaihirata <2230051@ecc.ac.jp> Date: Wed, 29 Oct 2025 09:22:10 +0900 Subject: [PATCH 1/5] =?UTF-8?q?update:=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB?= =?UTF-8?q?=E3=80=81=E3=82=A2=E3=82=A4=E3=82=B3=E3=83=B3=E3=80=81=E6=9C=AC?= =?UTF-8?q?=E7=95=AA=E7=92=B0=E5=A2=83=E3=81=AEURL=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++-- public/w2cLogo.svg | 9 +++++++++ src/utils/baseURL.ts | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 public/w2cLogo.svg diff --git a/index.html b/index.html index e4b78ea..fd1e034 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,9 @@ - + - Vite + React + TS + W2C 問題集
diff --git a/public/w2cLogo.svg b/public/w2cLogo.svg new file mode 100644 index 0000000..4c4ffeb --- /dev/null +++ b/public/w2cLogo.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/utils/baseURL.ts b/src/utils/baseURL.ts index 0a5efa7..69f9c1b 100644 --- a/src/utils/baseURL.ts +++ b/src/utils/baseURL.ts @@ -1 +1,2 @@ -export const baseURL = 'http://localhost:8787' +export const baseURL = 'http://153.126.190.250:8080/' +// http://localhost:8787 From de578847ca2ae4cf0d335bc102b8ac5f8874c2e5 Mon Sep 17 00:00:00 2001 From: koudaihirata <2230051@ecc.ac.jp> Date: Tue, 2 Dec 2025 19:07:45 +0900 Subject: [PATCH 2/5] =?UTF-8?q?add:=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/ApiType/Login/type.ts | 12 +++ src/models/entity/client/Users.ts | 26 +++++ .../entity/client/fmt/LoginFmt0001VO.ts | 13 +++ src/pages/Login/action.ts | 61 +++++++++++ src/pages/Login/page.tsx | 43 ++++++-- src/pages/Login/reducer.ts | 102 ++++++++++++++++++ 6 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 src/models/ApiType/Login/type.ts create mode 100644 src/models/entity/client/Users.ts create mode 100644 src/models/entity/client/fmt/LoginFmt0001VO.ts create mode 100644 src/pages/Login/action.ts create mode 100644 src/pages/Login/reducer.ts diff --git a/src/models/ApiType/Login/type.ts b/src/models/ApiType/Login/type.ts new file mode 100644 index 0000000..61bc931 --- /dev/null +++ b/src/models/ApiType/Login/type.ts @@ -0,0 +1,12 @@ +import { LoginFmt0001VO } from '@/models/entity/client/fmt/LoginFmt0001VO' + +export namespace LoginApi { + export namespace POST { + export type Request = { + user: LoginFmt0001VO.Type + } + export type Response = { + token: string + } + } +} diff --git a/src/models/entity/client/Users.ts b/src/models/entity/client/Users.ts new file mode 100644 index 0000000..52e8015 --- /dev/null +++ b/src/models/entity/client/Users.ts @@ -0,0 +1,26 @@ +export namespace UsersVO { + export type Type = { + id?: number + name: string + email: string + password_digest: string + role?: number + class_name?: number + created_at: string + updated_at: string + delete_flag: boolean + version: number + } + + export function create(): UsersVO.Type { + return { + name: '', + email: '', + password_digest: '', + created_at: '', + updated_at: '', + delete_flag: false, + version: 0, + } + } +} diff --git a/src/models/entity/client/fmt/LoginFmt0001VO.ts b/src/models/entity/client/fmt/LoginFmt0001VO.ts new file mode 100644 index 0000000..1f782be --- /dev/null +++ b/src/models/entity/client/fmt/LoginFmt0001VO.ts @@ -0,0 +1,13 @@ +export namespace LoginFmt0001VO { + export type Type = { + email: string + password: string + } + + export function create(): LoginFmt0001VO.Type { + return { + email: '', + password: '', + } + } +} diff --git a/src/pages/Login/action.ts b/src/pages/Login/action.ts new file mode 100644 index 0000000..4878258 --- /dev/null +++ b/src/pages/Login/action.ts @@ -0,0 +1,61 @@ +import { LoginFmt0001VO } from '@/models/entity/client/fmt/LoginFmt0001VO' +import { ActionType } from './reducer' +import { LoginApi } from '@/models/ApiType/Login/type' +import { baseURL } from '@/utils/baseURL' + +export namespace Action { + export async function editForm( + dispatch: React.Dispatch, + targetName: string, + value: any, + ) { + dispatch({ + type: 'EDIT_FORM', + payload: { + targetName, + value, + }, + }) + } + + export async function logIn( + dispatch: React.Dispatch, + user: LoginFmt0001VO.Type, + ) { + dispatch({ type: 'LOGIN_REQUEST' }) + + if (!user.email || !user.password) { + return console.log('入力されていません') + } + + try { + const json: LoginApi.POST.Request = { + user, + } + + const res = await fetch(`${baseURL}auth/login`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(json), + }) + + const result: LoginApi.POST.Response = await res.json() + + dispatch({ + type: 'LOGIN_SUCCESS', + payload: { + token: result.token, + }, + }) + } catch (e) { + dispatch({ type: 'LOGIN_FAILURE' }) + throw e + } + } + + export function ShowPass(dispatch: React.Dispatch) { + dispatch({ type: 'SHOW_PASS' }) + } +} diff --git a/src/pages/Login/page.tsx b/src/pages/Login/page.tsx index e0185ae..6afec64 100644 --- a/src/pages/Login/page.tsx +++ b/src/pages/Login/page.tsx @@ -3,15 +3,15 @@ import logo from '../../assets/w2cLogo.svg' import eyeIcon from '../../assets/eye.svg' import eyeOffIcon from '../../assets/eyeOff.svg' import { Button } from '@/stories/Button' -import { useState } from 'react' +import { useReducer } from 'react' import { Link } from 'react-router-dom' +import { defaultState, reducer } from './reducer' +import { Action } from './action' export default function Login() { - const [showPassword, setShowPassword] = useState(false) + const [state, dispatch] = useReducer(reducer, undefined, defaultState) - const togglePassword = () => { - setShowPassword((prev) => !prev) - } + console.log(state) return ( <> @@ -35,6 +35,13 @@ export default function Login() { placeholder="学籍番号@ecc.ac.jp" autoComplete="email" required + onChange={(e) => { + Action.editForm( + dispatch, + 'login.email', + e.target.value, + ) + }} />
@@ -45,26 +52,44 @@ export default function Login() {
{ + Action.editForm( + dispatch, + 'login.password', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
-
@@ -45,19 +52,32 @@ export default function Signup() {
{ + Action.editForm( + dispatch, + 'signup.password', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
@@ -72,19 +92,32 @@ export default function Signup() {
{ + Action.editForm( + dispatch, + 'signup.conPassword', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
@@ -98,6 +131,13 @@ export default function Signup() { placeholder="例)ウェブ 二郎" autoComplete="email" required + onChange={(e) => { + Action.editForm( + dispatch, + 'signup.name', + e.target.value, + ) + }} />
@@ -108,11 +148,30 @@ export default function Signup() { id="text" placeholder="例)WD1A" required + onChange={(e) => { + Action.editForm( + dispatch, + 'signup.class_name', + e.target.value, + ) + }} />
-