/* eslint-disable react-hooks/rules-of-hooks */ import { useEffect, useState } from 'react'; import { Avatar, Box, Button, Container, Flex, Icon, Image, Skeleton, Text, chakra, useColorModeValue, useToast } from '@chakra-ui/react'; import { Link } from '@chakra-ui/next-js'; import { useAuthContext } from '@/contexts/AuthContext'; import { Invitation } from '@/types'; import Head from 'next/head'; import { useRouter } from 'next/router'; import { FiArrowRight } from 'react-icons/fi'; export default function Invitation({ invite, errorMessage }: { invite: Invitation, errorMessage: string | null }) { const { query, push } = useRouter(); const toast = useToast(); const [isAcceptLoading, setIsAcceptLoading] = useState(false); const { user, currentUser } = useAuthContext(); const [loading, setLoading] = useState(true); let { id: queryId } = query; const id = queryId?.length ? queryId[0] : null; useEffect(() => { setLoading(false); }, [user]); const acceptInvite = async () => { setIsAcceptLoading(true); if (invite.type === 'organization') { push(`/organizations/?invitation=${query.id}`); } else if (invite.type === 'xcs') { push(`/auth/activate/${query.id}`); } }; const inviteTypeSwitch = (type: string) => { switch (type) { case 'organization': return 'join their organization'; case 'xcs': return 'create an account.'; default: return null; } }; return ( <> Invitation - Wyre Management {'Wyre {invite ? invite.type === 'organization' ? "You've recieved an invitation" : "You're invited to register" : 'Invitation not found'} {invite ? ( <> {invite?.creator?.displayName || invite?.creator?.name?.first} has invited you to{' '} {inviteTypeSwitch(invite?.type)} {invite?.type === 'organization' ? ( {', '} {invite.organization?.name} ) : null} ) : ( <>{!errorMessage ? "The invitation you are looking for is either invalid or no longer exists." : errorMessage} )} {invite ? ( <> { invite.type === 'organization' && ( <> ) } {currentUser || invite.type === 'xcs' ? ( ) : ( )} By accepting this invitation, you agree to the{' '} Wyre Management {' '} Terms of Use {' '} and{' '} Privacy Policy . ) : ( <> )} ); }