Skip to content

Commit 330fc2d

Browse files
authored
make it possible to see upcoming periods (#364)
* show upcoming periods * edit skeleton * remove apply button from upcoming periods * format
1 parent b653e02 commit 330fc2d

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

components/PeriodCard.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import { PeriodSkeleton } from "./PeriodSkeleton";
1010

1111
interface Props {
1212
period: periodType;
13+
active: boolean;
1314
}
1415

15-
const PeriodCard = ({ period }: Props) => {
16+
const PeriodCard = ({ period, active }: Props) => {
1617
const { data: session } = useSession();
1718
const [hasApplied, setHasApplied] = useState(false);
1819

@@ -56,12 +57,14 @@ const PeriodCard = ({ period }: Props) => {
5657
</span>
5758
)}
5859
<div className="flex justify-center mt-4">
59-
<Button
60-
title={hasApplied ? "Se søknad" : "Søk nå"}
61-
size="small"
62-
color="white"
63-
href={`/apply/${period._id}`}
64-
/>
60+
{active ?
61+
<Button
62+
title={hasApplied ? "Se søknad" : "Søk nå"}
63+
size="small"
64+
color="white"
65+
href={`/apply/${period._id}`}
66+
/> : <></>
67+
}
6568
</div>
6669
</div>
6770
</div>

components/PeriodSkeleton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const PeriodSkeleton = () => {
1414
export const PeriodSkeletonPage = () => {
1515
return (
1616
<div className="flex flex-col gap-10 my-10">
17-
<SimpleTitle title="Nåværende opptaksperioder" />
1817
<div className="flex flex-col items-center max-w-full gap-5">
1918
<PeriodSkeleton />
2019
</div>

pages/apply/index.tsx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SimpleTitle } from "../../components/Typography";
1010

1111
const Apply = () => {
1212
const [currentPeriods, setCurrentPeriods] = useState<periodType[]>([]);
13+
const [upcomingPeriods, setUpcomingPeriods] = useState<periodType[]>([])
1314

1415
const {
1516
data: periodsData,
@@ -33,6 +34,14 @@ const Apply = () => {
3334
return startDate <= today && endDate >= today;
3435
})
3536
);
37+
38+
setUpcomingPeriods(
39+
periodsData.periods.filter((period: periodType) => {
40+
const startDate = new Date(period.applicationPeriod.start || "");
41+
42+
return startDate >= today
43+
})
44+
)
3645
}, [periodsData]);
3746

3847
if (periodsIsLoading) return <PeriodSkeletonPage />;
@@ -41,7 +50,7 @@ const Apply = () => {
4150
return (
4251
<div className="flex flex-col justify-between overflow-x-hidden text-online-darkBlue dark:text-white">
4352
<div className="flex flex-col items-center justify-center gap-5 px-5">
44-
{currentPeriods.length === 0 ? (
53+
{currentPeriods.length === 0 && upcomingPeriods.length === 0 ? (
4554
<div className="flex flex-col items-center justify-center gap-8">
4655
<SimpleTitle title="Ingen åpne opptak for øyeblikket" />
4756
<p className="w-10/12 max-w-2xl text-center text-md ">
@@ -74,15 +83,30 @@ const Apply = () => {
7483
</p>
7584
</div>
7685
) : (
77-
<div className="flex flex-col gap-10">
78-
<SimpleTitle title="Nåværende opptaksperioder" />
79-
<div className="flex flex-col items-center max-w-full gap-5">
80-
{currentPeriods.map((period: periodType, index: number) => (
81-
<PeriodCard key={index} period={period} />
82-
))}
83-
</div>
84-
</div>
85-
)}
86+
<>
87+
{currentPeriods.length > 0 ? (
88+
<div className="flex flex-col gap-10">
89+
<SimpleTitle title="Nåværende opptaksperioder" />
90+
<div className="flex flex-col items-center max-w-full gap-5">
91+
{currentPeriods.map((period: periodType, index: number) => (
92+
<PeriodCard key={index} period={period} active={true} />
93+
))}
94+
</div>
95+
</div>
96+
) : <></>}
97+
{upcomingPeriods.length > 0 ? (
98+
<div className="flex flex-col gap-10 mt-16">
99+
<SimpleTitle title="Kommende opptaksperioder" />
100+
<div className="flex flex-col items-center max-w-full gap-5">
101+
{upcomingPeriods.map((period: periodType, index: number) => (
102+
<PeriodCard key={index} period={period} active={false} />
103+
))}
104+
</div>
105+
</div>
106+
) : <></>}
107+
</>
108+
)
109+
}
86110
</div>
87111
</div>
88112
);

0 commit comments

Comments
 (0)