Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

テーブル機能を実装 #6

Merged
merged 12 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Header />
<Component {...pageProps} />;
<Component {...pageProps} />
</>
);
}
244 changes: 173 additions & 71 deletions pages/users.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,189 @@
import { queryDb } from "@/util/db";
import { GetServerSideProps } from "next";
import { useState } from "react";
import { Table } from "react-bootstrap";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Form from "react-bootstrap/Form";
import Table from "react-bootstrap/Table";
import { User } from "./api/user";

type Props = {
users: User[];
};

type TableDataType = "id" | "icon" | "discord";
const allTableDataTypes: TableDataType[] = ["id", "icon", "discord"];
{
/* あとでオブジェクトのリストに書き換えます */
MogamiTsuchikawa marked this conversation as resolved.
Show resolved Hide resolved
}
type TableDataType = "公開情報" | "有効期限・ID" | "個人情報" | "保護者情報";

const allTableDataTypes: TableDataType[] = [
"公開情報",
"有効期限・ID",
"個人情報",
"保護者情報",
];

const defaultTableDataTypes: TableDataType[] = ["公開情報", "有効期限・ID"];

const kanjiNameStyle = {
width: "100px",
MogamiTsuchikawa marked this conversation as resolved.
Show resolved Hide resolved
};

const kanaNameStyle = {
width: "125px",
};

const phoneNumberStyle = {
width: "115px",
};

const addressStyle = {
width: "200px",
};

const UsersPage = ({ users }: Props) => {
const [selectTypes, setSelectTypes] = useState<TableDataType[]>([]);
const [selectTypes, setSelectTypes] = useState<TableDataType[]>([
...defaultTableDataTypes,
]);
const onCheckFilter = (checked: boolean, type: TableDataType) => {
if (checked) setSelectTypes([...selectTypes, type]);
else setSelectTypes(selectTypes.filter(t => t !== type));
}
else setSelectTypes(selectTypes.filter((t) => t !== type));
};
return (
<div style={{ width: "100%" }} className="overflow-auto">
{allTableDataTypes.map(t => (
<>
<input type="checkbox" key={t} onChange={(e) => { onCheckFilter(e.target.checked, t) }} />
{t}
</>
))}
<Table striped bordered hover style={{ tableLayout: "fixed" }}>
<thead>
<tr>
{
// 幅は調整中。細かい調整は後ほど。
}
{selectTypes.indexOf("id") !== -1 ? <th style={{ width: 150 }}>ID</th> : <></>}

<th className="table-th-studentNumber">学籍番号</th>
<th className="table-th-username">ユーザー名</th>
<th style={{ width: 30 }}>学年</th>
<th style={{ width: 66 }}>アイコン</th>
<th style={{ width: 100 }}>Discord ID</th>
<th style={{ width: 100 }}>有効期限</th>
<th style={{ width: 150 }}>自己紹介</th>
<th className="table-th-name">名字</th>
<th className="table-th-name">名前</th>
<th className="table-th-name-kana">名字カナ</th>
<th className="table-th-name-kana">名前カナ</th>
<th style={{ width: 30 }}>性別</th>
<th className="table-th-phoneNumber">電話番号</th>
<th className="table-th-address">住所</th>
<th style={{ width: 100 }}>親氏名</th>
<th className="table-th-phoneNumber">親電話番号</th>
<th className="table-th-phoneNumber">親固定電話番号</th>
<th className="table-th-address">親住所</th>
</tr>
</thead>
<tbody>
{users.map((user) => (
<tr key={user.id}>
{selectTypes.indexOf("id") !== -1 ? <td>{user.id}</td> : <></>}

<td>{user.studentNumber}</td>
<td>{user.username}</td>
<td>{user.schoolGrade}</td>
<td>
<img src={user.iconUrl} alt="" style={{ width: "50px" }} />
</td>
<td>{user.discordUserId}</td>
<td>{user.activeLimit}</td>
<td>{user.shortIntroduction}</td>
<td>{user.firstName}</td>
<td>{user.lastName}</td>
<td>{user.firstNameKana}</td>
<td>{user.lastNameKana}</td>
<td>{user.isMale ? "男" : "女"}</td>
<td>{user.phoneNumber}</td>
<td>{user.address}</td>
<td>{user.parentName}</td>
<td>{user.parentCellphoneNumber}</td>
<td>{user.parentHomephoneNumber}</td>
<td>{user.parentAddress}</td>
</tr>
<Container fluid>
<Row>
<div className="p-2">
{allTableDataTypes.map((t) => (
<Form.Check
defaultChecked={defaultTableDataTypes.includes(t)}
inline
key={t}
label={t}
type="checkbox"
id={t}
onChange={(e) => {
onCheckFilter(e.target.checked, t);
}}
/>
))}
</tbody>
</Table>
</div>
</div>
</Row>
<Row>
<div className="overflow-auto">
<Table
striped
bordered
hover
style={{ tableLayout: "fixed", overflow: "auto" }}
>
<thead>
<tr>
{/* 幅は調整中。細かい調整は後ほど。*/}
<th style={{ width: 82 }}>学籍番号</th>
<th style={{ width: 125 }}>ユーザー名</th>
<th style={{ width: 30 }}>学年</th>
{selectTypes.indexOf("公開情報") !== -1 ? (
<>
<th style={{ width: 66 }}>アイコン</th>
<th style={{ width: 200 }}>自己紹介</th>
</>
) : (
<></>
)}
{selectTypes.indexOf("有効期限・ID") !== -1 ? (
<>
<th style={{ width: 100 }}>有効期限</th>
<th style={{ width: 150 }}>ID</th>
<th style={{ width: 100 }}>Discord ID</th>
</>
) : (
<></>
)}
{selectTypes.indexOf("個人情報") !== -1 ? (
<>
<th style={kanjiNameStyle}>名字</th>
<th style={kanjiNameStyle}>名前</th>
<th style={kanaNameStyle}>名字カナ</th>
<th style={kanaNameStyle}>名前カナ</th>
<th style={{ width: 30 }}>性別</th>
<th style={phoneNumberStyle}>電話番号</th>
<th style={addressStyle}>住所</th>
</>
) : (
<></>
)}
{selectTypes.indexOf("保護者情報") !== -1 ? (
<>
<th style={{ width: 100 }}>親氏名</th>
<th style={phoneNumberStyle}>親電話番号</th>
<th style={phoneNumberStyle}>親固定電話番号</th>
<th style={addressStyle}>親住所</th>
</>
) : (
<></>
)}
</tr>
</thead>
<tbody>
{users.map((user) => (
<tr key={user.id}>
<td>{user.studentNumber}</td>
<td>{user.username}</td>
<td>{user.schoolGrade}</td>
{selectTypes.indexOf("公開情報") !== -1 ? (
<>
<td>
<img
src={user.iconUrl}
alt=""
style={{ width: "50px" }}
/>
</td>
<td>{user.shortIntroduction}</td>
</>
) : (
<></>
)}
{selectTypes.indexOf("有効期限・ID") !== -1 ? (
<>
<td>{user.activeLimit}</td>
<td>{user.id}</td>
<td>{user.discordUserId}</td>
</>
) : (
<></>
)}
{selectTypes.indexOf("個人情報") !== -1 ? (
<>
<td>{user.firstName}</td>
<td>{user.lastName}</td>
<td>{user.firstNameKana}</td>
<td>{user.lastNameKana}</td>
<td>{user.isMale ? "男" : "女"}</td>
<td>{user.phoneNumber}</td>
<td>{user.address}</td>
</>
) : (
<></>
)}
{selectTypes.indexOf("保護者情報") !== -1 ? (
<>
<td>{user.parentName}</td>
<td>{user.parentCellphoneNumber}</td>
<td>{user.parentHomephoneNumber}</td>
<td>{user.parentAddress}</td>
</>
) : (
<></>
)}
</tr>
))}
</tbody>
</Table>
</div>
</Row>
</Container>
);
};

Expand Down Expand Up @@ -128,7 +230,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
schoolGrade: r.school_grade,
iconUrl: r.icon_url,
discordUserId: r.discord_userid,
activeLimit: r.active_limit.toString(),
activeLimit: r.active_limit.toLocaleString("ja-JP"),
shortIntroduction: r.short_introduction,
firstName: r.first_name,
lastName: r.last_name,
Expand Down
25 changes: 0 additions & 25 deletions styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

.table-th-studentNumber{
width: 75px;
}

.table-th-username{
width: 125px;
}

.table-th-name{
width: 100px;
}

.table-th-name-kana{
width: 125px;
}

.table-th-phoneNumber{
width: 115px;
}

.table-th-address{
width: 250px;
}
Loading