Skip to content

Commit 1fb12e0

Browse files
authored
検索画面から、リクエストを送れるようになった (#561)
# PRの概要 #494 ## 具体的な変更内容 <img width="381" alt="スクリーンショット 2024-12-28 19 11 19" src="https://github.com/user-attachments/assets/464162d3-5ca5-4f4b-b045-40c12826e5c6" /> ## 影響範囲 ## 動作要件 ## 補足 ## レビューリクエストを出す前にチェック! - [ ] 改めてセルフレビューしたか - [ ] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 -->
1 parent b30a52e commit 1fb12e0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

web/components/human/humanListItem.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type HumanListItemProps = {
1414
onAccept?: (id: number) => void;
1515
onReject?: (id: number) => void;
1616
onCancel?: (id: number) => void;
17+
onRequest?: (id: number) => void;
1718
hasDots?: boolean;
1819
dotsActions?: object;
1920
};
@@ -32,6 +33,7 @@ export function HumanListItem(props: HumanListItemProps) {
3233
onAccept,
3334
onReject,
3435
onCancel,
36+
onRequest,
3537
hasDots,
3638
} = props;
3739

@@ -70,7 +72,7 @@ export function HumanListItem(props: HumanListItemProps) {
7072
)}
7173
</div>
7274
</button>
73-
<div className="flex items-center space-x-2">
75+
<div className="mr-3 flex items-center space-x-2">
7476
{unreadCount ? (
7577
<span className="badge badge-primary">{unreadCount}</span>
7678
) : undefined}
@@ -107,6 +109,15 @@ export function HumanListItem(props: HumanListItemProps) {
107109
キャンセル
108110
</button>
109111
)}
112+
{onRequest && (
113+
// biome-ignore lint/a11y/useButtonType: <explanation>
114+
<button
115+
className="btn btn-sm bg-primary text-white"
116+
onClick={() => onRequest(id)}
117+
>
118+
リクエスト
119+
</button>
120+
)}
110121
{hasDots && (
111122
<Dots
112123
actions={[

web/components/search/table.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22
import { useMemo } from "react";
3-
import { useAll, useMyID } from "~/api/user";
3+
import request from "~/api/request";
4+
import { useAll, useMatched, useMyID, usePendingFromMe } from "~/api/user";
45
import { useModal } from "../common/modal/ModalProvider";
56
import { HumanListItem } from "../human/humanListItem";
67

@@ -21,6 +22,19 @@ export default function UserTable({ query }: { query: string }) {
2122
)
2223
: initialData;
2324

25+
const {
26+
state: { data: matches },
27+
} = useMatched();
28+
29+
const {
30+
state: { data: pending },
31+
} = usePendingFromMe();
32+
33+
// ユーザーがリクエストを送ってない人だけリストアップする
34+
const canRequest = (userId: number) =>
35+
!matches?.some((match) => match.id === userId) &&
36+
!pending?.some((pending) => pending.id === userId);
37+
2438
return (
2539
<div>
2640
{users?.map((user) => (
@@ -30,6 +44,14 @@ export default function UserTable({ query }: { query: string }) {
3044
name={user.name}
3145
pictureUrl={user.pictureUrl}
3246
onOpen={() => openModal(user)}
47+
onRequest={
48+
canRequest(user.id)
49+
? () => {
50+
request.send(user.id);
51+
location.reload();
52+
}
53+
: undefined
54+
}
3355
/>
3456
))}
3557
</div>

0 commit comments

Comments
 (0)