-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1babb58
commit 2354d9f
Showing
7 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { type ChangeEvent, useState } from "react"; | ||
import { useAppDispatch, useAppSelector } from "@/types"; | ||
import { type RootState } from "@/redux/store"; | ||
import { Board } from "@/components/Board"; | ||
import { loginThunk } from "@/redux/auth/loginThunk"; | ||
import style from "./Auth.module.scss"; | ||
|
||
export const AuthPage = () => { | ||
const [deviceId, setDeviceId] = useState(""); | ||
const [pin, setPin] = useState(""); | ||
|
||
const isLoggedIn = useAppSelector( | ||
(state: RootState) => state.auth.isLoggedIn, | ||
); | ||
|
||
const onDeviceIdChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setDeviceId(e.target.value); | ||
}; | ||
|
||
const onPinChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setPin(e.target.value); | ||
}; | ||
|
||
const dispatch = useAppDispatch(); | ||
|
||
const onSubmitHandler = () => { | ||
dispatch(loginThunk(deviceId, pin)); | ||
setDeviceId(""); | ||
setPin(""); | ||
}; | ||
|
||
if (isLoggedIn) { | ||
return <Board />; | ||
} | ||
|
||
return ( | ||
<div className={style.modalWrapper}> | ||
<div className={style.modalContainer}> | ||
<h1 className={style.modalTitle}> Zabo Board Login</h1> | ||
<br /> | ||
<p className={style.modalContent}> | ||
Zabo Board 서비스를 이용하기 위해서는 등록된 device Id와 PIN을 | ||
입력하세요. | ||
<br /> | ||
Zabo Board 서비스를 등록하기 위해서는 zabo.sparcs.org 채널톡으로 | ||
문의해주세요. | ||
</p> | ||
<div className={style.form}> | ||
<label className={style.input}> | ||
device Id | ||
<input | ||
className={style.input} | ||
name="deviceId" | ||
onChange={onDeviceIdChange} | ||
/> | ||
</label> | ||
<label className={style.input}> | ||
PIN | ||
<input | ||
className={style.input} | ||
type="password" | ||
name="PIN" | ||
onChange={onPinChange} | ||
/> | ||
</label> | ||
</div> | ||
<button | ||
type="submit" | ||
className={style.submit} | ||
onClick={onSubmitHandler} | ||
> | ||
Submit | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
export interface AuthState { | ||
isLoggedIn: boolean; | ||
} | ||
|
||
const initialState: AuthState = { | ||
isLoggedIn: false, | ||
}; | ||
|
||
const authSlice = createSlice({ | ||
name: "auth", | ||
initialState, | ||
reducers: { | ||
setIsLoggedIn: (state, action) => { | ||
state.isLoggedIn = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setIsLoggedIn } = authSlice.actions; | ||
|
||
export const authReducer = authSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type AppDispatch } from "@/redux/store"; | ||
import { setIsLoggedIn } from "./authSlice"; | ||
|
||
// send device id and pin to server and get session cookie | ||
export const loginThunk = | ||
(deviceId: string, pin: string) => async (dispatch: AppDispatch) => { | ||
// request zabo board login and get response | ||
console.log(deviceId); | ||
console.log(pin); | ||
|
||
// mock api request time | ||
setTimeout(() => {}, 1000); | ||
|
||
// if success, then set zabo store's isLogin to true | ||
dispatch(setIsLoggedIn(true)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { combineReducers } from "@reduxjs/toolkit"; | ||
import { type ZaboListState, zaboReducer } from "./zabos/zaboSlice"; | ||
import { type AuthState, authReducer } from "./auth/authSlice"; | ||
|
||
export interface RootState { | ||
zabo: ZaboListState; | ||
auth: AuthState; | ||
} | ||
|
||
export const rootReducer = combineReducers({ | ||
zabo: zaboReducer, | ||
auth: authReducer, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters