2023-07-25 19:37:04 +02:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-12-07 18:09:01 +01:00
|
|
|
import { FullScreenLoader } from "@/components/Preloader";
|
|
|
|
import Invite from "@/models/invite";
|
2023-07-25 19:37:04 +02:00
|
|
|
import NewUserModal from "./NewUserModal";
|
2024-01-23 23:19:08 +01:00
|
|
|
import ModalWrapper from "@/components/ModalWrapper";
|
2023-07-25 19:37:04 +02:00
|
|
|
|
|
|
|
export default function InvitePage() {
|
|
|
|
const { code } = useParams();
|
|
|
|
const [result, setResult] = useState({
|
|
|
|
status: "loading",
|
|
|
|
message: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
async function checkInvite() {
|
|
|
|
if (!code) {
|
|
|
|
setResult({
|
|
|
|
status: "invalid",
|
|
|
|
message: "No invite code provided.",
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { invite, error } = await Invite.checkInvite(code);
|
|
|
|
setResult({
|
|
|
|
status: invite ? "valid" : "invalid",
|
|
|
|
message: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
checkInvite();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (result.status === "loading") {
|
|
|
|
return (
|
2023-11-14 22:58:00 +01:00
|
|
|
<div className="w-screen h-screen overflow-hidden bg-sidebar flex">
|
2023-07-25 19:37:04 +02:00
|
|
|
<FullScreenLoader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.status === "invalid") {
|
|
|
|
return (
|
2023-11-14 22:58:00 +01:00
|
|
|
<div className="w-screen h-screen overflow-hidden bg-sidebar flex items-center justify-center">
|
|
|
|
<p className="text-red-400 text-lg">{result.message}</p>
|
2023-07-25 19:37:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-11-14 22:58:00 +01:00
|
|
|
<div className="w-screen h-screen overflow-hidden bg-sidebar flex items-center justify-center">
|
2024-01-23 23:19:08 +01:00
|
|
|
<ModalWrapper isOpen={true}>
|
|
|
|
<NewUserModal />
|
|
|
|
</ModalWrapper>
|
2023-07-25 19:37:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|