Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production/v 1 #189

Merged
merged 14 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions WebApp/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HOST_IP=26.120.94.67
HOST_IP=localhost
HOST_PROTOCOL=http
# DATABASE CONNECTION STRINGS
BACKEND_ACCOUNT_CONN_STR=Server=mssql;Database=QuizMasterAccount;Trusted_Connection=False;TrustServerCertificate=True;User Id=sa;Password=MsSql123
Expand All @@ -8,7 +8,7 @@ BACKEND_QUIZ_CONN_STR=Server=mssql;Database=QuizMasterQuiz;Trusted_Connection=Fa
BACKEND_SESSION_CONN_STR=Server=mssql;Database=QuizMasterSession;Trusted_Connection=False;TrustServerCertificate=True;User Id=sa;Password=MsSql123

# GATEWAY
GATEWAY_CORS=http://26.120.94.67:3000;http://26.120.94.67:3001;http://26.120.94.67:5173;https://26.120.94.67:7081;
GATEWAY_CORS=http://localhost:3000;http://localhost:3001;http://localhost:5173;https://localhost:7081;

# SESSION SETTINGS
SHOW_ANSWER_AFTER_QUESTION_DELAY=10
Expand Down
2 changes: 1 addition & 1 deletion WebApp/backend/QuizMaster.API.Monitoring/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void Main(string[] args)

app.UseHttpsRedirection();

app.UseCors(options => options.SetIsOriginAllowed(x => true).AllowAnyMethod().AllowCredentials().AllowAnyHeader());
app.UseCors(options => options.SetIsOriginAllowed(x => true).AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

app.UseAuthorization();
app.MapGrpcService<MonitoringInfoService>().RequireCors("AllowAll"); ;
Expand Down
1 change: 1 addition & 0 deletions WebApp/frontend/quiz-master/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXTAUTH_URL=http://26.120.94.67:3000
BASE_URL=http://26.120.94.67:3000
QUIZMASTER_GATEWAY=https://26.120.94.67:7081
QUIZMASTER_SESSION_WEBSITE=http://26.120.94.67:3001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const authOptions = {
return session;
},
},

site: process.env.BASE_URL
};

const handler = NextAuth(authOptions as any);
Expand Down
7 changes: 4 additions & 3 deletions WebApp/frontend/quiz-master/app/auth/[authPage]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import ErrorContainer from "@/components/pages/ErrorContainer";
import ErrorBoundary from "@/components/pages/ErrorContainer";
import RegisterForm from "@/components/register-form";
import { useSession } from "next-auth/react";
import { redirect } from "next/navigation";
import { redirect, useRouter } from "next/navigation";
import { useSearchParams } from "next/navigation";
import { useEffect } from "react";

export default function Page({
params,
}: {
params: { authPage: "login" | "signup" | undefined };
}) {
const searchParams = useSearchParams();

const router = useRouter();
const authPage = params.authPage || "login";
const callbackUrl = searchParams.get("callbackUrl") || "/dashboard";
const callbackUrl = searchParams.get("callbackUrl") || "/home";
const { status } = useSession();

if (status === "loading") {
Expand Down
10 changes: 3 additions & 7 deletions WebApp/frontend/quiz-master/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

import LoginForm from "@/components/login-form";
import { getServerSession } from "next-auth";
import HeadNav from "@/components/Commons/navbars/head-nav";
import Homes from "./home/layout";

import React from "react";
export default async function Home() {
const session = await getServerSession();
return (
<main >
{session ? (
<HeadNav />
) : (
<LoginForm callbackUrl="/" />
)}
<main>
{session ? <Homes>e</Homes> : <LoginForm callbackUrl="/" />}
</main>
);
}
80 changes: 56 additions & 24 deletions WebApp/frontend/quiz-master/app/question-sets/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { postQuestionSet, updateQuestionSet } from "@/lib/hooks/set";
import { notification } from "@/lib/notifications";
import { useRouter } from "next/navigation";
import { fetchQuestion, fetchSet, fetchSetQuestions } from "@/lib/quizData";
import { QUIZMASTER_SET_DELETE } from "@/api/api-routes";
import { notifications } from "@mantine/notifications";

const items = [
{ label: "All", href: "/question-sets" },
Expand Down Expand Up @@ -91,13 +93,13 @@ export default function Page({ params }: { params: { id: number } }) {
});
}, [params.id]);

// useEffect(() => {
// removeQuestion.map((id) => {
// setQuestionSet((prev) =>
// prev.filter((question) => question.id !== id)
// );
// });
// }, [removeQuestion]);
useEffect(() => {
removeQuestion.map((id) => {
setQuestionSet((prev) =>
prev.filter((question) => question.id !== id)
);
});
}, [removeQuestion]);

//check if there are changes in list of questions
useEffect(() => {
Expand All @@ -112,6 +114,25 @@ export default function Page({ params }: { params: { id: number } }) {
});
}, [questionSet]);

const handleDelete = async () => {
const token = localStorage.getItem("token");
const res = await fetch(`${QUIZMASTER_SET_DELETE}${params.id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});

if (res.status === 200) {
notifications.show({
title: "Set Deleted",
message: "Set was deleted successfully",
});
router.push("/question-sets");
}
};

const handleSubmit = useCallback(async () => {
formValues.values.questions = questionSet.map(
(question) => question.id
Expand Down Expand Up @@ -158,8 +179,7 @@ export default function Page({ params }: { params: { id: number } }) {
</div>
<form
className="flex flex-col gap-8 relative"
onSubmit={form.onSubmit((values) => {
})}
onSubmit={form.onSubmit((values) => {})}
onReset={() => form.reset()}
>
<LoadingOverlay
Expand Down Expand Up @@ -211,21 +231,33 @@ export default function Page({ params }: { params: { id: number } }) {
>
Cancel
</Link>
<Button
className="flex ml-3 h-[40px] bg-[--primary] items-center gap-3 rounded-md py-3 text-white text-sm font-medium justify-start px-3"
color="green"
onClick={handleSubmit}
disabled={
(formValues.values.qSetName ===
originalSetDetails?.qSetName &&
noChanges &&
questionSet.length === originalQIds.length) ||
questionSet.length === 0 ||
formValues.values.qSetName === ""
}
>
<p className="block">Update Set</p>
</Button>
{questionSet.length > 0 ? (
<Button
className="flex ml-3 h-[40px] bg-[--primary] items-center gap-3 rounded-md py-3 text-white text-sm font-medium justify-start px-3"
color="green"
onClick={handleSubmit}
disabled={
(formValues.values.qSetName ===
originalSetDetails?.qSetName &&
noChanges &&
questionSet.length ===
originalQIds.length) ||
questionSet.length === 0 ||
formValues.values.qSetName === ""
}
>
<p className="block">Update Set</p>
</Button>
) : (
<Button
className="flex ml-3 h-[40px] bg-red-200 items-center gap-3 rounded-md py-3 text-white text-sm font-medium justify-start px-3"
color="red"
onClick={handleDelete}
disabled={questionSet.length !== 0}
>
<p className="block">Delete Set</p>
</Button>
)}
</div>
</form>
<AddQuestionToSetModal
Expand Down
40 changes: 32 additions & 8 deletions WebApp/frontend/quiz-master/app/questions/create-question/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import {
import { useForm } from "@mantine/form";
import { useDisclosure } from "@mantine/hooks";
import { useRouter } from "next/navigation";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import styles from "@/styles/input.module.css";
import { notifications } from "@mantine/notifications";
import notificationStyles from "@/styles/notification.module.css";
import ImageInput from "@/components/Commons/inputs/ImageInput";
import AudioInput from "@/components/Commons/inputs/AudioInput";
import { notification } from "@/lib/notifications";
import { postQuestion } from "@/lib/hooks/question";
import { GetAllQuestion, postQuestion } from "@/lib/hooks/question";
import { useQuestionnaire } from "@/store/QuestionStore";

const timeLimits = [10, 15, 30, 60, 120];

Expand All @@ -49,6 +50,7 @@ export default function Page() {
const { questionCategories } = useQuestionCategoriesStore();
const { questionDifficulties } = useQuestionDifficultiesStore();
const { questionTypes } = useQuestionTypesStore();
const { questionnaire, setQuestionnaire } = useQuestionnaire();
const router = useRouter();
const [visible, { close, open }] = useDisclosure(false);
const [fileImage, setFileImage] = useState<File | null>(null);
Expand All @@ -59,10 +61,10 @@ export default function Page() {
qStatement: "",
qAudio: "",
qImage: "",
qCategoryId: "1",
qDifficultyId: "1",
qTypeId: "1",
qTime: "30",
qCategoryId: questionnaire.qCategoryId + "",
qDifficultyId: questionnaire.qDifficultyId + "",
qTypeId: questionnaire.qTypeId + "",
qTime: questionnaire.qTime + "",
questionDetailCreateDtos: [],
options: [],
trueOrFalseAnswer: true,
Expand Down Expand Up @@ -162,6 +164,14 @@ export default function Page() {
return "Provide option";
}

// Check if more than one option is selected
if (
values.options.filter((option) => option.isAnswer)
.length > 1
) {
return "Only one answer must be selected";
}

return values.options.findIndex((op, i) => {
return (
op.value === value && path !== `options.${i}.value`
Expand Down Expand Up @@ -205,6 +215,8 @@ export default function Page() {
type: "success",
title: response.message,
});
const questionsRes = await GetAllQuestion();
if (questionsRes) setQuestionnaire(questionsRes.pop());
// redirect to qeustions page
router.push("/questions");
} else {
Expand Down Expand Up @@ -327,10 +339,22 @@ export default function Page() {
<QuestionDetails form={form} />

<div className="flex justify-end">
<Button variant="transparent" color="gray" type="reset" onClick={()=>{router.push("/questions")}}>
<Button
variant="transparent"
color="gray"
type="reset"
onClick={() => {
router.push("/questions");
}}
>
Cancel
</Button>
<Button variant="filled" color="green" type="submit" className="bg-[#FF6633]">
<Button
variant="filled"
color="green"
type="submit"
className="bg-[#FF6633]"
>
Create
</Button>
</div>
Expand Down
12 changes: 9 additions & 3 deletions WebApp/frontend/quiz-master/app/questions/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ import ErrorContainer from "@/components/pages/ErrorContainer";
import { useErrorRedirection } from "@/utils/errorRedirection";
import { fetchLoginUser } from "@/lib/quizData";
import { useRouter } from "next/navigation";
import { useQuestionnaire } from "@/store/QuestionStore";
import { GetAllQuestion } from "@/lib/hooks/question";

export default function Layout({ children }: { children: React.ReactNode }) {
const router = useRouter();

useEffect(()=>{
useEffect(() => {
fetchLoginUser().then((res) => {
if (res !== null && res !== undefined) {
if(!(res?.info.roles.includes("Administrator"))){
if (!res?.info.roles.includes("Administrator")) {
router.push("/home");
}
}
});
}, [])
}, []);

const { setQuestionCategories } = useQuestionCategoriesStore();
const { setQuestionDifficulties } = useQuestionDifficultiesStore();
const { setQuestionTypes } = useQuestionTypesStore();
const { setQuestionnaire } = useQuestionnaire();
const { redirectToError } = useErrorRedirection();

const populateData = useCallback(async () => {
Expand All @@ -43,6 +46,9 @@ export default function Layout({ children }: { children: React.ReactNode }) {

const typesRes = await getAllTypes();
setQuestionTypes(typesRes.data);

const questionsRes = await GetAllQuestion();
if (questionsRes) setQuestionnaire(questionsRes.pop());
} catch (error) {
redirectToError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function ParticipantAnswersTablePDF({
participantAnswers: ParticipantAnswerReport[];
questionInfos: Question[];
}) {
console.log(
"QUESTION INFOS FROM THE PARTICIPANTANSWERS TABLE COMPONENT",
questionInfos
);
return (
<View>
<View>
Expand Down
Loading
Loading