-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponents.tsx
More file actions
242 lines (228 loc) · 8.91 KB
/
components.tsx
File metadata and controls
242 lines (228 loc) · 8.91 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { Components } from "@frontend/common";
import { useBackendAdminClient, usePublicFileQuery } from "@frontend/common/src/hooks/useAdminAPI";
import { useCommonContext } from "@frontend/common/src/hooks/useCommonContext";
import {
Accordion,
AccordionDetails,
AccordionSummary,
Box,
Stack,
styled,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
TextFieldProps,
Typography,
} from "@mui/material";
import * as React from "react";
import * as R from "remeda";
type SharedPreviewFieldProps = {
originalDataset: Record<string, unknown>;
previewDataset: Record<string, unknown>;
name: string;
label: string;
};
type PreviewFieldProps = Omit<TextFieldProps, "value" | "name" | "label"> & SharedPreviewFieldProps;
const MarkdownContainerBox = styled(Box)(({ theme }) => ({
width: "100%",
color: "black",
"& .markdown-body": {
width: "100%",
p: { margin: theme.spacing(2, 0) },
a: { color: theme.palette.primary.main },
},
}));
export const PreviewTextField: React.FC<PreviewFieldProps> = ({ originalDataset, previewDataset, name, ...props }) => {
const textFieldSx: TextFieldProps["sx"] = {
"& .MuiInputBase-input, & .Mui-disabled": {
color: "black",
WebkitTextFillColor: "black",
"-webkit-text-fill-color": "black",
},
};
const textFieldProps: TextFieldProps = {
fullWidth: true,
disabled: true,
variant: "outlined",
value: previewDataset[name] || "(값 없음)",
sx: textFieldSx,
...props,
};
const modifiedTextFieldProps: TextFieldProps = { ...textFieldProps, sx: { ...textFieldSx, backgroundColor: "rgba(255, 255, 0, 0.1)" } };
const originalTextFieldProps: TextFieldProps = { ...textFieldProps, sx: { ...textFieldSx, backgroundColor: "rgba(0, 64, 64, 0.1)" } };
const isModified = originalDataset[name] !== previewDataset[name];
return originalDataset[name] === previewDataset[name] ? (
<TextField {...textFieldProps} sx={{ ...textFieldSx, my: 1 }} />
) : (
<Box sx={{ my: 1 }}>
<Accordion>
<AccordionSummary>
<Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between">
<TextField {...(isModified ? modifiedTextFieldProps : textFieldProps)} />
<Typography variant="caption">기존 값을 보려면 여기를 클릭해주세요.</Typography>
</Stack>
</AccordionSummary>
<AccordionDetails>
<TextField {...originalTextFieldProps} value={originalDataset[name] || "(값 없음)"} />
</AccordionDetails>
</Accordion>
</Box>
);
};
export const PreviewMarkdownField: React.FC<SharedPreviewFieldProps> = ({ originalDataset, previewDataset, name, label }) => {
const { baseUrl, mdxComponents } = useCommonContext();
return originalDataset[name] === previewDataset[name] ? (
<Components.Fieldset legend={label} style={{ width: "100%" }}>
<MarkdownContainerBox>
<Components.MDXRenderer format="md" text={(previewDataset[name] as string) || "(값 없음)"} baseUrl={baseUrl} mdxComponents={mdxComponents} />
</MarkdownContainerBox>
</Components.Fieldset>
) : (
<Box sx={{ my: 1 }}>
<Accordion>
<AccordionSummary>
<Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between">
<Components.Fieldset legend={label} style={{ width: "100%", backgroundColor: "rgba(255, 255, 0, 0.1)" }}>
<MarkdownContainerBox>
<Components.MDXRenderer
format="md"
text={(previewDataset[name] as string) || "(값 없음)"}
baseUrl={baseUrl}
mdxComponents={mdxComponents}
/>
</MarkdownContainerBox>
</Components.Fieldset>
<Typography variant="caption">기존 값을 보려면 여기를 클릭해주세요.</Typography>
</Stack>
</AccordionSummary>
<AccordionDetails>
<Components.Fieldset legend={label} style={{ backgroundColor: "rgba(0, 64, 64, 0.1)" }}>
<MarkdownContainerBox>
<Components.MDXRenderer
format="md"
text={(originalDataset[name] as string) || "(값 없음)"}
baseUrl={baseUrl}
mdxComponents={mdxComponents}
/>
</MarkdownContainerBox>
</Components.Fieldset>
</AccordionDetails>
</Accordion>
</Box>
);
};
const ImageFallback: React.FC = () => (
<Stack sx={{ width: "100%", height: "100%", alignItems: "center", justifyContent: "center" }}>
<Typography variant="caption" color="textSecondary" children="이미지를 불러오는 중 문제가 발생했습니다." />
</Stack>
);
const WidthSpecifiedFallbackImage = styled(Components.FallbackImage)({
maxWidth: "20rem",
objectFit: "cover",
});
export const PreviewImageField: React.FC<SharedPreviewFieldProps> = ({ originalDataset, previewDataset, name, label }) => {
const backendAdminClient = useBackendAdminClient();
const oldImgId = (originalDataset[name] as string) || "";
const newImgId = (previewDataset[name] as string) || "";
const { data: originalImage } = usePublicFileQuery(backendAdminClient, oldImgId);
const { data: previewImage } = usePublicFileQuery(backendAdminClient, newImgId);
return originalImage?.id === previewImage?.id ? (
<Components.Fieldset legend={label} style={{ width: "100%" }}>
<Stack alignItems="center" justifyContent="center">
{previewImage?.file ? (
<WidthSpecifiedFallbackImage src={previewImage?.file || ""} alt={label} errorFallback={<ImageFallback />} />
) : (
<Typography variant="caption" children="이미지를 지정하지 않았습니다." />
)}
</Stack>
</Components.Fieldset>
) : (
<Box sx={{ my: 1 }}>
<Accordion>
<AccordionSummary>
<Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between">
<Components.Fieldset legend={label} style={{ width: "100%", backgroundColor: "rgba(255, 255, 0, 0.1)" }}>
<Stack alignItems="center" justifyContent="center">
{previewImage?.file ? (
<WidthSpecifiedFallbackImage src={previewImage?.file || ""} alt={label} errorFallback={<ImageFallback />} />
) : (
<Typography variant="caption" children="새 이미지를 지정하지 않았습니다." />
)}
</Stack>
</Components.Fieldset>
<Typography variant="caption">기존 이미지를 보려면 여기를 클릭해주세요.</Typography>
</Stack>
</AccordionSummary>
<AccordionDetails>
<Components.Fieldset legend={label} style={{ backgroundColor: "rgba(0, 64, 64, 0.1)" }}>
<Stack alignItems="center" justifyContent="center">
{originalImage?.file ? (
<WidthSpecifiedFallbackImage src={originalImage?.file || ""} alt={label} errorFallback={<ImageFallback />} />
) : (
<Typography variant="caption" children="기존 이미지를 지정하지 않았습니다." />
)}
</Stack>
</Components.Fieldset>
</AccordionDetails>
</Accordion>
</Box>
);
};
type SimplifiedModificationAudit = {
id: string;
created_at: string;
created_by: string;
status: string;
comments?: {
content: string;
created_by: { is_superuser: boolean; nickname: string };
}[];
};
export const ModificationAuditProperties: React.FC<{ audit: SimplifiedModificationAudit }> = ({ audit }) => {
let rejectReason: React.ReactNode = null;
if (R.isArray(audit.comments) && !R.isEmpty(audit.comments.filter((c) => c.created_by.is_superuser))) {
const comment = audit.comments.filter((c) => c.created_by.is_superuser)[0];
rejectReason = (
<>
<TableRow>
<TableCell>반려 사유</TableCell>
<TableCell>
<pre style={{ whiteSpace: "pre-wrap" }}>{comment.content}</pre>(by {comment.created_by.nickname})
</TableCell>
</TableRow>
</>
);
}
return (
<Table>
<TableHead>
<TableRow>
<TableCell>속성</TableCell>
<TableCell>값</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>심사 ID</TableCell>
<TableCell>{audit.id}</TableCell>
</TableRow>
<TableRow>
<TableCell>심사 요청 시간</TableCell>
<TableCell>{new Date(audit.created_at).toLocaleString()}</TableCell>
</TableRow>
<TableRow>
<TableCell>심사 요청자</TableCell>
<TableCell>{audit.created_by}</TableCell>
</TableRow>
<TableRow>
<TableCell>심사 상태</TableCell>
<TableCell>{audit.status}</TableCell>
</TableRow>
{rejectReason}
</TableBody>
</Table>
);
};