Skip to content

Commit

Permalink
add AdminEventStatus page but not done
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonc01 committed Aug 14, 2024
1 parent 41e34c3 commit 184a267
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 1 deletion.
2 changes: 1 addition & 1 deletion admin/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import AdminEventStatus from './pages/AdminEventStatus/AdminEventStatus';
import AdminEventStatus from '@/pages/AdminEventStatus/AdminEventStatus';

function App() {
return (
Expand Down
8 changes: 8 additions & 0 deletions admin/src/pages/AdminEventStatus/AdminEventStatus.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React, { useEffect } from 'react';
import TableComponent from '@/pages/AdminEventStatus/TableComponent';

function AdminEventStatus() {
return <TableComponent />;
}

export default AdminEventStatus;
25 changes: 25 additions & 0 deletions admin/src/pages/AdminEventStatus/RadioButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';

function RadioButton({ value, rowsPerPage, onChange }) {
return (
<label className="flex items-center gap-2">
<input
type="radio"
value={value}
checked={rowsPerPage === value}
onChange={onChange}
className="w-[20px] h-[20px]"
/>
{value}개씩 보기
</label>
);
}

RadioButton.propTypes = {
value: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
};

export default RadioButton;
130 changes: 130 additions & 0 deletions admin/src/pages/AdminEventStatus/TableComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, { useState, useEffect } from 'react';
import TableRow from '@/pages/AdminEventStatus/TableRow';
import RadioButton from '@/pages/AdminEventStatus/RadioButton';

const TableComponent = () => {
const [rowsPerPage, setRowsPerPage] = useState(10);
const [totalRows, setTotalRows] = useState(-1);
const [currentPage, setCurrentPage] = useState(1);
const [pageData, setPageData] = useState([
{ id: 1, phoneNumber: '10', time: 's', result: '1' },
{ id: 2, phoneNumber: '10', time: 's', result: '1' },
{ id: 3, phoneNumber: '10', time: 's', result: '1' },
{ id: 4, phoneNumber: '10', time: 's', result: '1' },
{ id: 5, phoneNumber: '10', time: 's', result: '1' },
{ id: 6, phoneNumber: '10', time: 's', result: '1' },
{ id: 7, phoneNumber: '10', time: 's', result: '1' },
{ id: 8, phoneNumber: '10', time: 's', result: '1' },
]);

useEffect(() => {
getCurrentPageData(currentPage);
}, [rowsPerPage, currentPage]);

useEffect(() => {
setTotalRows(156); //TODO API 통신으로 가져오기 및 데이터를 가져오기
}, []);

const totalPages = Math.ceil(totalRows / rowsPerPage);
const startPage = Math.floor((currentPage - 1) / 10) * 10 + 1;
const endPage = Math.min(startPage + 9, totalPages);

const handleRowsPerPageChange = event => {
setRowsPerPage(Number(event.target.value));
setCurrentPage(1);
};

const handlePageChange = newPage => {
setCurrentPage(newPage);
};

const getCurrentPageData = currentPage => {
// try{
// const data //API 통신
// }
//setPageData(data); // data의 정보 array 가져오기
};

return (
<div className="flex flex-col text-nowrap w-[90%]">
<div className="h-screen">
<div className="flex justify-between py-400">
<div className="text-body-3-regular">전체 {totalRows}</div>
<div className="flex gap-6">
<RadioButton
value={10}
rowsPerPage={rowsPerPage}
onChange={handleRowsPerPageChange}
/>
<RadioButton
value={30}
rowsPerPage={rowsPerPage}
onChange={handleRowsPerPageChange}
/>
<RadioButton
value={50}
rowsPerPage={rowsPerPage}
onChange={handleRowsPerPageChange}
/>
</div>
</div>
<div className="flex">
<div className="set-center w-[275px] border border-black">순번</div>
<div className="flex-1 border border-black set-center">전화번호</div>
<div className="flex-1 border border-black set-center">응모 시간</div>
<div className="flex-1 border border-black set-center">응모 결과</div>
</div>
{pageData.map(item => (
<TableRow
id={item.id}
phoneNumber={item.phoneNumber}
time={item.time}
result={item.result}
key={item.id}
/>
))}
<div className="flex justify-center gap-2 mt-10">
<button
onClick={() => handlePageChange(Math.max(1, currentPage - 10))}
disabled={1 === currentPage}
>
&laquo; {/* << 기호 */}
</button>
<button
onClick={() => handlePageChange(currentPage - 1)}
disabled={currentPage === 1}
>
&lt;
</button>
{Array.from({ length: endPage - startPage + 1 }).map((_, index) => (
<button
key={index}
onClick={() => handlePageChange(startPage + index)}
className={`${
currentPage === startPage + index ? 'font-bold' : 'font-normal'
}`}
>
{startPage + index}
</button>
))}
<button
onClick={() => handlePageChange(currentPage + 1)}
disabled={currentPage === 1}
>
&gt;
</button>
<button
onClick={() =>
handlePageChange(Math.min(totalPages, currentPage + 10))
}
disabled={currentPage === totalPages}
>
&raquo; {/* >> 기호 */}
</button>
</div>
</div>
</div>
);
};

export default TableComponent;
23 changes: 23 additions & 0 deletions admin/src/pages/AdminEventStatus/TableRow.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import '@/styles/global.css';

function TableRow({ id, phoneNumber, time, result }) {
return (
<div className="flex bg-neutral-white h-[50px]">
<div className="set-center w-[275px] border border-black">{id}</div>
<div className="flex-1 border border-black set-center">{phoneNumber}</div>
<div className="flex-1 border border-black set-center">{time}</div>
<div className="flex-1 border border-black set-center">{result}</div>
</div>
);
}

TableRow.propTypes = {
id: PropTypes.number.isRequired,
phoneNumber: PropTypes.string.isRequired,
time: PropTypes.string.isRequired,
result: PropTypes.string.isRequired,
};

export default TableRow;
7 changes: 7 additions & 0 deletions admin/src/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.set-center {
@apply flex items-center justify-center;
}

0 comments on commit 184a267

Please sign in to comment.