-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* User invitiations listing * Fix helper * Fix wording
- Loading branch information
Showing
5 changed files
with
147 additions
and
37 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,65 @@ | ||
'use client'; | ||
|
||
import Button from '../Button'; | ||
import useTransitionRefresh from '@/hooks/useTransitionRefresh'; | ||
import { useMutation } from 'react-query'; | ||
import api from '@/lib/api'; | ||
import { routes } from '@/core/constants'; | ||
import { UserInvitationItem } from '@/lib/queries'; | ||
import useCustomToast from '@/hooks/useCustomToast'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
const UserInvitationItem = ({ | ||
invitation, | ||
}: { | ||
invitation: UserInvitationItem; | ||
}) => { | ||
const router = useRouter(); | ||
const { successToast, errorToast } = useCustomToast(); | ||
const { refresh, isRefreshing } = useTransitionRefresh(); | ||
const { mutate: joinTeam, isLoading } = useMutation( | ||
'join-team', | ||
({ teamId, invitationId }: { teamId: string; invitationId: string }) => | ||
api.get(`${routes.TEAMS}/${teamId}/invitations/${invitationId}/accept`), | ||
{ | ||
onSuccess: () => { | ||
successToast('Welcome to your new team !'); | ||
refresh(); | ||
router.push(`${routes.TEAMS}/${invitation?.membership?.team?.slug}`, { | ||
forceOptimisticNavigation: true, | ||
}); | ||
}, | ||
onError: () => { | ||
errorToast('Something went wrong...'); | ||
}, | ||
} | ||
); | ||
|
||
return ( | ||
<div role="group" className="flex gap-2 p-2 rounded-md bg-gray-50"> | ||
<div className="w-full flex gap-2"> | ||
<div className="flex gap-2 justify-between items-center w-full"> | ||
<p className="overflow-hidden overflow-ellipsis whitespace-nowrap max-w-[14rem] text-gray-900 font-semibold text-sm"> | ||
{invitation?.membership?.team?.name} | ||
</p> | ||
<div className="flex gap-2 justify-between self-end items-center"> | ||
<Button | ||
variant="outline" | ||
isLoading={isLoading || isRefreshing} | ||
onClick={() => | ||
joinTeam({ | ||
teamId: invitation?.membership?.team?.id, | ||
invitationId: invitation?.id, | ||
}) | ||
} | ||
> | ||
Accept | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserInvitationItem; |
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,31 @@ | ||
'use client'; | ||
|
||
import SectionContainer from '../layout/SectionContainer'; | ||
import { UserInvitationsResults } from '@/lib/queries'; | ||
import UserInvitationItem from './UserInvitationItem'; | ||
|
||
const UserInvitations = ({ | ||
invitations, | ||
}: { | ||
invitations: UserInvitationsResults; | ||
}) => { | ||
return ( | ||
<SectionContainer | ||
title="My invitations" | ||
className="flex justify-center max-w-2xl m-auto w-full" | ||
> | ||
{invitations?.length ? ( | ||
<p className="pb-4">Find all pending invitations below</p> | ||
) : ( | ||
<p>You have no pending invitations</p> | ||
)} | ||
<div className="flex flex-col space-y-4"> | ||
{invitations?.map((invitation) => ( | ||
<UserInvitationItem key={invitation?.id} invitation={invitation} /> | ||
))} | ||
</div> | ||
</SectionContainer> | ||
); | ||
}; | ||
|
||
export default UserInvitations; |
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
919b4cf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
digestclub – ./
digestclub-premieroctet.vercel.app
digestclub-git-main-premieroctet.vercel.app
digestclub.vercel.app