Merge branch 'develop' into feature/paypal-integration
This commit is contained in:
@@ -14,5 +14,6 @@ export const sessionOptions: IronSessionOptions = {
|
||||
declare module "iron-session" {
|
||||
interface IronSessionData {
|
||||
user?: User | null;
|
||||
envVariables?: {[key: string]: string};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {useRouter} from "next/router";
|
||||
import {useEffect} from "react";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import usePreferencesStore from "@/stores/preferencesStore";
|
||||
import {PayPalScriptProvider} from "@paypal/react-paypal-js";
|
||||
|
||||
export default function App({Component, pageProps}: AppProps) {
|
||||
const reset = useExamStore((state) => state.reset);
|
||||
@@ -32,10 +31,5 @@ export default function App({Component, pageProps}: AppProps) {
|
||||
}
|
||||
}, [setIsSidebarMinimized]);
|
||||
|
||||
return (
|
||||
<PayPalScriptProvider
|
||||
options={{clientId: process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID || "", currency: "EUR", intent: "capture", commit: true, vault: true}}>
|
||||
<Component {...pageProps} />
|
||||
</PayPalScriptProvider>
|
||||
);
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { Html, Head, Main, NextScript } from 'next/document'
|
||||
/* eslint-disable @next/next/no-sync-scripts */
|
||||
import {Html, Head, Main, NextScript} from "next/document";
|
||||
|
||||
export default function Document() {
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head />
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
)
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head />
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,10 +29,18 @@ import TeacherDashboard from "@/dashboards/Teacher";
|
||||
import AgentDashboard from "@/dashboards/Agent";
|
||||
import PaymentDue from "./(status)/PaymentDue";
|
||||
import {useRouter} from "next/router";
|
||||
import {PayPalScriptProvider} from "@paypal/react-paypal-js";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
|
||||
const envVariables: {[key: string]: string} = {};
|
||||
Object.keys(process.env)
|
||||
.filter((x) => x.startsWith("NEXT_PUBLIC"))
|
||||
.forEach((x: string) => {
|
||||
envVariables[x] = process.env[x]!;
|
||||
});
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
res.setHeader("location", "/login");
|
||||
res.statusCode = 302;
|
||||
@@ -40,16 +48,17 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
return {
|
||||
props: {
|
||||
user: null,
|
||||
envVariables,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
props: {user: req.session.user, envVariables},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Home() {
|
||||
export default function Home({envVariables}: {envVariables: {[key: string]: string}}) {
|
||||
const [showDiagnostics, setShowDiagnostics] = useState(false);
|
||||
const [showDemographicInput, setShowDemographicInput] = useState(false);
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
@@ -92,7 +101,18 @@ export default function Home() {
|
||||
</div>
|
||||
</Layout>
|
||||
)}
|
||||
{(user.status === "paymentDue" || checkIfUserExpired()) && <PaymentDue hasExpired user={user} reload={router.reload} />}
|
||||
{(user.status === "paymentDue" || checkIfUserExpired()) && (
|
||||
<PayPalScriptProvider
|
||||
options={{
|
||||
clientId: envVariables["NEXT_PUBLIC_PAYPAL_CLIENT_ID"] || "",
|
||||
currency: "EUR",
|
||||
intent: "capture",
|
||||
commit: true,
|
||||
vault: true,
|
||||
}}>
|
||||
<PaymentDue hasExpired user={user} reload={router.reload} />
|
||||
</PayPalScriptProvider>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,22 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import Navbar from "@/components/Navbar";
|
||||
import {BsFileEarmarkText, BsPencil, BsStar, BsBook, BsHeadphones, BsPen, BsMegaphone} from "react-icons/bs";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {useEffect, useState} from "react";
|
||||
import useStats from "@/hooks/useStats";
|
||||
import {averageScore, groupBySession, totalExams} from "@/utils/stats";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import Sidebar from "@/components/Sidebar";
|
||||
import Diagnostic from "@/components/Diagnostic";
|
||||
import {ToastContainer} from "react-toastify";
|
||||
import {capitalize} from "lodash";
|
||||
import {Module} from "@/interfaces";
|
||||
import ProgressBar from "@/components/Low/ProgressBar";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import {calculateAverageLevel} from "@/utils/score";
|
||||
import axios from "axios";
|
||||
import DemographicInformationInput from "@/components/DemographicInformationInput";
|
||||
import moment from "moment";
|
||||
import Link from "next/link";
|
||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
||||
import ProfileSummary from "@/components/ProfileSummary";
|
||||
import StudentDashboard from "@/dashboards/Student";
|
||||
import AdminDashboard from "@/dashboards/Admin";
|
||||
import CorporateDashboard from "@/dashboards/Corporate";
|
||||
import TeacherDashboard from "@/dashboards/Teacher";
|
||||
import AgentDashboard from "@/dashboards/Agent";
|
||||
import PaymentDue from "./(status)/PaymentDue";
|
||||
import {useRouter} from "next/router";
|
||||
import {PayPalScriptProvider} from "@paypal/react-paypal-js";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
|
||||
const envVariables: {[key: string]: string} = {};
|
||||
Object.keys(process.env)
|
||||
.filter((x) => x.startsWith("NEXT_PUBLIC"))
|
||||
.forEach((x: string) => {
|
||||
envVariables[x] = process.env[x]!;
|
||||
});
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
res.setHeader("location", "/login");
|
||||
res.statusCode = 302;
|
||||
@@ -40,16 +24,17 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
return {
|
||||
props: {
|
||||
user: null,
|
||||
envVariables,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
props: {user: req.session.user, envVariables},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Home() {
|
||||
export default function Home({envVariables}: {envVariables: {[key: string]: string}}) {
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
const router = useRouter();
|
||||
|
||||
@@ -64,7 +49,18 @@ export default function Home() {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
{user && <PaymentDue user={user} reload={router.reload} />}
|
||||
{user && (
|
||||
<PayPalScriptProvider
|
||||
options={{
|
||||
clientId: envVariables["NEXT_PUBLIC_PAYPAL_CLIENT_ID"] || "",
|
||||
currency: "EUR",
|
||||
intent: "capture",
|
||||
commit: true,
|
||||
vault: true,
|
||||
}}>
|
||||
<PaymentDue user={user} reload={router.reload} />
|
||||
</PayPalScriptProvider>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,3 +8,7 @@ export function dateSorter(a: any, b: any, direction: "asc" | "desc", key: strin
|
||||
if (moment(b[key]).isAfter(a[key])) return direction === "asc" ? 1 : -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function env(key: string) {
|
||||
return (window as any).__ENV[key];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user