Skip to content

Commit

Permalink
[chore] 린트 수정 및 프리티어 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
lybell-art committed Aug 14, 2024
1 parent 3656f2f commit 8369277
Show file tree
Hide file tree
Showing 27 changed files with 498 additions and 350 deletions.
6 changes: 1 addition & 5 deletions src/adminPage/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ function App() {
<>
<Routes>
<Route element={<ProtectedRoute />}>
<Route
exact
path="/events/create"
element={<EventsCreatePage />}
/>
<Route exact path="/events/create" element={<EventsCreatePage />} />
<Route
exact
path="/events/:id/edit"
Expand Down
35 changes: 18 additions & 17 deletions src/adminPage/features/eventEdit/Container.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import Button from "@common/components/Button.jsx";

function EventEditContainer({title, children})
{
return <section className="flex flex-col gap-8">
<div className="flex w-full justify-between">
<div>
<h2 className="text-title-m font-bold">{title}</h2>
<p className="text-detail-l">*는 필수 입력</p>
</div>
<div>
<Button>임시저장 불러오기</Button>
<Button>임시저장</Button>
<Button>등록</Button>
</div>
</div>
{children}
</section>
function EventEditContainer({ title, children }) {
return (
<section className="flex flex-col gap-8">
<div className="flex w-full justify-between">
<div>
<h2 className="text-title-m font-bold">{title}</h2>
<p className="text-detail-l">*는 필수 입력</p>
</div>
<div>
<Button>임시저장 불러오기</Button>
<Button>임시저장</Button>
<Button>등록</Button>
</div>
</div>
{children}
</section>
);
}

export default EventEditContainer;
export default EventEditContainer;
38 changes: 21 additions & 17 deletions src/adminPage/features/eventEdit/index.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import Input from "@common/components/Input.jsx";

function EventEditor({defaultValue})
{
return <div>
<label>
<span>이벤트 명<sup>*</sup></span>
<Input />
</label>
<label>
<span>이벤트 ID</span>
<span>(대충 이벤트 id 들어감)</span>
</label>
<div>
<span>이벤트 기간<sup>*</sup></span>

</div>
</div>
function EventEditor() {
return (
<div>
<label>
<span>
이벤트 명<sup>*</sup>
</span>
<Input />
</label>
<label>
<span>이벤트 ID</span>
<span>(대충 이벤트 id 들어감)</span>
</label>
<div>
<span>
이벤트 기간<sup>*</sup>
</span>
</div>
</div>
);
}

export default EventEditor;
export default EventEditor;
73 changes: 45 additions & 28 deletions src/adminPage/features/eventList/DeleteButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,51 @@ import AlertModal from "@admin/modals/AlertModal.jsx";
import Button from "@common/components/Button.jsx";
import openModal from "@common/modal/openModal.js";

function DeleteButton({selected, reset})
{
const mutate = useMutation(
"admin-event-list",
()=>fetchServer("/api/v1/admin/events", {
method: "delete",
body: {
eventIds: [...selected]
}
}),
{
onSuccess: ()=>{
openModal(<AlertModal title="삭제" description="기대평이 삭제되었습니다." />);
reset();
}
}
);
const deleteConfirmModal = <ConfirmModal title="삭제" description={<>
<span>이 동작은 다시 돌이킬 수 없습니다.</span>
<br/>
<span>{selected.keys().next().value}{selected.size > 1 && ` 외 ${selected.size - 1} 개의`} 이벤트를 삭제하시겠습니까?</span>
</>} onConfirm={mutate} />;
function DeleteButton({ selected, reset }) {
const mutate = useMutation(
"admin-event-list",
() =>
fetchServer("/api/v1/admin/events", {
method: "delete",
body: {
eventIds: [...selected],
},
}),
{
onSuccess: () => {
openModal(
<AlertModal title="삭제" description="기대평이 삭제되었습니다." />,
);
reset();
},
},
);
const deleteConfirmModal = (
<ConfirmModal
title="삭제"
description={
<>
<span>이 동작은 다시 돌이킬 수 없습니다.</span>
<br />
<span>
{selected.keys().next().value}
{selected.size > 1 && ` 외 ${selected.size - 1} 개의`} 이벤트를
삭제하시겠습니까?
</span>
</>
}
onConfirm={mutate}
/>
);

function onClick()
{
openModal(deleteConfirmModal);
}
return <Button onClick={onClick} disabled={ selected.size === 0 }>삭제</Button>
function onClick() {
openModal(deleteConfirmModal);
}
return (
<Button onClick={onClick} disabled={selected.size === 0}>
삭제
</Button>
);
}

export default DeleteButton;
export default DeleteButton;
30 changes: 16 additions & 14 deletions src/adminPage/features/eventList/checkReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ function checkReducer(state, action) {
switch (action.type) {
case "reset":
return new Set();
case "check_key":{
const newSet = new Set(state);
if(action.value === true) newSet.add(action.key);
else if(action.value === false) newSet.delete(action.key);
else if(state.has(action.key)) newSet.delete(action.key);
else newSet.add(action.key);
return newSet;}
case "toggle_keys":{
const newSet = new Set(state);
let allFalse = action.keys.every( key=>state.has(key) === false );
if(allFalse) action.keys.forEach( key=>newSet.add(key) );
else action.keys.forEach( key=>newSet.delete(key) );
return newSet;}
case "check_key": {
const newSet = new Set(state);
if (action.value === true) newSet.add(action.key);
else if (action.value === false) newSet.delete(action.key);
else if (state.has(action.key)) newSet.delete(action.key);
else newSet.add(action.key);
return newSet;
}
case "toggle_keys": {
const newSet = new Set(state);
let allFalse = action.keys.every((key) => state.has(key) === false);
if (allFalse) action.keys.forEach((key) => newSet.add(key));
else action.keys.forEach((key) => newSet.delete(key));
return newSet;
}
}
throw Error("unknown action.");
}

export default checkReducer;
export default checkReducer;
30 changes: 22 additions & 8 deletions src/adminPage/features/eventList/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useReducer, useDeferredValue } from "react";
import { Link } from "react-router-dom";

import { searchReducer, setDefaultState, searchStateToQuery } from "./queryReducer.js";
import {
searchReducer,
setDefaultState,
searchStateToQuery,
} from "./queryReducer.js";
import checkReducer from "./checkReducer.js";

import SearchBar from "./SearchBar.jsx";
Expand All @@ -16,24 +20,34 @@ function EventList() {
const [state, dispatch] = useReducer(searchReducer, null, setDefaultState);
const [checkSet, setCheck] = useReducer(checkReducer, new Set());
const query = useDeferredValue(searchStateToQuery(state));
const resetCheck = ()=>setCheck({type:"reset"});
const resetCheck = () => setCheck({ type: "reset" });

return (
<div className="w-full h-full flex flex-col gap-4">
<div className="flex justify-end">
<Link to="./create"><Button>+ 이벤트 등록</Button></Link>
<Link to="./create">
<Button>+ 이벤트 등록</Button>
</Link>
</div>
<SearchBar onSearch={ (value)=>{
dispatch({type:"set_query", value});
resetCheck();
} } />
<SearchBar
onSearch={(value) => {
dispatch({ type: "set_query", value });
resetCheck();
}}
/>
<Filter state={state.filter} dispatch={dispatch} />
<div className="flex justify-end">
<DeleteButton selected={checkSet} reset={resetCheck} />
</div>
<ErrorBoundary fallback={<div>Error</div>}>
<Suspense fallback={<div>login</div>}>
<SearchResult query={query} queryState={state} queryDispatch={dispatch} checkState={checkSet} checkDispatch={setCheck} />
<SearchResult
query={query}
queryState={state}
queryDispatch={dispatch}
checkState={checkSet}
checkDispatch={setCheck}
/>
</Suspense>
</ErrorBoundary>
</div>
Expand Down
Loading

0 comments on commit 8369277

Please sign in to comment.