Implemented the whole flow for when a user intends to input their own levels
This commit is contained in:
@@ -16,11 +16,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const docUser = await getDoc(doc(db, "users", req.session.user.id));
|
||||
const user = docUser.data() as User;
|
||||
|
||||
const userRef = doc(db, "users", user.id);
|
||||
setDoc(userRef, req.body, {merge: true});
|
||||
const userRef = doc(db, "users", req.session.user.id);
|
||||
await setDoc(userRef, req.body, {merge: true});
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
}
|
||||
|
||||
@@ -36,14 +36,18 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
export default function Home() {
|
||||
const [showEndExam, setShowEndExam] = useState(false);
|
||||
const [windowWidth, setWindowWidth] = useState(0);
|
||||
const [showDiagnostics, setShowDiagnostics] = useState(false);
|
||||
|
||||
const {stats, isLoading} = useStats();
|
||||
const {user} = useUser({redirectTo: "/login"});
|
||||
|
||||
useEffect(() => setShowEndExam(window.innerWidth <= 960), []);
|
||||
useEffect(() => setWindowWidth(window.innerWidth), []);
|
||||
useEffect(() => {
|
||||
if (user) setShowDiagnostics(user.isFirstLogin);
|
||||
}, [user]);
|
||||
|
||||
if (user && user.isFirstLogin) {
|
||||
if (user && showDiagnostics) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -56,7 +60,7 @@ export default function Home() {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<main className="w-full h-full min-h-[100vh] flex flex-col items-center justify-center bg-neutral-100 text-black">
|
||||
<Diagnostic user={user} />
|
||||
<Diagnostic user={user} onFinish={() => setShowDiagnostics(false)} />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user