Skip to content

Commit

Permalink
[chore] 린트 수정 및 프리티어 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
lybell-art committed Aug 23, 2024
1 parent ef64cfc commit a74a92f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
119 changes: 63 additions & 56 deletions packages/adminPage/src/features/eventDetail/drawButton/DrawButton.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef } from "react";
import { useParams } from "react-router-dom";
import { fetchServer } from "@common/dataFetch/fetchServer.js";

Expand All @@ -12,23 +12,24 @@ import Suspense from "@common/components/Suspense.jsx";
import Spinner from "@common/components/Spinner.jsx";
import DelaySkeleton from "@common/components/DelaySkeleton.jsx";

function ResultModalContainer({eventId})
{
return <div className="w-[calc(100vw-8rem)] h-[calc(100vh-8rem)] p-8 bg-white relative">
<ErrorBoundary fallback={<div>에러남</div>}>
<Suspense
fallback={
<div className="w-full h-full flex justify-center items-center">
<DelaySkeleton>
<Spinner />
</DelaySkeleton>
</div>
}
>
<DrawResultModal eventId={eventId} />
</Suspense>
</ErrorBoundary>
</div>
function ResultModalContainer({ eventId }) {
return (
<div className="w-[calc(100vw-8rem)] h-[calc(100vh-8rem)] p-8 bg-white relative">
<ErrorBoundary fallback={<div>에러남</div>}>
<Suspense
fallback={
<div className="w-full h-full flex justify-center items-center">
<DelaySkeleton>
<Spinner />
</DelaySkeleton>
</div>
}
>
<DrawResultModal eventId={eventId} />
</Suspense>
</ErrorBoundary>
</div>
);
}

function DrawButton() {
Expand All @@ -37,67 +38,73 @@ function DrawButton() {
const interval = useRef(null);
const timeout = useRef(null);

useEffect( ()=>{
useEffect(() => {
fetchServer(`/api/v1/admin/draw/${eventId}/status`)
.then( ({status})=>setDrawState(status) )
.catch( (e)=>{
.then(({ status }) => setDrawState(status))
.catch(() => {
setDrawState("ERROR");
} );
}, [] );
});
}, [eventId]);

useEffect( ()=>{
return ()=>{
useEffect(() => {
return () => {
clearInterval(interval.current);
clearTimeout(timeout.current);
}
}, [] );
};
}, []);

async function onSubmit()
{
function shortPooling()
{
async function onSubmit() {
function shortPooling() {
fetchServer(`/api/v1/admin/draw/${eventId}/status`)
.then( ({status})=>{
.then(({ status }) => {
setDrawState(status);
if(status !== "IS_DRAWING") {
if (status !== "IS_DRAWING") {
clearInterval(interval.current);
}
} )
.catch( (e)=>{
})
.catch(() => {
setDrawState("ERROR");
clearInterval(interval.current);
} );
});
}

try {
await fetchServer(`/api/v1/admin/draw/${eventId}/draw`, { method: "post" });
setDrawState("IS_DRAWING");
openModal(<AlertModal title="성공" description="성공적으로 추첨 요청이 전송되었습니다." />);
timeout.current = setTimeout( ()=>{
timeout.current = setTimeout(() => {
shortPooling();
interval.current = setInterval( shortPooling, 5000 );
}, 500 );
}
catch {
interval.current = setInterval(shortPooling, 5000);
}, 500);
} catch {
openModal(<AlertModal title="오류" description="추첨에 오류가 발생했습니다." />);
}
}

switch(drawState)
{
case "BEFORE_END": return null;
case "AVAILABLE": return (
<Button className="w-32 h-8 px-4 py-1" onClick={onSubmit}>
추첨하기
</Button>
);
case "IS_DRAWING": return <div className="w-32 h-8 px-4 py-1 bg-neutral-600 text-neutral-400">추첨 진행중...</div>;
case "COMPLETE": return (
<Button className="w-32 h-8 px-4 py-1" onClick={() => openModal(<ResultModalContainer eventId={eventId} />)}>
결과 보기
</Button>
);
default: return <div className="w-32 h-8 px-4 py-1 bg-neutral-600 text-neutral-400">에러</div>;
switch (drawState) {
case "BEFORE_END":
return null;
case "AVAILABLE":
return (
<Button className="w-32 h-8 px-4 py-1" onClick={onSubmit}>
추첨하기
</Button>
);
case "IS_DRAWING":
return (
<div className="w-32 h-8 px-4 py-1 bg-neutral-600 text-neutral-400">추첨 진행중...</div>
);
case "COMPLETE":
return (
<Button
className="w-32 h-8 px-4 py-1"
onClick={() => openModal(<ResultModalContainer eventId={eventId} />)}
>
결과 보기
</Button>
);
default:
return <div className="w-32 h-8 px-4 py-1 bg-neutral-600 text-neutral-400">에러</div>;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const handlers = [
http.post("/api/v1/admin/draw/:eventId/draw", () => {
result = makeDrawComplete();
status = "IS_DRAWING";
setTimeout( ()=>status = "COMPLETE", 3000 );
setTimeout(() => (status = "COMPLETE"), 3000);
return new HttpResponse(null, { status: 201 });
}),
http.get("/api/v1/admin/draw/:eventId/winners", () => {
return HttpResponse.json(result);
}),
http.get("/api/v1/admin/draw/:eventId/status", () => {
return HttpResponse.json({status});
return HttpResponse.json({ status });
}),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ function SearchResultItem({ eventId, name, startTime, endTime, eventType, checke
<div className="flex justify-center items-center">
{eventType === "fcfs" ? "선착순" : eventType === "draw" ? "추첨" : "???"}
</div>
<div className="flex justify-center items-center">
{eventStatus}
</div>
<div className="flex justify-center items-center">{eventStatus}</div>
<div className="flex justify-center items-center">
<Link to={`./${eventId}`}>
<Button styleType="ghost" className="px-2 py-1 text-body-s">
Expand Down
2 changes: 1 addition & 1 deletion packages/common/sharedAssetRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function sharedAssetRouter(paths) {
if (originPath === null) return next();
const filePath = join(__dirname, originPath);

if(!existsSync(filePath)) return next();
if (!existsSync(filePath)) return next();

const stream = createReadStream(filePath);
stream.on("error", (err) => {
Expand Down

0 comments on commit a74a92f

Please sign in to comment.