Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/toast message 최종 개선 #650 #668

Closed
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3e5239b
[Feat] 관리자 페이지 알림관리의 All버튼과 모달 연결 및 modalprovider 불필요한 intraID 조건 삭제
Feb 14, 2023
f231e7a
[Feat] 관리자 전체 유저 알림 적용,취소 버튼 크기 변경 #650
Feb 14, 2023
7b209f0
[Feat] toast message 기능 초안 추가 #655
salty0306 Feb 14, 2023
f9ff2be
[Feat] 전체 유저 알림 모달 toast message 띄우기 초안 #655
salty0306 Feb 14, 2023
0734fdc
[Feat] 관리자 전체 유저 알림 모달 textarea 수정 #650
salty0306 Feb 15, 2023
c679d26
Merge pull request #660 from 42organization/Feat/toast-message-기능-추가-…
salty0306 Feb 15, 2023
4287a81
[Feat] toast message 최종 개선 #650
salty0306 Feb 20, 2023
d18c3f1
[Feat] 불필요한 주석/코드 삭제 #650
salty0306 Feb 20, 2023
6a6dec4
[Feat] CreateNotiButton 파일 불필요한 주석 삭제 #650
salty0306 Feb 20, 2023
f925104
[Feat] 관리자 전체 유저 알림 모달 불필요한 문구 삭제 #650
salty0306 Feb 20, 2023
4bad0b7
[Feat] escapeKeyDown 기능 추가 및 하드코딩 수정 #650
salty0306 Feb 21, 2023
9cc5ad6
[Feat] import 룰 순서 수정 #650
salty0306 Feb 21, 2023
3b32f69
[Feat] import 룰 기반 순서 수정 #650
salty0306 Feb 21, 2023
d35d10b
[Feat] scss 컨벤션 기반 순서 수정 #650
salty0306 Feb 21, 2023
0849137
Merge branch 'main' into Feat/관리자-전체-유저-알림-모달-개선-#650
salty0306 Feb 21, 2023
3c5d7d9
[Feat] toast message provider로 모달과 분리 작업 #650
salty0306 Feb 22, 2023
5a6721f
Merge branch 'main' into Feat/관리자-전체-유저-알림-모달-개선-#650
salty0306 Feb 22, 2023
3f495a1
[Feat] toast message 모달과 분리 시키기 추가 작업 #650
salty0306 Feb 22, 2023
06f2297
[Feat] 전체 유저 알림 css order 수정 #650
salty0306 Feb 22, 2023
384e852
[Feat] 전체 유저 알림 모달 입력창 사이즈 조절 제한 #650
salty0306 Feb 22, 2023
93c7ec8
[Fix] 두 줄로 되어있는 코드 한 줄로 깔끔 개선 #650
salty0306 Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions components/admin/notification/CreateNotiButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ import style from 'styles/admin/notification/CreateNotificationButton.module.scs
export default function CreateNotiButton() {
const setModal = useSetRecoilState(modalState);

// TODO Create Modal Distinguishing Criteria(param)
const openModal = (param?: string) => {
if (!param) {
// TODO all notification modal
console.log('Create all notification');
} else {
// TODO someone notification modal
console.log(`Create ${param} notification`);
}
};
return (
<>
<div className={style.container}>
<button className={style.createAllButton} onClick={() => openModal()}>
Create All
<button
className={style.createAllButton}
onClick={() => setModal({ modalName: 'ADMIN-NOTI_ALL' })}
>
All
</button>
<button
className={style.createSomeoneButton}
onClick={() => openModal('SOME-ONE')}
onClick={() => setModal({ modalName: 'ADMIN-NOTI_USER' })}
>
Create Someone
User
</button>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion components/modal/ModalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ModalProvider() {
'FIXED-STAT': <StatChangeModal {...exp} />,
'ADMIN-PROFILE': intraId ? <AdminProfileModal value={intraId} /> : null,
'ADMIN-PENALTY': intraId ? <AdminPenaltyModal value={intraId} /> : null,
'ADMIN-NOTI_ALL': intraId ? <AdminNotiAllModal value={intraId} /> : null,
'ADMIN-NOTI_ALL': <AdminNotiAllModal />,
'ADMIN-NOTI_USER': intraId ? <AdminNotiUserModal value={intraId} /> : null,
'ADMIN-CHECK_FEEDBACK': intraId ? <AdminCheckFeedback /> : null,
};
Expand Down
65 changes: 19 additions & 46 deletions components/modal/admin/AdminNotiAllModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { useEffect, useState } from 'react';
import styles from 'styles/admin/modal/AdminNotiAll.module.scss';
import { modalState } from 'utils/recoil/modal';
import instance from 'utils/axios';
import { finished } from 'stream';
import CustomizedSnackbars from 'components/toastmsg/toastmsg';
import styles from 'styles/admin/modal/AdminNotiAll.module.scss';

interface EditedAllNoti {
notification: string | number;
}

//noti가 비어있을 때 적용안되게 수정필요

const MINUTE_LIMIT = 59;

42sungwook marked this conversation as resolved.
Show resolved Hide resolved
export default function AdminNotiAllModal(props: any) {
const [allNoti, setAllNoti] = useState<any>(/* 초기값 필요 */);
const [editedAllNoti, setEditedAllNoti] = useState<EditedAllNoti>({
Expand All @@ -30,52 +25,23 @@ export default function AdminNotiAllModal(props: any) {
}));
};

const getBasicNotiAllHandler = async () => {
const res = await fetch(
`http://localhost:3000/api/admin/users/intraId/penalty`
/* noti 모달인데 패널티 api를 불러옴 post요청인데 애초에 fetch로 정보 불러온게 이상 */
);
const data = await res.json();
setAllNoti(data[0]);
};

// useEffect(() => {
// getBasicPenaltyHandler();
// }, []);
const finishEditHandler = () => {
let errMsg = '';
if (editedAllNoti.notification < 0) {
errMsg += '시간은 0 이상이어야합니다.\n';
console.log(errMsg);
editedAllNoti.notification = '';
}
if (errMsg) alert(errMsg);
setAllNoti({
...editedAllNoti,
intraID: props.value,
});
// setModal({ modalName: null });
};
useEffect(() => {
console.log({ allNoti });
return () => {
console.log({ allNoti });
};
}, [allNoti]);
const setModal = useSetRecoilState(modalState);
const finishEditHandler = () => setModal({ modalName: null });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 핸들러가 현재 안쓰이는데 handleclick에 넣으시면 될 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[적용] 버튼을 눌렀을 때에 Success 토스트 메세지가 띄워짐과 동시에 모달 창만 닫히는 것으로 구현을 해야할지, 아니면 모달 창은 그대로 있는 상태에서 토스트 메세지만 띄워져야할지 상의 후 결정 나는 로직대로 수정하겠습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거는 알림 보낸게 table에 그대로 남으니까 모달창 꺼줘도 될꺼 같아요.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 finishEditHandler와 cancelEditHandler 둘다 동작 로직이 동일해서 개선이 필요해 보여요
finishEditHandler같은 경우 동작 시 toast가 어떤 형식으로든 나타날 테니 finishEditHandler 부븐을 수정하면 어떨까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모송님 의견에 동의합니다 짧은 내용이라 handler를 굳이 함수로 선언하기보다는 사용하는곳에 화살표함수로 setmodal null을 실행하는것도 좋을것같다고 생각해용

const cancelEditHandler = () => setModal({ modalName: null });
const [open, setOpen] = useState(false);

const handleClick = () => {
setOpen((prev) => !prev);
};

return (
<div className={styles.whole}>
<div className={styles.body}>
<div className={styles.title}>NOTI FOR ALL</div>

<label className={styles.body}>
To: everyone
<input
<textarea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따로 입력길이 제한은 안넣는걸까요?
기존 notification 데이터 저장할 때 제한 조건이 없었다면 사용자측에 보여지는 방식을 한번 봐야할 거 같네요. (ex. 입력 데이터가 너무 길 경우)

salty0306 marked this conversation as resolved.
Show resolved Hide resolved
className={styles.blank}
type='text'
pattern='[a-zA-Z0-9가-힣]'
name='notification'
onChange={inputChangeHandler}
value={allNoti?.notification}
Expand All @@ -85,11 +51,18 @@ export default function AdminNotiAllModal(props: any) {

<div className={styles.btns}>
<button
className={allNoti ? `${styles.hide}` : `${styles.btn}`}
onClick={finishEditHandler}
onClick={() => {
handleClick();
}}
className={styles.btn}
>
적용
</button>
<CustomizedSnackbars
clicked={open}
severity='success'
message='Successfully Sent!'
/>
salty0306 marked this conversation as resolved.
Show resolved Hide resolved
<button className={styles.btn} onClick={cancelEditHandler}>
취소
</button>
Expand Down
52 changes: 52 additions & 0 deletions components/toastmsg/toastmsg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { forwardRef, useEffect, useState } from 'react';
import Stack from '@mui/material/Stack';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertColor, AlertProps } from '@mui/material/Alert';

interface Props {
severity: AlertColor;
message: string;
clicked: boolean;
}

const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
props,
ref
) {
return <MuiAlert elevation={6} ref={ref} variant='filled' {...props} />;
});
Comment on lines +8 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몇가지 궁금한게 있어서 설명해주시면 좋을거 같습니다!

  • forwardRef의 기능
  • MuiAlert에서 elevation의 역할


export default function CustomizedSnackbars({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일이름과 컴포넌트 이름은 같은게 보기 좋을것같아요 !

severity,
message,
clicked,
}: Props) {
const [open, setOpen] = useState(false);

useEffect(() => {
if (clicked) {
setOpen(true);
}
salty0306 marked this conversation as resolved.
Show resolved Hide resolved
}, [clicked]);

const handleClose = (
event?: React.SyntheticEvent | Event,
reason?: string
) => {
if (reason === 'clickaway' || reason === 'escapeKeyDown') {
return;
salty0306 marked this conversation as resolved.
Show resolved Hide resolved
}

setOpen(false);
};

return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoHideDuration에 들어가는 인자도 상수화 해주는게 좋을거 같네요.
현재 main에 constants 폴더 안에 구성해 놓은게 있으니 merge하셔서 확인해보세요

<Alert onClose={handleClose} severity={severity} sx={{ width: '100%' }}>
{message}
</Alert>
</Snackbar>
</Stack>
);
}
26 changes: 12 additions & 14 deletions styles/admin/modal/AdminNotiAll.module.scss
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
.whole {
text-align: center;
display: flex;
justify-content: center;
display: inline-block;
align-items: center;
display: inline-block;
justify-content: center;
width: 25rem;
height: 40rem;
text-align: center;
align-items: center;
salty0306 marked this conversation as resolved.
Show resolved Hide resolved
}

.title {
margin-top: 20px;
font-size: 1.5rem;
font-weight: bold;
font-style: normal;
margin-top: 20px;
}

.body {
display: flex;
margin-bottom: 0.2px;
justify-content: center;
padding: 1rem 1rem;
flex-direction: column;
justify-content: center;
text-align: center;
font-size: 30px;
}

.blank {
display: flex;
text-align: center;
margin: auto;
width: 20rem;
height: 25rem;
}

.btns {
text-align: center;
flex-direction: column;
display: flex;
justify-content: center;
// justify-items: center;
flex-direction: column;
text-align: center;
}

.btn {
display: flex;
text-align: center;
justify-content: center;
margin-bottom: 10px;
width: 100px;
height: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
width: 20rem;
height: 40px;
font-weight: bold;
text-align: center;
align-items: center;
salty0306 marked this conversation as resolved.
Show resolved Hide resolved
}

.hide {
Expand Down