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/App.tsx b/src/App.tsx index a368a49..41714a3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,28 +1,50 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import './App.css' import { createBrowserRouter, createRoutesFromElements, + Navigate, Outlet, Route, RouterProvider, } from 'react-router-dom' -import Login from './pages/Login/page' -import Home from './pages/Home/page' +import Home from './pages/Home' import NotFound from './pages/NotFound' import Problems from './pages/Problems' import CreateProblem from './pages/CreateProblem' import CreateProblemDetail from './pages/CreateProblem/detail' import Header from './components/Header/Header' import Admin from './pages/Admin' -import Signup from './pages/Signup/page' +import Login from './pages/Login' +import Signup from './pages/Signup' +import { UserCookieFmt0001VO } from './models/entity/client/fmt/UserCookieFmt0001VO' +import { getCookie, getToken } from './utils/getCookie' + +const RequireAuth: React.FC = () => { + const token = getToken('W2CToken') + return token ? : +} const MainLayout: React.FC = () => { const [state, setState] = useState(true) + const [user, setUser] = useState( + undefined, + ) + + useEffect(() => { + const userStr = getCookie('user') + const user: UserCookieFmt0001VO.Type = userStr + ? JSON.parse(userStr) + : null + + setUser(user) + }, []) + + console.log(user) return (
-
setState(!state)} state={state} /> +
setState(state)} state={state} />
} /> } /> - }> - } /> - } /> - } /> - } - /> - } /> + }> + }> + } /> + } /> + } /> + } + /> + } /> + } /> , diff --git a/src/models/ApiType/Login/type.ts b/src/models/ApiType/Login/type.ts new file mode 100644 index 0000000..fa22bee --- /dev/null +++ b/src/models/ApiType/Login/type.ts @@ -0,0 +1,16 @@ +export namespace LoginApi { + export namespace POST { + export type Request = { + email: string + password: string + } + export type Response = { + token: string + id: number + email: string + name: string + role: string + class_name: string + } + } +} diff --git a/src/models/ApiType/Signup/type.ts b/src/models/ApiType/Signup/type.ts new file mode 100644 index 0000000..91bc036 --- /dev/null +++ b/src/models/ApiType/Signup/type.ts @@ -0,0 +1,16 @@ +export namespace SignupApi { + export namespace POST { + export type Request = { + name: string + email: string + password: string + role: string + class_name: string + } + + export type Response = { + name: string + email: 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/models/entity/client/fmt/SignupFmt0001VO.ts b/src/models/entity/client/fmt/SignupFmt0001VO.ts new file mode 100644 index 0000000..bded890 --- /dev/null +++ b/src/models/entity/client/fmt/SignupFmt0001VO.ts @@ -0,0 +1,9 @@ +export namespace SignupFmt0001VO { + export type Type = { + name: string + email: string + password: string + role: string + class_name: string + } +} diff --git a/src/models/entity/client/fmt/UserCookieFmt0001VO.ts b/src/models/entity/client/fmt/UserCookieFmt0001VO.ts new file mode 100644 index 0000000..6ffc729 --- /dev/null +++ b/src/models/entity/client/fmt/UserCookieFmt0001VO.ts @@ -0,0 +1,9 @@ +export namespace UserCookieFmt0001VO { + export type Type = { + id: number + name: string + email: string + role: string + class_name: string + } +} diff --git a/src/pages/Home/page.tsx b/src/pages/Home/index.tsx similarity index 80% rename from src/pages/Home/page.tsx rename to src/pages/Home/index.tsx index eee45da..df870ba 100644 --- a/src/pages/Home/page.tsx +++ b/src/pages/Home/index.tsx @@ -1,8 +1,13 @@ +import { getCookie } from '@/utils/getCookie' import styles from './style.module.css' -import { useState } from 'react' +import { useEffect, useState } from 'react' +import { useNavigate } from 'react-router-dom' +import { UserCookieFmt0001VO } from '@/models/entity/client/fmt/UserCookieFmt0001VO' export default function Home() { const [filter, setFilter] = useState('stillAns') + const [userName, setUserName] = useState('') + const navigate = useNavigate() const tasks = [ { @@ -36,10 +41,21 @@ export default function Home() { filter === 'all' ? true : task.status === filter, ) + useEffect(() => { + const userStr = getCookie('user') + const user: UserCookieFmt0001VO.Type = userStr + ? JSON.parse(userStr) + : null + + const name = user.name + + setUserName(name) + }, []) + return ( <>
-

平田晃大

+

{userName}

{ + Action.editForm( + dispatch, + 'login.password', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
-
@@ -45,19 +53,32 @@ export default function Signup() {
{ + Action.editForm( + dispatch, + 'signup.password', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
@@ -72,19 +93,32 @@ export default function Signup() {
{ + Action.editForm( + dispatch, + 'signup.conPassword', + e.target.value, + ) + }} /> パスワード表示切り替え + Action.ShowPass(dispatch) + } className={styles.eyeIcon} />
@@ -98,6 +132,13 @@ export default function Signup() { placeholder="例)ウェブ 二郎" autoComplete="email" required + onChange={(e) => { + Action.editForm( + dispatch, + 'signup.name', + e.target.value, + ) + }} />
@@ -108,11 +149,30 @@ export default function Signup() { id="text" placeholder="例)WD1A" required + onChange={(e) => { + Action.editForm( + dispatch, + 'signup.class_name', + e.target.value, + ) + }} />
-