2023-07-18 10:47:59 +03:00
|
|
|
"use client";
|
|
|
|
|
2023-08-10 10:55:40 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
2023-07-18 10:47:59 +03:00
|
|
|
import Button from "@/lib/components/ui/Button";
|
|
|
|
import PageHeading from "@/lib/components/ui/PageHeading";
|
|
|
|
import Spinner from "@/lib/components/ui/Spinner";
|
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
|
|
|
|
|
|
|
import { useInvitation } from "./hooks/useInvitation";
|
|
|
|
|
|
|
|
const InvitationPage = (): JSX.Element => {
|
2023-08-10 10:55:40 +03:00
|
|
|
const { t } = useTranslation('invitation');
|
2023-07-18 19:28:44 +03:00
|
|
|
const {
|
|
|
|
handleAccept,
|
|
|
|
isProcessingRequest,
|
|
|
|
handleDecline,
|
|
|
|
isLoading,
|
|
|
|
brainName,
|
2023-07-20 19:17:55 +03:00
|
|
|
role,
|
2023-07-18 19:28:44 +03:00
|
|
|
} = useInvitation();
|
2023-07-18 10:47:59 +03:00
|
|
|
const { session } = useSupabase();
|
2023-07-18 19:28:44 +03:00
|
|
|
|
2023-07-18 10:47:59 +03:00
|
|
|
if (isLoading) {
|
|
|
|
return <Spinner />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (session?.user === undefined) {
|
|
|
|
redirectToLogin();
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:17:55 +03:00
|
|
|
if (role === undefined) {
|
|
|
|
// This should never happen
|
|
|
|
// It is a way to prevent the page from crashing when invitation is invalid instead of throwing an error
|
|
|
|
// The user will be redirected to the home page (handled in the useInvitation hook)
|
|
|
|
return <div />;
|
2023-07-20 16:15:43 +03:00
|
|
|
}
|
|
|
|
|
2023-07-18 10:47:59 +03:00
|
|
|
return (
|
|
|
|
<main className="pt-10">
|
|
|
|
<PageHeading
|
2023-08-10 10:55:40 +03:00
|
|
|
title={t("wellcome",{brain: brainName, ns: "invitation"})}
|
|
|
|
subtitle={t("invitationMessage",{role: role, ns: "invitation"})}
|
2023-07-18 10:47:59 +03:00
|
|
|
/>
|
2023-07-18 19:28:44 +03:00
|
|
|
{isProcessingRequest ? (
|
|
|
|
<div className="flex flex-col items-center justify-center mt-5">
|
|
|
|
<Spinner />
|
2023-08-10 10:55:40 +03:00
|
|
|
<p className="text-center">{t("processingRequest",{ns: "invitation"})}</p>
|
2023-07-18 19:28:44 +03:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex flex-col items-center justify-center gap-5 mt-5">
|
|
|
|
<Button
|
|
|
|
onClick={() => void handleAccept()}
|
|
|
|
variant={"secondary"}
|
|
|
|
className="py-3"
|
|
|
|
>
|
2023-08-10 10:55:40 +03:00
|
|
|
{t("accept",{ns: "invitation"})}
|
2023-07-18 19:28:44 +03:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={() => void handleDecline()}
|
|
|
|
variant={"danger"}
|
|
|
|
className="py-3"
|
|
|
|
>
|
2023-08-10 10:55:40 +03:00
|
|
|
{t("reject",{ns: "invitation"})}
|
2023-07-18 19:28:44 +03:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-18 10:47:59 +03:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InvitationPage;
|