Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#131-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj2713 committed Aug 12, 2024
2 parents a3dd68d + ef215ea commit b93bbbb
Show file tree
Hide file tree
Showing 38 changed files with 1,645 additions and 313 deletions.
1 change: 1 addition & 0 deletions admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"class-variance-authority": "^0.7.0",
"react": "^18.3.1",
"react-cookie": "^7.2.0",
"react-dom": "^18.3.1",
"react-router-dom": "^6.25.1"
},
Expand Down
5 changes: 3 additions & 2 deletions admin/public/assets/icons/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions admin/src/apis/authAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { PostAuthParams, PostAuthResponse } from "@/types/authApi";
import "@/types/lotteryApi";
import { fetchWithTimeout } from "@/utils/fetchWithTimeout";

const baseURL = `${import.meta.env.VITE_API_URL}/admin/auth`;
const headers = {
"Content-Type": "application/json",
};

export const AuthAPI = {
async postAuth(body: PostAuthParams): Promise<PostAuthResponse> {
try {
return new Promise((resolve) =>
resolve({
accessToken: "access token",
})
);
const response = await fetchWithTimeout(`${baseURL}`, {
method: "POST",
headers: headers,
body: JSON.stringify(body),
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
};
138 changes: 138 additions & 0 deletions admin/src/apis/lotteryAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {
GetLotteryExpectationsParams,
GetLotteryExpectationsResponse,
GetLotteryResponse,
GetLotteryWinnerParams,
GetLotteryWinnerResponse,
PostLotteryWinnerResponse,
} from "@/types/lotteryApi";
import { fetchWithTimeout } from "@/utils/fetchWithTimeout";

const baseURL = `${import.meta.env.VITE_API_URL}/admin/event/lottery`;
const headers = {
"Content-Type": "application/json",
};

export const LotteryAPI = {
async getLottery(): Promise<GetLotteryResponse> {
try {
return new Promise((resolve) =>
resolve([
{
lotteryEventId: 1,
startDate: "2024-07-26",
startTime: "00:00",
endDate: "2024-08-25",
endTime: "23:59",
appliedCount: 1000000,
winnerCount: 363,
},
])
);
const response = await fetchWithTimeout(`${baseURL}`, {
method: "GET",
headers: headers,
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async postLotteryWinner(): Promise<PostLotteryWinnerResponse> {
try {
return new Promise((resolve) => resolve({ message: "요청에 성공하였습니다." }));
const response = await fetchWithTimeout(`${baseURL}/winner`, {
method: "POST",
headers: headers,
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async getLotteryWinner({
id,
size,
page,
phoneNumber,
}: GetLotteryWinnerParams): Promise<GetLotteryWinnerResponse> {
try {
return new Promise((resolve) =>
resolve({
data: [
{
id: 1,
phoneNumber: "010-1111-2222",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
{
id: 2,
phoneNumber: "010-1111-2223",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
{
id: 3,
phoneNumber: "010-1111-2224",
linkClickedCounts: 1,
expectation: 1,
appliedCount: 3,
},
],
isLastPage: false,
totalParticipants: 10000,
})
);
const response = await fetchWithTimeout(
`${baseURL}/${id}/winner?size=${size}&page=${page}&number=${phoneNumber}`,
{
method: "GET",
headers: headers,
}
);
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async getLotteryExpectations({
lotteryId,
participantId,
}: GetLotteryExpectationsParams): Promise<GetLotteryExpectationsResponse> {
try {
return new Promise((resolve) =>
resolve([
{
casperId: 1,
expectation: "기대평 1",
},
{
casperId: 2,
expectation: "기대평 2",
},
{
casperId: 3,
expectation: "기대평 3",
},
])
);
const response = await fetchWithTimeout(
`${baseURL}/${lotteryId}/participants/${participantId}/expectations`,
{
method: "GET",
headers: headers,
}
);
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
};
147 changes: 147 additions & 0 deletions admin/src/apis/rushAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import {
GetRushOptionsParams,
GetRushOptionsResponse,
GetRushParticipantListParams,
GetRushParticipantListResponse,
GetRushWinnerListParams,
} from "@/types/rushApi";
import { fetchWithTimeout } from "@/utils/fetchWithTimeout";

const baseURL = `${import.meta.env.VITE_API_URL}/admin/event/rush`;
const headers = {
"Content-Type": "application/json",
};

export const RushAPI = {
async getRushParticipantList({
id,
phoneNumber,
size,
page,
option,
}: GetRushParticipantListParams): Promise<GetRushParticipantListResponse> {
try {
return new Promise((resolve) =>
resolve({
data: [
{
id: 1,
phoneNumber: "010-1111-2222",
balanceGameChoice: option,
createdAt: "2024-07-25 20:00:123",
rank: 1,
},
{
id: 3,
phoneNumber: "010-1111-2222",
balanceGameChoice: option,
createdAt: "2024-07-25 20:00:125",
rank: 2,
},
{
id: 4,
phoneNumber: "010-1111-2222",
balanceGameChoice: option,
createdAt: "2024-07-25 20:00:127",
rank: 3,
},
],
isLastPage: false,
totalParticipants: 10000,
})
);
const response = await fetchWithTimeout(
`${baseURL}/${id}/participants?number=${phoneNumber}&size=${size}&page=${page}&option=${option}`,
{
method: "GET",
headers: headers,
}
);
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async getRushWinnerList({
id,
phoneNumber,
size,
page,
}: GetRushWinnerListParams): Promise<GetRushParticipantListResponse> {
try {
return new Promise((resolve) =>
resolve({
data: [
{
id: 1,
phoneNumber: "010-3843-6999",
balanceGameChoice: 1,
createdAt: "2024-07-25 20:00:123",
rank: 1,
},
{
id: 3,
phoneNumber: "010-1111-2222",
balanceGameChoice: 1,
createdAt: "2024-07-25 20:00:125",
rank: 2,
},
{
id: 4,
phoneNumber: "010-1111-2222",
balanceGameChoice: 1,
createdAt: "2024-07-25 20:00:127",
rank: 3,
},
],
isLastPage: false,
totalParticipants: 10000,
})
);
const response = await fetchWithTimeout(
`${baseURL}/${id}/participants?number=${phoneNumber}&size=${size}&page=${page}`,
{
method: "GET",
headers: headers,
}
);
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
async getRushOptions({ id }: GetRushOptionsParams): Promise<GetRushOptionsResponse> {
try {
return new Promise((resolve) =>
resolve([
{
rushOptionId: 1,
mainText: "첫 차로 저렴한 차 사기",
subText: " 첫 차는 가성비가 짱이지!",
resultMainText: "누구보다 가성비 갑인 캐스퍼 일렉트릭",
resultSubText: "전기차 평균보다 훨씬 저렴한 캐스퍼 일렉트릭!",
imageUrl: "left_image.png",
},
{
rushOptionId: 2,
mainText: "첫 차로 성능 좋은 차 사기",
subText: " 차는 당연히 성능이지!",
resultMainText: "필요한 건 다 갖춘 캐스퍼 일렉트릭",
resultSubText: "전기차 평균보다 훨씨니 저렴한 캐스퍼 일렉트릭!",
imageUrl: "left_image.png",
},
])
);
const response = await fetchWithTimeout(`${baseURL}/${id}/options`, {
method: "GET",
headers: headers,
});
return response.json();
} catch (error) {
console.error("Error:", error);
throw error;
}
},
};
4 changes: 2 additions & 2 deletions admin/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HTMLProps } from "react";
import { ComponentProps } from "react";

interface InputProps extends HTMLProps<HTMLInputElement> {
interface InputProps extends ComponentProps<"input"> {
label?: string;
}

Expand Down
5 changes: 1 addition & 4 deletions admin/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Outlet } from "react-router-dom";
import { RushEventContext } from "@/contexts/rushEventContext";
import Header from "../Header";

export default function Layout() {
return (
<div className="overflow-hidden h-screen">
<Header />
<div className="mb-[80px]">
<RushEventContext>
<Outlet />
</RushEventContext>
<Outlet />
</div>
</div>
);
Expand Down
27 changes: 27 additions & 0 deletions admin/src/components/Route/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useCookies } from "react-cookie";
import { Navigate, Outlet } from "react-router-dom";
import { COOKIE_KEY } from "@/constants/cookie";

interface RouteProps {
redirectPath?: string;
}

export function ProtectedRoute({ redirectPath = "/login" }: RouteProps) {
const [cookies] = useCookies([COOKIE_KEY.ACCESS_TOKEN]);

if (!cookies[COOKIE_KEY.ACCESS_TOKEN]) {
return <Navigate to={redirectPath} replace />;
}

return <Outlet />;
}

export function UnProtectedRoute({ redirectPath = "/lottery" }: RouteProps) {
const [cookies] = useCookies([COOKIE_KEY.ACCESS_TOKEN]);

if (cookies[COOKIE_KEY.ACCESS_TOKEN]) {
return <Navigate to={redirectPath} replace />;
}

return <Outlet />;
}
Loading

0 comments on commit b93bbbb

Please sign in to comment.