Skip to content

Commit fcf3ad0

Browse files
committed
전역 dialog 관련 상태 추가
1 parent 5550364 commit fcf3ad0

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

src/dialogs/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useCallback } from 'react'
2+
import { useSelector } from "react-redux"
3+
4+
import { RootState } from "store"
5+
import { PossibleGlobalDialogTyle } from "store/Core"
6+
import { DIALOG_CONST_PROGRAM_NOT_HELD_ON_2024, DIALOG_TYPE_PROGRAM_NOT_HELD_ON_2024 } from 'store/Core/dialog'
7+
import { ProgramNotHeldOn2024 } from './program'
8+
9+
export const useGlobalDialog = () => {
10+
const globalDialogState = useSelector<RootState, PossibleGlobalDialogTyle>((state) => state.core.globalDialog);
11+
return useCallback((key: DIALOG_TYPE_PROGRAM_NOT_HELD_ON_2024) => globalDialogState === key, [globalDialogState]);
12+
};
13+
14+
export const DialogCollection: React.FC = () => {
15+
const dialogOpenMgr = useGlobalDialog();
16+
return <>
17+
<ProgramNotHeldOn2024 open={dialogOpenMgr(DIALOG_CONST_PROGRAM_NOT_HELD_ON_2024)} />
18+
</>
19+
}

src/dialogs/program.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react'
2+
import { useDispatch } from 'react-redux'
3+
4+
import { closeGlobalDialog } from 'store/Core'
5+
import styled from 'styled-components'
6+
7+
export const ProgramNotHeldOn2024: React.FC<{open?: boolean}> = (props) => {
8+
const dispatch = useDispatch()
9+
return <dialog {...props}>
10+
<DialogAside>
11+
<div>
12+
<h1>튜토리얼 및 스프린트 관련 안내</h1>
13+
올해도 파이썬의 저변을 넓히는 활동의 하나로 튜토리얼 프로그램을 준비하고 있었으나,<br />
14+
아쉽게도 올해는 내부 사정으로 인해 올해는 튜토리얼 프로그램이 진행되지 않음을 알려드립니다.<br />
15+
<br />
16+
이러한 안내를 드리게 되어 저희도 매우 아쉬운 마음이며,<br />
17+
많은 파이써니스타 여러분들께 너른 양해를 구합니다.<br />
18+
</div>
19+
<br />
20+
<DialogCloseButton onClick={() => dispatch(closeGlobalDialog())}>확인</DialogCloseButton>
21+
</DialogAside>
22+
</dialog>
23+
}
24+
25+
const DialogAside = styled.aside`
26+
background-color: #333;
27+
padding: 1rem;
28+
border-radius: 0.25rem;
29+
`
30+
31+
const DialogCloseButton = styled.button`
32+
width: 100%;
33+
padding: 0.25rem;
34+
`

src/routes.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const Router = () => {
2929
<Route path="*" element={<Navigate replace to={"/404"} />} />
3030
</Routes>
3131
<Footer />
32+
<DialogCollection />
3233
</BrowserRouter>
3334
);
3435
};

src/store/Core/dialog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const DIALOG_CONST_PROGRAM_NOT_HELD_ON_2024 = "PROGRAM_NOT_HELD_ON_2024";
2+
export type DIALOG_TYPE_PROGRAM_NOT_HELD_ON_2024 = typeof DIALOG_CONST_PROGRAM_NOT_HELD_ON_2024;

src/store/Core/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
import { createSlice } from "@reduxjs/toolkit";
1+
import { createSlice } from "@reduxjs/toolkit"
22

3+
import { DIALOG_TYPE_PROGRAM_NOT_HELD_ON_2024 } from "./dialog"
4+
5+
export type PossibleLanguage = "KOR" | "ENG";
6+
export type PossibleGlobalDialogTyle = DIALOG_TYPE_PROGRAM_NOT_HELD_ON_2024 | null;
37
export type CoreState = {
4-
language: "KOR" | "ENG";
8+
language: PossibleLanguage;
9+
globalDialog: PossibleGlobalDialogTyle;
510
};
611

712
const initialState: CoreState = {
813
language: "KOR",
14+
globalDialog: null,
915
};
1016

1117
const core = createSlice({
1218
name: "core",
1319
initialState,
1420
reducers: {
21+
// Set page language
1522
setLanguage: (state, { payload }: { payload: CoreState["language"] }) => {
1623
state.language = payload;
1724
},
25+
// Show global dialog
26+
openGlobalDialog: (state, { payload }: { payload: PossibleGlobalDialogTyle }) => {
27+
state.globalDialog = payload;
28+
},
29+
closeGlobalDialog: (state) => {
30+
state.globalDialog = null;
31+
},
1832
},
1933
});
2034

21-
export const { setLanguage } = core.actions;
35+
export const { setLanguage, openGlobalDialog, closeGlobalDialog } = core.actions;
2236

2337
export default core.reducer;

0 commit comments

Comments
 (0)