Skip to content

Commit

Permalink
Merge branch 'main' into eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-ao committed Jul 29, 2024
2 parents e7d1bc6 + 4d8a253 commit 2366a59
Show file tree
Hide file tree
Showing 49 changed files with 1,232 additions and 633 deletions.
2 changes: 1 addition & 1 deletion .env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ AUTH0_CLIENT_SECRET=#client secret
AUTH0_ISSUER=#issuer base url, example: example.us.auth0.com

AWS_SECRET_ACCESS_KEY=#aws secret access key
AWS_ACCESS_KEY_ID=#aws access key id
AWS_ACCESS_KEY_ID=#aws access key id
5 changes: 2 additions & 3 deletions algorithm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ cd algorithm
python -m venv ".venv"
```

Lag så en fil i `.\.venv\Lib\site-packages` som slutter på `.pth` og inneholder den absolutte filstien til `mip_matching`-mappen.

```
.\.venv\Scripts\activate
python -m pip install -r requirements.txt
pip install -e .
pip install -r requirements.txt
```

## TODOs
Expand Down
2 changes: 2 additions & 0 deletions algorithm/bridge/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGODB_URI=#url to mongodb database
DB_NAME=#name of db
76 changes: 76 additions & 0 deletions algorithm/bridge/fetch_applicants_and_committees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from pymongo import MongoClient
from dotenv import load_dotenv
from datetime import datetime, timezone
import os
import certifi

def main():
periods = fetch_periods()

#Sjekker om perioden er etter søknadstiden og før intervjuslutt og hasSentInterviewtimes er false, og returnerer søkere og komitétider dersom det er tilfelle
for period in periods:
periodId = str(period["_id"])
interview_end = datetime.fromisoformat(period["interviewPeriod"]["end"].replace("Z", "+00:00"))
application_end = datetime.fromisoformat(period["applicationPeriod"]["end"].replace("Z", "+00:00"))


now = datetime.now(timezone.utc)

if application_end > now and period["hasSentInterviewTimes"] == False and interview_end < now:
applicants = fetch_applicants(periodId)
committee_times = fetch_committee_times(periodId)
print(applicants)
print(committee_times)

return applicants, committee_times


def connect_to_db(collection_name):
load_dotenv()

mongo_uri = os.getenv("MONGODB_URI")
db_name = os.getenv("DB_NAME")

client = MongoClient(mongo_uri, tlsCAFile=certifi.where())

db = client[db_name] # type: ignore

collection = db[collection_name]

return collection, client

def fetch_periods():
collection, client = connect_to_db("period")

periods = collection.find()

periods = list(periods)

client.close()

return periods

def fetch_applicants(periodId):
collection, client = connect_to_db("applicant")

applicants = collection.find({"periodId": periodId})

applicants = list(applicants)

client.close()

return applicants

def fetch_committee_times(periodId):
collection, client = connect_to_db("committee")

committee_times = collection.find({"periodId": periodId})

committee_times = list(committee_times)

client.close()

return committee_times

if __name__ == "__main__":
main()
Binary file modified algorithm/requirements.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions algorithm/src/mip_matching/Applicant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
# Unngår cyclic import
from Committee import Committee
from TimeInterval import TimeInterval
from mip_matching.Committee import Committee
from mip_matching.TimeInterval import TimeInterval

import itertools

Expand Down
23 changes: 23 additions & 0 deletions components/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Image from "next/image";
import { useTheme } from "../lib/hooks/useTheme";

const ErrorPage = () => {
const theme = useTheme();

const onlineLogoSrc =
theme === "dark" ? "/Online_hvit.svg" : "/Online_bla.svg";

return (
<div className="flex flex-col items-center justify-center h-full gap-10 bg-white dark:bg-gray-900">
<Image
src={onlineLogoSrc}
width={300}
height={100}
alt="Online logo"
/>
<div className="text-xl text-black dark:text-white">Det har skjedd en feil :(</div>
</div>
);
};

export default ErrorPage;
9 changes: 4 additions & 5 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ const Navbar = () => {
<div>
<div className="hidden md:flex justify-between w-full px-5 py-5 sm:items-center border-b-[1px] border-gray-200 dark:border-0 dark:bg-gray-800">
<Link href="/" passHref>
<a
aria-label="Online logo"
>
<a aria-label="Online logo">
<Image
src={onlineLogoSrc}
width={100 * 1.5}
height={30 * 1.5}
priority
alt="Online logo"
className="transition-all cursor-pointer hover:opacity-60"
/>
Expand All @@ -65,7 +64,7 @@ const Navbar = () => {
href="/admin"
/>
)}
{session.user?.isCommitee && (
{session.user?.isCommittee && (
<Button
title="For komiteer"
color="blue"
Expand Down Expand Up @@ -102,7 +101,7 @@ const Navbar = () => {
height={30 * 1.5}
alt="Bekk logo"
className="transition-all cursor-pointer hover:opacity-60"
/>
/>
</a>
</Link>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/PageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const PageTitle = ({
{mainTitle}
</h2>
{subTitle && (
<p className="text-xl text-gray-500 dark:text-gray-400">
<div className="text-xl text-gray-500 dark:text-gray-400">
{boldSubTitle && <span className="font-semibold">{boldSubTitle}{boldSubTitle && subTitle && ":"}&nbsp;</span>}
{subTitle}
</p>
</div>
)}
</div>
</div>
Expand Down
28 changes: 13 additions & 15 deletions components/PeriodCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { periodType } from "../lib/types/types";
import { formatDateNorwegian } from "../lib/utils/dateUtils";
import Button from "./Button";
import CheckIcon from "./icons/icons/CheckIcon";
import { useQuery } from "@tanstack/react-query";
import { fetchApplicantByPeriodAndId } from "../lib/api/applicantApi";
import { PeriodSkeleton } from "./PeriodSkeleton";

interface Props {
period: periodType;
Expand All @@ -13,23 +16,18 @@ const PeriodCard = ({ period }: Props) => {
const { data: session } = useSession();
const [hasApplied, setHasApplied] = useState(false);

useEffect(() => {
const checkApplicationStatus = async () => {
if (session?.user?.owId) {
const response = await fetch(
`/api/applicants/${period._id}/${session.user.owId}`
);
if (response.ok) {
const data = await response.json();
setHasApplied(data.exists);
}
}
};
const { data: applicantData, isLoading: applicantIsLoading } = useQuery({
queryKey: ["applicants", period._id, session?.user?.owId],
queryFn: fetchApplicantByPeriodAndId,
});

if (period._id && session?.user?.owId) {
checkApplicationStatus();
useEffect(() => {
if (applicantData) {
setHasApplied(applicantData.exists);
}
}, [period._id, session?.user?.owId]);
}, [applicantData]);

if (applicantIsLoading) return <PeriodSkeleton />;

return (
<div className="relative w-full max-w-md mx-auto break-words border rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 dark:text-white">
Expand Down
27 changes: 27 additions & 0 deletions components/PeriodSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const PeriodSkeleton = () => {
return (
<div className="w-full max-w-md p-4 border border-gray-200 rounded shadow animate-pulse md:p-6 dark:border-gray-700 ">
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>
</div>
);
};

export const PeriodSkeletonPage = () => {
return (
<div className="flex flex-col justify-between overflow-x-hidden text-online-darkBlue dark:text-white">
<div className="flex flex-col items-center justify-center gap-5 px-5 my-10">
<div className="flex flex-col gap-10">
<h3 className="text-4xl font-bold tracking-tight text-center dark:text-white">
Nåværende opptaksperioder
</h3>
<div className="flex flex-col items-center max-w-full gap-5">
<PeriodSkeleton />
</div>
</div>
</div>
</div>
);
};
18 changes: 9 additions & 9 deletions components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const Table = ({ rows, columns, onDelete }: TableProps) => {
const router = useRouter();

return (
<div className="">
<div className="hidden md:flex overflow-auto border border-gray-200 rounded-lg shadow-md dark:border-gray-700">
<>
<div className="hidden overflow-auto border border-gray-200 rounded-lg shadow-md md:flex dark:border-gray-700">
<table className="w-full text-gray-500 border-collapse dark:bg-online-darkBlue dark:text-gray-200">
<thead className="bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
Expand All @@ -36,16 +36,16 @@ const Table = ({ rows, columns, onDelete }: TableProps) => {
{column.label}
</th>
) : (
<div className="px-10 py-2"></div>
<th className="px-10 py-2"></th>
)}
</React.Fragment>
))}
</tr>
</thead>
<tbody className="border-t border-gray-100 dark:border-0">
{rows.map((row) => (
{rows.map((row, index) => (
<tr
key={"tr-" + row.id}
key={"tr-" + index}
className="relative cursor-pointer hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-900 dark:border-gray-700"
onClick={() => row.link && router.push(row.link)}
>
Expand Down Expand Up @@ -78,12 +78,12 @@ const Table = ({ rows, columns, onDelete }: TableProps) => {
</tbody>
</table>
</div>
<div className="md:hidden flex flex-col space-y-4">
{rows.map((row) => (
<TableCard key={row.id} period={row} onDelete={onDelete} />
<div className="flex flex-col space-y-4 md:hidden">
{rows.map((row, index) => (
<TableCard key={"TableCard-" + index} period={row} onDelete={onDelete} />
))}
</div>
</div>
</>
);
};

Expand Down
4 changes: 3 additions & 1 deletion components/applicantoverview/ApplicantCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const ApplicantCard = ({ applicant, includePreferences }: Props) => {
)}

<h1 className="text-lg font-semibold pt-3">Om:</h1>
<p>Bankom: {getBankomValue(applicant?.bankom)}</p>
<p>
Ønsker å være økonomiansvarlig: {getBankomValue(applicant?.bankom)}
</p>
<div className="p-4 mt-2 bg-gray-100 rounded-lg dark:bg-gray-700">
<p className="whitespace-pre-wrap">{applicant?.about}</p>
</div>
Expand Down
Loading

0 comments on commit 2366a59

Please sign in to comment.