-
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
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import "../../../polyfill.ts";
import { Button, Flex, Separator, Spinner, Text } from "@radix-ui/themes";
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,
type Workspace,
} from "@yamori/proto/yamori/workspace/v1/workspace_pb.js";
import { type FC, Fragment } from "react";
import * as Empty from "../../../components/Empty.ts";
import { ManagedErrorCallout } from "../../../components/ErrorCallout.ts";
import * as HelpDialog from "../../../components/HelpDialog.ts";
import { useMethodQuery } from "../../../contexts/Service.tsx";
import { IllegalMessageError } from "../../../errors/IllegalMessageError.ts";
import { Layout } from "../Layout.tsx";
import { ListItem } from "./ListItem.tsx";
interface BodyProps {
workspace: Workspace;
}
const Body: FC<BodyProps> = ({ workspace: { id } }) => {
const definitions = useMethodQuery({
service: "yamori.workspace.v1.WorkspaceService",
method: "Get",
request: {
schema: GetRequestSchema,
data: {
workspaceId: id,
readMask: {
fields: [WorkspaceSchema.field.leaveDefinitions.number],
},
},
},
response: {
schema: GetResponseSchema,
},
mapResponse(resp) {
switch (resp.result.case) {
case "ok":
return resp.result.value.leaveDefinitions;
case undefined:
throw new IllegalMessageError(resp);
default:
throw resp.result.value;
}
},
});
if (definitions.data?.length === 0 && !definitions.isError) {
return (
<Empty.Root>
<Empty.Title>データがありません</Empty.Title>
<Empty.Description>
このワークスペースには休暇・休業が一つも登録されていません。
</Empty.Description>
</Empty.Root>
);
}
return (
<Flex direction="column" mt="5" gap="5">
{!!definitions.error && (
<ManagedErrorCallout
severity={definitions.data ? "warning" : "danger"}
title={
definitions.data ? "一覧の更新に失敗しました" : "一覧の取得に失敗しました"
}
error={definitions.error}
actions={
<Button
size="1"
loading={definitions.isFetching}
onClick={() => void definitions.refetch()}
>
{definitions.data ? "再試行" : "再取得"}
</Button>
}
/>
)}
{!definitions.data ? (
<Flex mt="5" justify="center" align="center" gap="2">
{definitions.isError ? (
<Text size="2" color="gray">
取得エラー
</Text>
) : (
<>
<Spinner />
<Text size="2" color="gray">
一覧を取得中...
</Text>
</>
)}
</Flex>
) : (
<Flex direction="column" gap="4" role="list">
{definitions.data.map((def, i) => (
<Fragment key={def.id?.value}>
{i > 0 && <Separator size="4" />}
<ListItem leaveDefinition={def} pageTitle={<Title />} />
</Fragment>
))}
</Flex>
)}
</Flex>
);
};
export const Title: FC = () => "休暇・休業種別一覧";
export interface PageProps {
workspace: Workspace;
}
export const Page: FC<PageProps> = ({ workspace }) => {
return (
<HelpDialog.Root>
<Layout
workspace={workspace}
title={
<Flex as="span" align="center" gap="2">
<Title />
<HelpDialog.Trigger>このページの説明</HelpDialog.Trigger>
</Flex>
}
>
<Body workspace={workspace} />
</Layout>
<HelpDialog.Content>
<HelpDialog.Title>
<Title />
</HelpDialog.Title>
<HelpDialog.Description>
このワークスペース内で利用可能な休暇と休業の一覧です。
</HelpDialog.Description>
<HelpDialog.Paragraph>
労働者の勤怠記録をつける際は、この一覧にある項目から選ぶことができます。
労働者やグループの設定ページで「休暇休業の絞り込み」が設定されている場合は、絞り込まれた項目の中からのみ選ぶことができます。
</HelpDialog.Paragraph>
</HelpDialog.Content>
</HelpDialog.Root>
);
};
export const pattern = new URLPattern({
pathname: "/:workspace/leave-definitions",
});