-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
410 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface NoticeListResponse { | ||
id: number | ||
title: string | ||
created_at: string | ||
} | ||
|
||
export interface NoticeDetailResponse { | ||
title: string; | ||
content: string; | ||
created_at: string; | ||
attachments: AttachmentResponse[]; | ||
} | ||
|
||
type AttachmentType = | ||
| "FILE" | ||
| "URL" | ||
|
||
export interface AttachmentResponse { | ||
url: string; | ||
type: AttachmentType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Icon } from '@team-return/design-system'; | ||
import { AttachmentResponse } from '../../../Apis/Notices/response'; | ||
import * as _ from './style'; | ||
import axios from 'axios'; | ||
|
||
interface PropsType { | ||
props: AttachmentResponse[]; | ||
} | ||
|
||
export function AttachedBox({ props }: PropsType) { | ||
const file_name_regex = (url: string) => { | ||
return url.replace(/(?:.*?-){5}(.*)/, '$1').replaceAll('+', ' '); | ||
}; | ||
|
||
const downLoadFile = async (attachment: AttachmentResponse) => { | ||
try { | ||
const response = await axios.get( | ||
`${process.env.REACT_APP_FILE_URL}${attachment.url}`, | ||
{ | ||
responseType: 'blob', | ||
} | ||
); | ||
|
||
const url = window.URL.createObjectURL(new Blob([response.data])); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = file_name_regex(attachment.url); | ||
document.body.appendChild(a); | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
document.body.removeChild(a); | ||
} catch (error) { | ||
console.error('파일 다운로드 에러: ', error); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<_.AttachedWrapper> | ||
<_.AttachmentTitle>첨부자료</_.AttachmentTitle> | ||
<_.Attachments> | ||
{props.map((attachment, index) => ( | ||
<_.Attachment key={index}> | ||
<div>{file_name_regex(attachment.url)}</div> | ||
<Icon | ||
icon="Download" | ||
size={15} | ||
color="liteBlue" | ||
cursor="pointer" | ||
onClick={() => downLoadFile(attachment)} | ||
/> | ||
</_.Attachment> | ||
))} | ||
</_.Attachments> | ||
</_.AttachedWrapper> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const AttachedWrapper = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
width: 100%; | ||
height: auto; | ||
margin-top: 32px; | ||
border-top: 2px solid #135c9d; | ||
border-bottom: 1px solid #135c9d; | ||
padding: 16px; | ||
gap: 20px; | ||
`; | ||
|
||
export const AttachmentTitle = styled.div` | ||
font-weight: 500; | ||
font-size: 18px; | ||
`; | ||
|
||
export const Attachments = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
justify-content: center; | ||
`; | ||
|
||
export const Attachment = styled.div` | ||
display: flex; | ||
gap: 7px; | ||
align-items: center; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useNoticeDetailData } from '../../../Apis/Notices'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { Header } from '../../../Components/Header'; | ||
import { Icon } from '@team-return/design-system'; | ||
import { useDeleteNotice } from '../../../Apis/Notices'; | ||
import * as _ from './style'; | ||
import { AttachedBox } from '../../../Components/Notice/AttachedBox'; | ||
|
||
export function NoticeDetailPage() { | ||
const { id } = useParams<{ id: any }>(); | ||
const { noticeDetail } = useNoticeDetailData(id); | ||
const items = [noticeDetail]; | ||
|
||
const navigate = useNavigate(); | ||
const { mutate: deleteNotice } = useDeleteNotice(id, { | ||
onSuccess: () => { | ||
navigate('/Notice'); | ||
}, | ||
onError: (error) => { | ||
console.error('notice delete error:', error); | ||
}, | ||
}); | ||
|
||
const handleDeleteClick = () => { | ||
if (window.confirm('공지사항을 삭제하시겠습니까?')) { | ||
deleteNotice(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<_.Wrapper> | ||
<_.Background> | ||
<_.Box> | ||
<_.HeaderWrapper> | ||
<_.Title>{noticeDetail?.title}</_.Title> | ||
<_.IconWrapper> | ||
<_.IconBox> | ||
<Icon | ||
icon="Trash" | ||
color={'gray90'} | ||
size={40} | ||
onClick={handleDeleteClick} | ||
></Icon> | ||
</_.IconBox> | ||
<_.IconBox> | ||
<Icon | ||
icon="EditPencil" | ||
color={'gray90'} | ||
size={26} | ||
></Icon> | ||
</_.IconBox> | ||
</_.IconWrapper> | ||
</_.HeaderWrapper> | ||
<_.Date> | ||
{noticeDetail?.created_at.substring(0, 10)} | ||
</_.Date> | ||
<_.Contents>{noticeDetail?.content}</_.Contents> | ||
{items?.map((item) => ( | ||
<AttachedBox props={item?.attachments || []} /> | ||
))} | ||
</_.Box> | ||
</_.Background> | ||
</_.Wrapper> | ||
</> | ||
); | ||
} |
Oops, something went wrong.