-
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
71465f4
commit 43aa999
Showing
13 changed files
with
222 additions
and
26 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
88 changes: 88 additions & 0 deletions
88
src/app/(dynamic-pages)/(authenticated-pages)/onboarding/AcceptInvitations.tsx
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,88 @@ | ||
import { CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; | ||
import { useToast } from "@/components/ui/use-toast"; | ||
import { getPendingInvitationsOfUser } from "@/data/user/invitation"; | ||
import { autoAcceptFirstInvitation } from "@/data/user/user"; | ||
import { useMutation, useQuery } from "@tanstack/react-query"; | ||
import { useEffect } from "react"; | ||
|
||
type AcceptInvitationsProps = { | ||
onSuccess: () => void; | ||
}; | ||
|
||
function Spinner() { | ||
return <div className="w-4 h-4 border-t-2 border-b-2 border-gray-900 rounded-full animate-spin"></div> | ||
} | ||
|
||
export function AcceptInvitations({ onSuccess }: AcceptInvitationsProps) { | ||
const { toast } = useToast(); | ||
|
||
const { data: invitations, isLoading, error } = useQuery({ | ||
queryKey: ["pendingInvitations"], | ||
queryFn: getPendingInvitationsOfUser, | ||
}); | ||
|
||
|
||
|
||
const acceptInvitationMutation = useMutation({ | ||
mutationFn: autoAcceptFirstInvitation, | ||
onSuccess: () => { | ||
toast({ title: "Organization setup complete!", description: "You've joined the organization." }); | ||
onSuccess(); | ||
}, | ||
onError: (error) => { | ||
const errorMessage = String(error); | ||
toast({ title: "Failed to accept invitation", description: errorMessage, variant: "destructive" }); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
acceptInvitationMutation.mutate(); | ||
}, []); | ||
|
||
|
||
|
||
if (isLoading) { | ||
return ( | ||
<> | ||
<CardHeader> | ||
<CardTitle>Checking Invitations</CardTitle> | ||
<CardDescription>Please wait while we process your invitations.</CardDescription> | ||
</CardHeader> | ||
<CardContent className="flex justify-center"> | ||
<Spinner /> | ||
</CardContent> | ||
</> | ||
); | ||
} | ||
|
||
if (error) { | ||
const errorMessage = String(error); | ||
return ( | ||
<> | ||
<CardHeader> | ||
<CardTitle>Error</CardTitle> | ||
<CardDescription>An error occurred while processing invitations.</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<p className="text-destructive">{errorMessage}</p> | ||
</CardContent> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<CardHeader> | ||
<CardTitle>Processing Invitations</CardTitle> | ||
<CardDescription> | ||
{invitations && invitations.length > 0 | ||
? "Accepting your invitations..." | ||
: "No pending invitations found."} | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent className="flex justify-center"> | ||
<Spinner /> | ||
</CardContent> | ||
</> | ||
); | ||
} |
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
8 changes: 0 additions & 8 deletions
8
src/app/(dynamic-pages)/(authenticated-pages)/onboarding/complete/page.tsx
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.