-
Notifications
You must be signed in to change notification settings - Fork 0
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
83f7c05
commit 91ee57c
Showing
4 changed files
with
99 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useRouter } from "next/router"; | ||
import { useCallback } from "react"; | ||
import { toast } from "react-toastify"; | ||
|
||
import { Button } from "@/components/forms/Button"; | ||
|
||
import { queryClient } from "@/pages/_app"; | ||
|
||
import { groupsService } from "@/services/groups/groups.service"; | ||
|
||
import { GroupCard, IGroupCard } from "./GroupCard"; | ||
|
||
export interface IGroupJoinedCard extends Omit<IGroupCard, "button"> {} | ||
|
||
export const GroupJoinedCard: React.FC<IGroupJoinedCard> = ({ ...props }) => { | ||
const router = useRouter(); | ||
|
||
const handleLeaveBtnClick = useCallback(() => { | ||
const request = groupsService.leaveGroup(props.id); | ||
toast | ||
.promise(request, { | ||
success: "그룹 탈퇴 완료!", | ||
pending: "잠시만 기다려주세요..", | ||
error: "회계담당자는 그룹을 탈퇴할 수 없습니다", | ||
}) | ||
.then(() => { | ||
queryClient.invalidateQueries({ queryKey: [`/groups`] }); | ||
}) | ||
.catch((e) => { | ||
console.log(e); | ||
}); | ||
}, [props.id]); | ||
|
||
const handleCardClick = useCallback(() => { | ||
router.push(`/groups/${router.query.id}`); | ||
}, [router]); | ||
|
||
return ( | ||
<GroupCard | ||
{...props} | ||
button={ | ||
<Button size="sm" variant="destructive" onClick={handleLeaveBtnClick}> | ||
탈퇴하기 | ||
</Button> | ||
} | ||
onClick={handleCardClick} | ||
/> | ||
); | ||
}; |
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,42 @@ | ||
import { useRouter } from "next/router"; | ||
import { useCallback } from "react"; | ||
import { toast } from "react-toastify"; | ||
|
||
import { Button } from "@/components/forms/Button"; | ||
|
||
import { groupsService } from "@/services/groups/groups.service"; | ||
|
||
import { GroupCard, IGroupCard } from "./GroupCard"; | ||
|
||
export interface IGroupSearchCard extends Omit<IGroupCard, "button"> {} | ||
|
||
export const GroupSearchCard: React.FC<IGroupSearchCard> = ({ ...props }) => { | ||
const router = useRouter(); | ||
|
||
const handleClick = useCallback(async () => { | ||
const request = groupsService.joinGroup(props.id); | ||
toast | ||
.promise(request, { | ||
pending: "그룹 가입중입니다", | ||
success: "그룹 가입 성공!", | ||
error: "그룹은 최대 10개까지 가입 가능합니다", | ||
}) | ||
.then(() => { | ||
router.push(`/groups/${props.id}`); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
}); | ||
}, [props.id, router]); | ||
|
||
return ( | ||
<GroupCard | ||
{...props} | ||
button={ | ||
<Button size="sm" variant="default" onClick={handleClick}> | ||
가입하기 | ||
</Button> | ||
} | ||
/> | ||
); | ||
}; |