Skip to content

Commit

Permalink
Merge pull request #104 from softeerbootcamp4th/feature/admin
Browse files Browse the repository at this point in the history
[Feat] 어드민 배포 및 404 페이지 추가
  • Loading branch information
jw0097 authored Aug 23, 2024
2 parents bf4ca53 + 5b8af48 commit a09637a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"admin": "webpack-dev-server --hot --config webpack.config.js",
"adminBuild": "webpack --config webpack.config.js"
"adminBuild": "webpack --config webpack.config.js --env DEV=false"
},
"keywords": [],
"author": "",
Expand Down
20 changes: 12 additions & 8 deletions src/admin/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ import {
fetchLogForm,
} from "../types/event";

const RANDOM_URL = process.env.RANDOM_URL;

export const fetchEventList = async (): Promise<
ApiResponse<{ eventList: EventInfo[] }>
> => {
const response = await fetch("/admin/eventlist");
const response = await fetch(RANDOM_URL + "/admin/eventlist");

return await response.json();
};

export const fetchLogList = async (
page: number,
): Promise<ApiResponse<fetchLogForm>> => {
const response = await fetch(`/admin/log?page=${page}`);
const response = await fetch(RANDOM_URL + `/admin/log?page=${page}`);

return await response.json();
};

export const putRandomEvent = async (
eventInfo: FormData,
): Promise<ApiResponse<EventInfo>> => {
const response = await fetch("/admin/lots/config", {
const response = await fetch(RANDOM_URL + "/admin/lots/config", {
method: "PUT",
headers: {},
body: eventInfo,
Expand All @@ -39,7 +41,7 @@ export const putRandomEvent = async (
export const putFCFSEvent = async (
eventInfo: FormData,
): Promise<ApiResponse<EventInfo>> => {
const response = await fetch("/admin/arrival/config", {
const response = await fetch(RANDOM_URL + "/admin/arrival/config", {
method: "PUT",
headers: {},
body: eventInfo,
Expand All @@ -66,7 +68,8 @@ export const fetchFCFSParticipants = async ({
}>
> => {
const response = await fetch(
`/admin/arrival/applicationList?page=${page}${createdAt ? `&createdAt=${createdAt}` : ""}${phoneNum ? `&phoneNum=${phoneNum}` : ""}`,
RANDOM_URL +
`/admin/arrival/applicationList?page=${page}${createdAt ? `&createdAt=${createdAt}` : ""}${phoneNum ? `&phoneNum=${phoneNum}` : ""}`,
);

return response.json();
Expand All @@ -88,7 +91,8 @@ export const fetchRandomParticipants = async ({
}>
> => {
const response = await fetch(
`/admin/lots/applicationList?page=${page}${phoneNum ? `&phoneNum=${phoneNum}` : ""}`,
RANDOM_URL +
`/admin/lots/applicationList?page=${page}${phoneNum ? `&phoneNum=${phoneNum}` : ""}`,
);

return response.json();
Expand All @@ -97,7 +101,7 @@ export const fetchRandomParticipants = async ({
export const putFCFSReward = async (
rewardInfo: RewardInterface,
): Promise<ApiResponse<RewardInterface>> => {
const response = await fetch("/admin/arrival/rewardconfig", {
const response = await fetch(RANDOM_URL + "/admin/arrival/rewardconfig", {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand All @@ -111,7 +115,7 @@ export const putFCFSReward = async (
export const putRandomReward = async (
rewardInfo: RewardInterface,
): Promise<ApiResponse<RewardInterface>> => {
const response = await fetch("/admin/lots/rewardconfig", {
const response = await fetch(RANDOM_URL + "/admin/lots/rewardconfig", {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("DriveDescriptionItem 렌더링 테스트", () => {
});

test("아무 요소도 선택되지 않았다면 텍스트가 보이지 않고, 이미지가 렌더링 되야 한다.", () => {
render(<DriveDescriptionItem {...defaultProps} noneSelected />);
render(<DriveDescriptionItem {...defaultProps} />);

const article = screen.getByRole("figure");

Expand All @@ -33,13 +33,7 @@ describe("DriveDescriptionItem 렌더링 테스트", () => {
});

test("요소가 선택되지 않았다면 텍스트가 보이지 않고, 투명도가 적용된 이미지가 렌더링 되야 한다.", () => {
render(
<DriveDescriptionItem
{...defaultProps}
noneSelected={false}
isSelected={false}
/>,
);
render(<DriveDescriptionItem {...defaultProps} isSelected={false} />);

const article = screen.getByRole("figure");

Expand All @@ -50,13 +44,7 @@ describe("DriveDescriptionItem 렌더링 테스트", () => {
});

test("요소가 선택되지 않았다면 텍스트가 보이고, 투명도가 적용된 이미지가 렌더링 되야 한다.", () => {
render(
<DriveDescriptionItem
{...defaultProps}
noneSelected={false}
isSelected={false}
/>,
);
render(<DriveDescriptionItem {...defaultProps} isSelected={false} />);

const article = screen.getByRole("figure");

Expand Down
9 changes: 6 additions & 3 deletions src/client/pages/FCFSEventPage/FCFSEventPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import Glow from "../../components/common/Glow/Glow";
import HomeButton from "../../components/common/HomeButton/HomeButton";
import AuthTooltip from "../../components/common/AuthTooltip/AuthTooltip";
import Cookies from "js-cookie";
import { useNavigate } from "react-router";
import { useLocation, useNavigate } from "react-router";
import { useAppContext } from "../../providers/AppProvider";
import { useErrorBoundary } from "react-error-boundary";
import { calculateLeftTime, calculateLeftTimeToEnd } from "../../utils/util";
import { calculateLeftTime } from "../../utils/util";

const FCFSEventPage = () => {
const location = useLocation();
const { showBoundary } = useErrorBoundary();
const [quizInfo, setQuizInfo] = useState<QuizInfo | null>(null);
const navigate = useNavigate();
Expand All @@ -41,7 +42,9 @@ const FCFSEventPage = () => {
};
tryFetch();
if (!isAuth) navigate("/");
if (calculateLeftTimeToEnd() < 0 || calculateLeftTime() > 0) {

if (location.state?.leftTime !== 0) {
console.log("lefttime 0");
navigate("/");
}
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const FCFSEventSection = (
<Button
onClick={() => {
isAuth
? navigate("event1")
? navigate("event1", { state: { leftTime: leftTime } })
: navigate("auth-modal", {
state: { background: location, event: 1, isOpen: isOpen },
});
Expand Down
2 changes: 2 additions & 0 deletions src/client/pages/mainPage/MainScreen/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FCFSEventSection from "./FCFSEventSection/FCFSEventSection";
import RandomEventSection from "./RandomEventSection/RandomEventSection";
import mainCar from "../../../../common/assets/images/mainCar.png?as=webp";
import EventSelectSection from "./EventSelectSection/EventSelectSection";
import AuthTooltip from "../../../components/common/AuthTooltip/AuthTooltip";

const MainScreen = (
props: React.HTMLProps<HTMLDivElement>,
Expand Down Expand Up @@ -115,6 +116,7 @@ const MainScreen = (

return (
<>
<AuthTooltip />
<GlowBackground />
<EventSelectSection
onFCFSClick={onFCFSClick}
Expand Down
16 changes: 14 additions & 2 deletions src/client/router/router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from "react";
import { BrowserRouter, Route, Routes, useLocation } from "react-router-dom";
import {
BrowserRouter,
Route,
Routes,
useLocation,
useNavigate,
} from "react-router-dom";
import MainPage from "../pages/mainPage/MainPage";
import FCFSEventPage from "../pages/FCFSEventPage/FCFSEventPage";
import FCFSEventResultPage from "../pages/FCFSEventResultPage/FCFSEventResultPage";
Expand All @@ -12,6 +18,7 @@ import FallbackPage from "../pages/fallbackPage/FallbackPage";

const RouterWithModal = () => {
const location = useLocation();
const navigate = useNavigate();
const background = location.state && location.state.background;

return (
Expand All @@ -25,7 +32,12 @@ const RouterWithModal = () => {
</Route>
<Route path="/event2/result" element={<RandomEventResultPage />} />
<Route path="/auth-modal" element={<AuthModal />} />
<Route path="*" element={<h1>404</h1>} />
<Route
path="*"
element={
<FallbackPage error="404" resetErrorBoundary={() => navigate(-1)} />
}
/>
</Routes>
{background && (
<Routes>
Expand Down
8 changes: 4 additions & 4 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = (env) => {
}),
createWebPGenerator({
presetName: "webp-smallh",
quality: 75,
quality: 100,
fileNames: [
"e1Gift.png",
"Drive1.png",
Expand All @@ -96,8 +96,8 @@ module.exports = (env) => {
"whiteRight.png",
],
resizeOptions: {
width: 300,
hgith: 170,
width: 600,
height: 340,
},
}),
createWebPGenerator({
Expand All @@ -111,7 +111,7 @@ module.exports = (env) => {
}),
createWebPGenerator({
presetName: "webp-blur",
quality: 20,
quality: 40,
fileNames: [
"random0.png",
"random1.png",
Expand Down
17 changes: 10 additions & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const path = require("path");
const webpack = require("webpack");
const dotenv = require("dotenv");
const HtmlWebPackPlugin = require("html-webpack-plugin");

module.exports = (env) => {
const { DEV } = env;
if (DEV === "true") {
dotenv.config({ path: "./.env.dev" });
} else if (DEV === "false") {
dotenv.config({ path: "./.env.prod" });
console.log("process.env.RANDOM_URL");
}
return {
mode: "development",
devtool: "inline-source-map",
devServer: {
port: 9000,
historyApiFallback: true,
open: true,
proxy: [
{
context: ["/admin"],
target: "http://3.38.151.69:8080",
},
],
},
entry: "./src/admin/index.tsx",
output: {
Expand Down Expand Up @@ -74,7 +76,8 @@ module.exports = (env) => {
filename: "index.html", // output으로 출력할 파일은 index.html 이다.
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env),
"process.env.RANDOM_URL": JSON.stringify(process.env.RANDOM_URL),
"process.env.FCFS_URL": JSON.stringify(process.env.FCFS_URL),
}),
],
};
Expand Down
2 changes: 1 addition & 1 deletion webpackUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createWebPGenerator({
{
quality: quality,
...(resizeOptions && {
resize: { width: 300, height: 600 },
resize: resizeOptions,
}),
},
],
Expand Down

0 comments on commit a09637a

Please sign in to comment.