Skip to content

Commit

Permalink
fix: 경찰 이미 사용했을 때는 토스트, 아직 안왔을 때는 안띄움
Browse files Browse the repository at this point in the history
  • Loading branch information
cheonjiyun committed Dec 26, 2024
1 parent f06057a commit 7d91115
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/components/job/PoliceNight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { middle } from '../../pages/Night';
import { VariablesCSS } from '../../styles/VariablesCSS';
import { Player } from '../../type';
import InvestResult from '../modal/InvestResult';
import ModalContainer from '../modal/ModalContainer';
import PlayerGrid from '../player/PlayerGrid';
import PlayerNight from '../player/PlayerNight';

Expand Down Expand Up @@ -48,9 +47,7 @@ export const PoliceNight = (props: PropsType) => {
</PlayerGrid>
</div>
{/* 경찰: 조사하기 */}
<ModalContainer isOpen={openModal}>
<InvestResult target={players[check - 1]?.name} />
</ModalContainer>
{openModal && <InvestResult target={players[check - 1]?.name} isOpen={openModal} />}
</>
);
};
Expand Down
38 changes: 27 additions & 11 deletions src/components/modal/InvestResult.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { useEffect, useState } from 'react';
import { Toaster } from 'react-hot-toast';

import { postSkill } from '../../axios/http';
import { VariablesCSS } from '../../styles/VariablesCSS';
import { Job, SkillResponse } from '../../type';
import PlayerInvest from '../player/PlayerInvest';
import { notifyUseToast } from '../toast/NotifyToast';
import ModalContainer from './ModalContainer';

interface PropsType {
target: string;
isOpen: boolean;
}
export default function InvestResult(props: PropsType) {
const { target } = props;
export default function InvestResult({ target, isOpen }: PropsType) {
const [jobResult, setJobResult] = useState<Job>(null);

const [jobResult, setJobResult] = useState<Job>('CITIZEN');
useEffect(() => {
(async () => {
const skillResponse: SkillResponse = await postSkill({ target: target });
setJobResult(skillResponse.result);
try {
const skillResponse: SkillResponse = await postSkill({ target: target });
setJobResult(skillResponse.result);
} catch (error: any) {
console.log(jobResult);

notifyUseToast(error.response.data.message, 'LOBBY');
}
})();
}, [target]);

return (
<div css={container}>
<PlayerInvest job={jobResult} name={target} />
<p css={description(jobResult)}>
{jobResult === 'MAFIA' ? '마피아가 맞습니다' : '마피아가 아닙니다'}
</p>
</div>
<>
{jobResult && (
<ModalContainer isOpen={isOpen}>
<div css={container}>
<PlayerInvest job={jobResult} name={target} />
<p css={description(jobResult)}>
{jobResult === 'MAFIA' ? '마피아가 맞습니다' : '마피아가 아닙니다'}
</p>
</div>
</ModalContainer>
)}
<Toaster />
</>
);
}

Expand Down

0 comments on commit 7d91115

Please sign in to comment.