-
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
Showing
20 changed files
with
319 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
## VITE_API_SERVER_URL should end without "/" | ||
VITE_API_SERVER_URL= | ||
VITE_ANIMATION_DURATION= | ||
VITE_TRANSITION_INTERVAL= | ||
VITE_TRANSITION_INTERVAL= | ||
|
||
## put s3 url for initial content for zabo boards | ||
VITE_INIT_CONTENT1= | ||
VITE_INIT_CONTENT2= |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
### Node ### | ||
# Logs | ||
.idea | ||
.uuid | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
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 |
---|---|---|
|
@@ -40,3 +40,4 @@ | |
.read-the-docs { | ||
color: #888; | ||
} | ||
|
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,46 @@ | ||
@import "src/styles"; | ||
|
||
.modalWrapper { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
padding-top: 500px; | ||
} | ||
|
||
.modalContainer { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 300px; | ||
max-width: 1800px; | ||
} | ||
|
||
.modalTitle { | ||
font-size: 100px; | ||
} | ||
|
||
.modalContent { | ||
font-size: 50px; | ||
} | ||
|
||
.form { | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: 100px; | ||
} | ||
|
||
.input { | ||
font-size: 50px; | ||
margin: 10px; | ||
} | ||
|
||
.submit { | ||
margin-top: 20px; | ||
font-size: 50px; | ||
} | ||
|
||
.errorBox { | ||
font-size: 50px; | ||
color: red; | ||
} |
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,46 @@ | ||
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 { LoginPage } from "@/components/Auth/LoginPage"; | ||
|
||
export const AuthPage = () => { | ||
const [deviceId, setDeviceId] = useState(""); | ||
const [pin, setPin] = useState(""); | ||
|
||
const isLoggedIn = useAppSelector( | ||
(state: RootState) => state.auth.isLoggedIn, | ||
); | ||
|
||
const errorMessage = useAppSelector( | ||
(state: RootState) => state.auth.errorMessage, | ||
); | ||
|
||
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(""); | ||
}; | ||
|
||
return isLoggedIn ? ( | ||
<Board /> | ||
) : ( | ||
<LoginPage | ||
errorMessage={errorMessage} | ||
onDeviceIdChange={onDeviceIdChange} | ||
onPinChange={onPinChange} | ||
onSubmitHandler={onSubmitHandler} | ||
/> | ||
); | ||
}; |
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,53 @@ | ||
import type { ChangeEvent } from "react"; | ||
import style from "./Auth.module.scss"; | ||
|
||
type LoginPageProps = { | ||
onDeviceIdChange: (e: ChangeEvent<HTMLInputElement>) => void; | ||
onPinChange: (e: ChangeEvent<HTMLInputElement>) => void; | ||
onSubmitHandler: () => void; | ||
errorMessage: string; | ||
}; | ||
|
||
export const LoginPage = ({ | ||
onDeviceIdChange, | ||
onPinChange, | ||
onSubmitHandler, | ||
errorMessage, | ||
}: LoginPageProps) => ( | ||
<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 className={style.errorBox}>{errorMessage}</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./Auth"; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./Board"; | ||
export * from "./Auth"; |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export const API_SERVER_URL = import.meta.env.VITE_API_SERVER_URL; | ||
export const ANIMATION_DURATION = import.meta.env.VITE_ANIMATION_DURATION; | ||
export const TRANSITION_INTERVAL = import.meta.env.VITE_TRANSITION_INTERVAL; | ||
|
||
export const INIT_CONTENT1 = import.meta.env.VITE_INIT_CONTENT1; | ||
export const INIT_CONTENT2 = import.meta.env.VITE_INIT_CONTENT2; |
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,28 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
export interface AuthState { | ||
isLoggedIn: boolean; | ||
errorMessage: string; | ||
} | ||
|
||
const initialState: AuthState = { | ||
isLoggedIn: false, | ||
errorMessage: "", | ||
}; | ||
|
||
const authSlice = createSlice({ | ||
name: "auth", | ||
initialState, | ||
reducers: { | ||
setIsLoggedIn: (state, action) => { | ||
state.isLoggedIn = action.payload; | ||
}, | ||
setErrorMessage: (state, action) => { | ||
state.errorMessage = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setIsLoggedIn, setErrorMessage } = 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,24 @@ | ||
import { type AppDispatch } from "@/redux/store"; | ||
import axios from "axios"; | ||
import { setIsLoggedIn, setErrorMessage } 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 | ||
|
||
// mock api request time | ||
const response = await axios.post(`/api/board/login`, { | ||
name: deviceId, | ||
password: pin, | ||
}); | ||
|
||
const isLoginSuccess = response.data.success; | ||
|
||
// if success, then set zabo store's isLogin to true | ||
if (isLoginSuccess) { | ||
dispatch(setIsLoggedIn(true)); | ||
} else { | ||
dispatch(setErrorMessage(response.data.error)); | ||
} | ||
}; |
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
Oops, something went wrong.