-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
7222049
commit dd22608
Showing
10 changed files
with
212 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
import styled from '@emotion/styled'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { useCallback } from 'react'; | ||
import { generatePath } from 'react-router'; | ||
|
||
import { RemoveButton, Row } from './styled'; | ||
|
||
import { ClearLink } from '@/components'; | ||
import { PAGE_URL } from '@/configs/path'; | ||
import { usePageUiStore } from '@/hooks'; | ||
|
||
export const BoardListItem: React.FC<{ model: Model.Board }> = observer(({ model }) => { | ||
const { deleteBoardModal } = usePageUiStore<PageUiStore.BoardList>(); | ||
|
||
const handleOpendeleteBoardModal = useCallback( | ||
(target: Model.Board) => () => { | ||
deleteBoardModal.open(target); | ||
}, | ||
[], | ||
); | ||
|
||
export const BoardListItem: React.FC<{ model: Model.Board }> = observer( | ||
({ model: { id: boardId, name } }) => ( | ||
<StyledLink to={generatePath(PAGE_URL.PostList, { boardId })}>{name}</StyledLink> | ||
), | ||
); | ||
return ( | ||
<> | ||
<Row> | ||
<StyledLink to={generatePath(PAGE_URL.PostList, { boardId: model.id })}> | ||
{model.name} | ||
</StyledLink> | ||
<RemoveButton onClick={handleOpendeleteBoardModal(model)} /> | ||
</Row> | ||
</> | ||
); | ||
}); | ||
|
||
const StyledLink = styled(ClearLink)` | ||
float: left; | ||
clear: left; | ||
margin-top: 14px; | ||
font-size: 12px; | ||
line-height: 14px; | ||
font-size: 14px; | ||
`; |
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
54 changes: 54 additions & 0 deletions
54
src/pages/board/boardList/components/DeleteBoardModal/DeleteBoardModal.tsx
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,54 @@ | ||
import { Modal } from '@mui/material'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { useCallback } from 'react'; | ||
|
||
import { | ||
ModalAlertMessage, | ||
ModalAlertTitle, | ||
ModalBox, | ||
ModalFooter, | ||
ModalFooterButton, | ||
} from '@/components'; | ||
import { usePageUiStore } from '@/hooks'; | ||
import { useRootStore } from '@/stores'; | ||
|
||
export const DeleteBoardModal: React.FC = observer(() => { | ||
const { | ||
ui: { alert }, | ||
} = useRootStore(); | ||
const { | ||
fetchBoards, | ||
deleteBoardModal: { deleteBoard, target, close, visible }, | ||
} = usePageUiStore<PageUiStore.BoardList>(); | ||
|
||
const handleOk = useCallback(async () => { | ||
if (!target || !target.id || !target.name === undefined) return; | ||
const { success, message } = (await deleteBoard(target.id)) as unknown as StoreAPI; | ||
if (success) { | ||
fetchBoards(); | ||
alert({ | ||
message: `${target.name} 동아리가 삭제되었습니다.`, | ||
}); | ||
} else if (message) alert({ message }); | ||
close(); | ||
}, [target]); | ||
|
||
return ( | ||
<Modal open={visible} closeAfterTransition> | ||
<ModalBox> | ||
<ModalAlertTitle> | ||
<strong>{target && target.name ? target.name : ''}</strong> 동아리 삭제 | ||
</ModalAlertTitle> | ||
<ModalAlertMessage center> | ||
정말로 <strong>{target && target.name ? target.name : ''}</strong> 동아리를 | ||
삭제하시겠습니까? <br /> | ||
삭제된 데이터는 복구되지 않습니다. | ||
</ModalAlertMessage> | ||
<ModalFooter> | ||
<ModalFooterButton onClick={close}>취소</ModalFooterButton> | ||
<ModalFooterButton onClick={handleOk}>확인</ModalFooterButton> | ||
</ModalFooter> | ||
</ModalBox> | ||
</Modal> | ||
); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/pages/board/boardList/components/DeleteBoardModal/DeleteBoardModalUi.ts
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 { makeAutoObservable } from 'mobx'; | ||
|
||
import { BoardRepoImpl as Repo } from '@/stores/repositories/BoardRepo'; | ||
|
||
export class DeleteBoardModalUi { | ||
visible = false; | ||
target?: Model.Board; | ||
|
||
constructor() { | ||
makeAutoObservable(this, {}, { autoBind: true }); | ||
} | ||
|
||
open(target: Model.Board): void { | ||
console.log(target); | ||
this.visible = true; | ||
this.target = target; | ||
} | ||
|
||
close(): void { | ||
this.visible = false; | ||
} | ||
|
||
*deleteBoard(boardId: string): Generator { | ||
try { | ||
yield Repo.delete(boardId); | ||
return { success: true } as StoreAPI; | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
} |
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 @@ | ||
export * from './DeleteBoardModal'; |
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,85 @@ | ||
import styled from '@emotion/styled'; | ||
import AddIcon from '@mui/icons-material/Add'; | ||
import AutorenewIcon from '@mui/icons-material/Autorenew'; | ||
import ClearIcon from '@mui/icons-material/Clear'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { memo, useCallback } from 'react'; | ||
|
||
import { ClearLink, ClearButton } from '@/components'; | ||
import { usePageUiStore } from '@/hooks'; | ||
|
||
export const Box = styled.div` | ||
position: relative; | ||
& + & { | ||
margin-top: 30px; | ||
} | ||
`; | ||
|
||
export const Title = styled.h2` | ||
margin: 0; | ||
padding: 10px 0; | ||
font-size: 18px; | ||
line-height: 21px; | ||
`; | ||
|
||
const _AddLink = styled(ClearLink)` | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
padding: 10px; | ||
`; | ||
|
||
export const AddLink: React.FC<{ to: string }> = memo(({ to }) => ( | ||
<_AddLink to={to}> | ||
<AddIcon fontSize="small" /> | ||
</_AddLink> | ||
)); | ||
|
||
export const Row = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
height: 30px; | ||
font-size: 13px; | ||
margin-top: 8px; | ||
margin-bottom: -10px; | ||
`; | ||
|
||
const UserNameButton = styled(ClearButton)` | ||
padding-left: 10px; | ||
width: 100%; | ||
text-align: left; | ||
-webkit-line-clamp: 1; | ||
`; | ||
|
||
export const UserName: React.FC<{ model: Model.User; withCircleName?: string }> = observer( | ||
({ model, withCircleName = undefined }) => { | ||
const { userInfoModal } = usePageUiStore<PageUiStore.SettingRoleManagement>(); | ||
const handleOpenInfoModal = useCallback(() => userInfoModal.open(model), [model]); | ||
|
||
return ( | ||
<div style={{ flex: '1 0 0', overflow: 'hidden' }}> | ||
<UserNameButton className="text-ellipsis" onClick={handleOpenInfoModal}> | ||
{withCircleName && model.circleNames ? `[ ${withCircleName} ] ` : ''} | ||
{model.nameWithAdmission} | ||
</UserNameButton> | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export const RemoveButton: React.FC<{ onClick: () => void }> = ({ ...props }) => ( | ||
<ClearButton style={{ padding: '10px' }} {...props}> | ||
<ClearIcon fontSize="small" /> | ||
</ClearButton> | ||
); | ||
|
||
export const AutorenewLink: React.FC<{ pathname: string; state: unknown }> = memo( | ||
({ pathname, state }) => ( | ||
<ClearLink to={{ pathname, state }} style={{ padding: '10px' }}> | ||
<AutorenewIcon fontSize="small" /> | ||
</ClearLink> | ||
), | ||
); |
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