-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathEntryControlMenu.tsx
159 lines (154 loc) · 4.04 KB
/
EntryControlMenu.tsx
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
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import {
Box,
ListItemIcon,
ListItemText,
Menu,
MenuItem,
Typography,
} from "@mui/material";
import { useSnackbar } from "notistack";
import React, { FC } from "react";
import { Link, useHistory } from "react-router-dom";
import {
entryEditPath,
aclPath,
showEntryHistoryPath,
copyEntryPath,
entityEntriesPath,
topPath,
entryDetailsPath,
aclHistoryPath,
} from "Routes";
import { Confirmable } from "components/common/Confirmable";
import { aironeApiClient } from "repository/AironeApiClient";
interface EntryControlProps {
entityId: number;
entryId: number;
anchorElem: HTMLButtonElement | null;
handleClose: (entryId: number) => void;
setToggle?: () => void;
disableChangeHistory?: boolean;
customDetailPath?: string;
customEditPath?: string;
customCopyPath?: string;
customACLPath?: string;
customHistoryPath?: string;
customACLHistoryPath?: string;
}
export const EntryControlMenu: FC<EntryControlProps> = ({
entityId,
entryId,
anchorElem,
handleClose,
setToggle,
disableChangeHistory = false,
customDetailPath,
customEditPath,
customCopyPath,
customACLPath,
customHistoryPath,
customACLHistoryPath,
}) => {
const { enqueueSnackbar } = useSnackbar();
const history = useHistory();
const handleDelete = async (entryId: number) => {
try {
await aironeApiClient.destroyEntry(entryId);
enqueueSnackbar("アイテムの削除が完了しました", {
variant: "success",
});
setToggle && setToggle();
history.replace(topPath());
history.replace(entityEntriesPath(entityId));
} catch (e) {
enqueueSnackbar("アイテムの削除が失敗しました", {
variant: "error",
});
}
};
return (
<Menu
id={`entryControlMenu-${entryId}`}
open={Boolean(anchorElem)}
onClose={() => handleClose(entryId)}
anchorEl={anchorElem}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
transformOrigin={{
vertical: "top",
horizontal: "right",
}}
>
<Box sx={{ width: 150 }}>
<MenuItem
component={Link}
to={
customDetailPath
? customDetailPath
: entryDetailsPath(entityId, entryId)
}
>
<Typography>詳細</Typography>
</MenuItem>
<MenuItem
component={Link}
to={
customEditPath ? customEditPath : entryEditPath(entityId, entryId)
}
>
<Typography>編集</Typography>
</MenuItem>
<MenuItem
component={Link}
to={
customCopyPath ? customCopyPath : copyEntryPath(entityId, entryId)
}
>
<Typography>コピー</Typography>
</MenuItem>
<MenuItem
component={Link}
to={customACLPath ? customACLPath : aclPath(entryId)}
>
<Typography>ACL 設定</Typography>
</MenuItem>
<MenuItem
component={Link}
to={
customHistoryPath
? customHistoryPath
: showEntryHistoryPath(entityId, entryId)
}
disabled={disableChangeHistory}
>
<Typography>変更履歴</Typography>
</MenuItem>
<MenuItem
component={Link}
to={
customACLHistoryPath
? customACLHistoryPath
: aclHistoryPath(entryId)
}
>
<Typography>ACL 変更履歴</Typography>
</MenuItem>
<Confirmable
componentGenerator={(handleOpen) => (
<MenuItem onClick={handleOpen} sx={{ justifyContent: "end" }}>
<ListItemText>削除</ListItemText>
<ListItemIcon>
<DeleteOutlineIcon />
</ListItemIcon>
</MenuItem>
)}
dialogTitle="本当に削除しますか?"
onClickYes={() => handleDelete(entryId)}
/>
</Box>
</Menu>
);
};