Skip to content

Commit

Permalink
feat: put/임시 저장 시 toast 메시지 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj2713 committed Aug 12, 2024
1 parent 08938ee commit 3235ebd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
16 changes: 14 additions & 2 deletions admin/src/features/Rush/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ import { EVENT_LIST_HEADER, QUERY_OPTION } from "@/constants/rush";
import useFetch from "@/hooks/useFetch";
import useRushEventDispatchContext from "@/hooks/useRushEventDispatchContext";
import useRushEventStateContext from "@/hooks/useRushEventStateContext";
import useToast from "@/hooks/useToast";
import { RUSH_ACTION } from "@/types/rush";
import { PutRushEventResponse } from "@/types/rushApi";
import { getTimeDifference } from "@/utils/getTimeDifference";

export default function EventList() {
const navigate = useNavigate();

const { showToast, ToastComponent } = useToast("수정 사항이 반영되었습니다!");

const { rushList } = useRushEventStateContext();
const dispatch = useRushEventDispatchContext();

const { isSuccess: isSuccessPutRush } = useFetch<PutRushEventResponse>(() =>
const { isSuccess: isSuccessPutRush, fetchData: putRush } = useFetch<PutRushEventResponse>(() =>
RushAPI.putRush(rushList)
);

useEffect(() => {
if (isSuccessPutRush) {
showToast();
}
}, [isSuccessPutRush]);

Expand All @@ -40,6 +44,10 @@ export default function EventList() {
dispatch({ type: RUSH_ACTION.SET_EVENT_LIST, payload: updatedTableItemList });
};

const handleUpdate = () => {
putRush();
};

const getTableData = () => {
return rushList.map((item, idx) => {
const canEdit = item.status !== EVENT_STATUS.BEFORE;
Expand Down Expand Up @@ -103,7 +111,11 @@ export default function EventList() {
<Table headers={EVENT_LIST_HEADER} data={getTableData()} />
</div>

<Button buttonSize="lg">수정사항 업데이트</Button>
<Button buttonSize="lg" onClick={handleUpdate}>
수정사항 업데이트
</Button>

{ToastComponent}
</div>
);
}
8 changes: 7 additions & 1 deletion admin/src/features/Rush/RushPrizeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import Button from "@/components/Button";
import SelectForm from "@/components/SelectForm";
import TabHeader from "@/components/TabHeader";
import TextField from "@/components/TextField";
import useRushEventDispatchContext from "@/hooks/useRushEventDispatchContext";
import useRushEventStateContext from "@/hooks/useRushEventStateContext";
import useToast from "@/hooks/useToast";
import { RUSH_ACTION, RushPrizeType } from "@/types/rush";

export default function RushPrizeForm() {
Expand All @@ -17,6 +17,8 @@ export default function RushPrizeForm() {
const { rushList } = useRushEventStateContext();
const dispatch = useRushEventDispatchContext();

const { showToast, ToastComponent } = useToast("입력한 내용이 임시 저장되었습니다!");

const [prizeState, setPrizeState] = useState<RushPrizeType>({} as RushPrizeType);

useEffect(() => {
Expand All @@ -40,6 +42,8 @@ export default function RushPrizeForm() {
type: RUSH_ACTION.SET_EVENT_LIST,
payload: updatedTableItemList,
});

showToast();
};

const option = [
Expand Down Expand Up @@ -70,6 +74,8 @@ export default function RushPrizeForm() {
<Button buttonSize="lg" onClick={handleUpdate}>
임시 저장
</Button>

{ToastComponent}
</div>
);
}
7 changes: 7 additions & 0 deletions admin/src/features/Rush/RushSelectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SelectForm from "@/components/SelectForm";
import TextField from "@/components/TextField";
import useRushEventDispatchContext from "@/hooks/useRushEventDispatchContext";
import useRushEventStateContext from "@/hooks/useRushEventStateContext";
import useToast from "@/hooks/useToast";
import { RUSH_ACTION, RushOptionType } from "@/types/rush";

export default function RushSelectForm() {
Expand All @@ -16,6 +17,8 @@ export default function RushSelectForm() {
const { rushList } = useRushEventStateContext();
const dispatch = useRushEventDispatchContext();

const { showToast, ToastComponent } = useToast("입력한 내용이 임시 저장되었습니다!");

const [selectOptionState, setSelectOptionState] = useState<RushOptionType[]>([]);

useEffect(() => {
Expand All @@ -40,6 +43,8 @@ export default function RushSelectForm() {
type: RUSH_ACTION.SET_EVENT_LIST,
payload: updatedTableItemList,
});

showToast();
};

const handleChangeItem = (key: string, changeIdx: number, text: string) => {
Expand Down Expand Up @@ -123,6 +128,8 @@ export default function RushSelectForm() {
<Button buttonSize="lg" onClick={handleUpdate}>
임시 저장
</Button>

{ToastComponent}
</div>
);
}

0 comments on commit 3235ebd

Please sign in to comment.