|
| 1 | +import * as Common from "@frontend/common"; |
| 2 | +import { |
| 3 | + Accordion, |
| 4 | + AccordionDetails, |
| 5 | + AccordionSummary, |
| 6 | + Box, |
| 7 | + Stack, |
| 8 | + styled, |
| 9 | + Table, |
| 10 | + TableBody, |
| 11 | + TableCell, |
| 12 | + TableHead, |
| 13 | + TableRow, |
| 14 | + TextField, |
| 15 | + TextFieldProps, |
| 16 | + Typography, |
| 17 | +} from "@mui/material"; |
| 18 | +import * as React from "react"; |
| 19 | + |
| 20 | +type SharedPreviewFieldProps = { |
| 21 | + originalDataset: Record<string, unknown>; |
| 22 | + previewDataset: Record<string, unknown>; |
| 23 | + name: string; |
| 24 | + label: string; |
| 25 | +}; |
| 26 | + |
| 27 | +type PreviewFieldProps = Omit<TextFieldProps, "value" | "name" | "label"> & SharedPreviewFieldProps; |
| 28 | + |
| 29 | +export const PreviewTextField: React.FC<PreviewFieldProps> = ({ originalDataset, previewDataset, name, ...props }) => { |
| 30 | + const textFieldSx: TextFieldProps["sx"] = { |
| 31 | + "& .MuiInputBase-input, & .Mui-disabled": { |
| 32 | + color: "black", |
| 33 | + WebkitTextFillColor: "black", |
| 34 | + "-webkit-text-fill-color": "black", |
| 35 | + }, |
| 36 | + }; |
| 37 | + const textFieldProps: TextFieldProps = { |
| 38 | + fullWidth: true, |
| 39 | + disabled: true, |
| 40 | + variant: "outlined", |
| 41 | + value: previewDataset[name] || "(값 없음)", |
| 42 | + sx: textFieldSx, |
| 43 | + ...props, |
| 44 | + }; |
| 45 | + const modifiedTextFieldProps: TextFieldProps = { ...textFieldProps, sx: { ...textFieldSx, backgroundColor: "rgba(255, 255, 0, 0.1)" } }; |
| 46 | + const originalTextFieldProps: TextFieldProps = { ...textFieldProps, sx: { ...textFieldSx, backgroundColor: "rgba(0, 64, 64, 0.1)" } }; |
| 47 | + const isModified = originalDataset[name] !== previewDataset[name]; |
| 48 | + |
| 49 | + return originalDataset[name] === previewDataset[name] ? ( |
| 50 | + <TextField {...textFieldProps} sx={{ ...textFieldSx, my: 1 }} /> |
| 51 | + ) : ( |
| 52 | + <Box sx={{ my: 1 }}> |
| 53 | + <Accordion> |
| 54 | + <AccordionSummary> |
| 55 | + <Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between"> |
| 56 | + <TextField {...(isModified ? modifiedTextFieldProps : textFieldProps)} /> |
| 57 | + <Typography variant="caption">기존 값을 보려면 여기를 클릭해주세요.</Typography> |
| 58 | + </Stack> |
| 59 | + </AccordionSummary> |
| 60 | + <AccordionDetails> |
| 61 | + <TextField {...originalTextFieldProps} value={originalDataset[name] || "(값 없음)"} /> |
| 62 | + </AccordionDetails> |
| 63 | + </Accordion> |
| 64 | + </Box> |
| 65 | + ); |
| 66 | +}; |
| 67 | + |
| 68 | +export const PreviewMarkdownField: React.FC<SharedPreviewFieldProps> = ({ originalDataset, previewDataset, name, label }) => { |
| 69 | + return originalDataset[name] === previewDataset[name] ? ( |
| 70 | + <Common.Components.Fieldset legend={label} style={{ width: "100%" }}> |
| 71 | + <Box sx={{ width: "100%", color: "black", "& .markdown-body": { width: "100%" } }}> |
| 72 | + <Common.Components.MDXRenderer format="md" text={(previewDataset[name] as string) || "(값 없음)"} /> |
| 73 | + </Box> |
| 74 | + </Common.Components.Fieldset> |
| 75 | + ) : ( |
| 76 | + <Box sx={{ my: 1 }}> |
| 77 | + <Accordion> |
| 78 | + <AccordionSummary> |
| 79 | + <Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between"> |
| 80 | + <Common.Components.Fieldset legend={label} style={{ width: "100%", backgroundColor: "rgba(255, 255, 0, 0.1)" }}> |
| 81 | + <Box sx={{ width: "100%", color: "black", "& .markdown-body": { width: "100%" } }}> |
| 82 | + <Common.Components.MDXRenderer format="md" text={(previewDataset[name] as string) || "(값 없음)"} /> |
| 83 | + </Box> |
| 84 | + </Common.Components.Fieldset> |
| 85 | + <Typography variant="caption">기존 값을 보려면 여기를 클릭해주세요.</Typography> |
| 86 | + </Stack> |
| 87 | + </AccordionSummary> |
| 88 | + <AccordionDetails> |
| 89 | + <Common.Components.Fieldset legend={label} style={{ backgroundColor: "rgba(0, 64, 64, 0.1)" }}> |
| 90 | + <Box sx={{ flexGrow: 1, color: "black", "& .markdown-body": { width: "100%" } }}> |
| 91 | + <Common.Components.MDXRenderer format="md" text={(originalDataset[name] as string) || "(값 없음)"} /> |
| 92 | + </Box> |
| 93 | + </Common.Components.Fieldset> |
| 94 | + </AccordionDetails> |
| 95 | + </Accordion> |
| 96 | + </Box> |
| 97 | + ); |
| 98 | +}; |
| 99 | + |
| 100 | +const ImageFallback: React.FC = () => ( |
| 101 | + <Stack sx={{ width: "100%", height: "100%", alignItems: "center", justifyContent: "center" }}> |
| 102 | + <Typography variant="caption" color="textSecondary" children="이미지를 불러오는 중 문제가 발생했습니다." /> |
| 103 | + </Stack> |
| 104 | +); |
| 105 | + |
| 106 | +const WidthSpecifiedFallbackImage = styled(Common.Components.FallbackImage)({ |
| 107 | + maxWidth: "20rem", |
| 108 | + objectFit: "cover", |
| 109 | +}); |
| 110 | + |
| 111 | +export const PreviewImageField: React.FC<SharedPreviewFieldProps> = ({ originalDataset, previewDataset, name, label }) => { |
| 112 | + const originalImage = originalDataset[name] as string; |
| 113 | + const previewImage = previewDataset[name] as string; |
| 114 | + |
| 115 | + return originalImage === previewImage ? ( |
| 116 | + <Common.Components.Fieldset legend={label} style={{ width: "100%" }}> |
| 117 | + <WidthSpecifiedFallbackImage src={previewImage} alt={label} errorFallback={<ImageFallback />} /> |
| 118 | + </Common.Components.Fieldset> |
| 119 | + ) : ( |
| 120 | + <Box sx={{ my: 1 }}> |
| 121 | + <Accordion> |
| 122 | + <AccordionSummary> |
| 123 | + <Stack sx={{ width: "100%" }} direction="column" alignItems="flex-start" justifyContent="space-between"> |
| 124 | + <Common.Components.Fieldset legend={label} style={{ width: "100%", backgroundColor: "rgba(255, 255, 0, 0.1)" }}> |
| 125 | + <WidthSpecifiedFallbackImage src={previewImage} alt={label} errorFallback={<ImageFallback />} /> |
| 126 | + </Common.Components.Fieldset> |
| 127 | + <Typography variant="caption">기존 이미지를 보려면 여기를 클릭해주세요.</Typography> |
| 128 | + </Stack> |
| 129 | + </AccordionSummary> |
| 130 | + <AccordionDetails> |
| 131 | + <Common.Components.Fieldset legend={label} style={{ backgroundColor: "rgba(0, 64, 64, 0.1)" }}> |
| 132 | + <WidthSpecifiedFallbackImage src={originalImage} alt={label} errorFallback={<ImageFallback />} /> |
| 133 | + </Common.Components.Fieldset> |
| 134 | + </AccordionDetails> |
| 135 | + </Accordion> |
| 136 | + </Box> |
| 137 | + ); |
| 138 | +}; |
| 139 | + |
| 140 | +type SimplifiedModificationAudit = { |
| 141 | + id: string; |
| 142 | + created_at: string; |
| 143 | + created_by: string; |
| 144 | + status: string; |
| 145 | +}; |
| 146 | + |
| 147 | +export const ModificationAuditProperties: React.FC<{ audit: SimplifiedModificationAudit }> = ({ audit }) => ( |
| 148 | + <Table> |
| 149 | + <TableHead> |
| 150 | + <TableRow> |
| 151 | + <TableCell>속성</TableCell> |
| 152 | + <TableCell>값</TableCell> |
| 153 | + </TableRow> |
| 154 | + </TableHead> |
| 155 | + <TableBody> |
| 156 | + <TableRow> |
| 157 | + <TableCell>심사 ID</TableCell> |
| 158 | + <TableCell>{audit.id}</TableCell> |
| 159 | + </TableRow> |
| 160 | + <TableRow> |
| 161 | + <TableCell>심사 요청 시간</TableCell> |
| 162 | + <TableCell>{new Date(audit.created_at).toLocaleString()}</TableCell> |
| 163 | + </TableRow> |
| 164 | + <TableRow> |
| 165 | + <TableCell>심사 요청자</TableCell> |
| 166 | + <TableCell>{audit.created_by}</TableCell> |
| 167 | + </TableRow> |
| 168 | + <TableRow> |
| 169 | + <TableCell>심사 상태</TableCell> |
| 170 | + <TableCell>{audit.status}</TableCell> |
| 171 | + </TableRow> |
| 172 | + </TableBody> |
| 173 | + </Table> |
| 174 | +); |
0 commit comments