-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import "../../polyfill.ts";
import { isMessage } from "@bufbuild/protobuf";
import { Button, Code, Container, Flex, Spinner, Text } from "@radix-ui/themes";
import { NotFoundSchema } from "@yamori/proto/yamori/error/v1/not_found_pb.js";
import { GetRequestSchema } from "@yamori/proto/yamori/workspace/v1/get_request_pb.js";
import { GetResponseSchema } from "@yamori/proto/yamori/workspace/v1/get_response_pb.js";
import { WorkspaceSchema } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js";
import { type FC } from "react";
import * as Empty from "../../components/Empty.ts";
import { ManagedErrorCallout } from "../../components/ErrorCallout.ts";
import { Select, useURLPatternResult } from "../../contexts/Router.tsx";
import { useMethodQuery } from "../../contexts/Service.tsx";
import { IllegalMessageError } from "../../errors/IllegalMessageError.ts";
import * as workers from "./workers/page.tsx";
import * as workersNew from "./workers/new/page.tsx";
import * as workerSubRoute from "./workers/:id/page.tsx";
import * as leaveDefinitions from "./leave-definitions/page.tsx";
import * as leaveDefinitionsNew from "./leave-definitions/new/page.tsx";
import { Layout } from "./Layout.tsx";
export const Page: FC = () => {
const { pathname } = useURLPatternResult();
const workspaceIdRaw = pathname.groups.workspace!;
const query = useMethodQuery({
service: "yamori.workspace.v1.WorkspaceService",
method: "Get",
request: {
schema: GetRequestSchema,
data: {
workspaceId: { value: workspaceIdRaw },
readMask: {
fields: [
WorkspaceSchema.field.id.number,
WorkspaceSchema.field.displayName.number,
WorkspaceSchema.field.workerAddKey.number,
WorkspaceSchema.field.createLeaveDefinitionKey.number,
],
},
},
},
response: {
schema: GetResponseSchema,
},
mapResponse(resp) {
switch (resp.result.case) {
case "ok":
return resp.result.value;
case undefined:
throw new IllegalMessageError(resp);
default:
throw resp.result.value;
}
},
});
if (query.isError) {
if (isMessage(query.error, NotFoundSchema)) {
return (
<Container p="3" size="2">
<Empty.Root>
<Empty.Title>ワークスペースが見つかりません</Empty.Title>
<Empty.Description>
ID が <Code>{workspaceIdRaw}</Code> のワークスペースが見つかりませんでした。
対象のワークスペースが既に削除されたか、打ち間違いや削除などにより ID
が不完全の可能性があります。
</Empty.Description>
<Empty.Actions>
<Button asChild size="3">
<a href="/">選択画面へ</a>
</Button>
</Empty.Actions>
</Empty.Root>
</Container>
);
}
return (
<Container p="3" size="2">
<Empty.Root>
<Empty.Title>ワークスペースの取得に失敗</Empty.Title>
<Empty.Description>
ワークスペースを読み込もうとしましたが、データ取得に失敗しました。
</Empty.Description>
<ManagedErrorCallout title="取得失敗" error={query.error} />
<Empty.Actions>
<Button size="3" onClick={() => void query.refetch()}>
再取得
</Button>
<Button asChild size="3" variant="outline">
<a href="/">選択画面へ戻る</a>
</Button>
</Empty.Actions>
</Empty.Root>
</Container>
);
}
if (!query.data) {
return (
<Flex position="absolute" inset="0" align="center" justify="center" gap="2">
<Spinner />
<Text size="2" color="gray">
ワークスペースを読込中...
</Text>
</Flex>
);
}
const workspace = query.data;
return (
<Select
routes={[
{
pattern: workers.pattern,
children: <workers.Page workspace={workspace} />,
},
{
pattern: workersNew.pattern,
children: <workersNew.Page workspace={workspace} />,
},
{
pattern: leaveDefinitions.pattern,
children: <leaveDefinitions.Page workspace={workspace} />,
},
{
pattern: leaveDefinitionsNew.pattern,
children: <leaveDefinitionsNew.Page workspace={workspace} />,
},
{
pattern: workerSubRoute.pattern,
children: <workerSubRoute.Page workspace={workspace} />,
},
]}
fallback={
<Layout title="404" workspace={workspace}>
<Empty.Root>
<Empty.Title>ページが見つかりません</Empty.Title>
<Empty.Description>指定された URL にページはありません。</Empty.Description>
<Empty.Actions>
<Button asChild size="3">
<a href={`/${workspace.id?.value}/workers`}>労働者一覧へ</a>
</Button>
</Empty.Actions>
</Empty.Root>
</Layout>
}
/>
);
};
export const pattern = new URLPattern({
pathname: "/:workspace(ws-[^\\/]+)/:frag*",
});