-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into KB-225-Block-campus-functionality-if-student-…
…not-signed-Code-of-Honor # Conflicts: # src/app/[locale]/(private)/profile/profile.tsx
- Loading branch information
Showing
34 changed files
with
610 additions
and
169 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use server'; | ||
|
||
import { campusFetch } from '@/lib/client'; | ||
import { Announcement } from '@/types/announcement'; | ||
|
||
export const getAnnouncements = async () => { | ||
try { | ||
const response = await campusFetch<Announcement[]>('announcements'); | ||
|
||
if (!response.ok) { | ||
return []; | ||
} | ||
|
||
return response.json(); | ||
} catch (error) { | ||
return []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/app/[locale]/(private)/cards/announcements-card/announcement-slide.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client'; | ||
|
||
import { useTranslations } from 'next-intl'; | ||
import Link from 'next/link'; | ||
import { Heading3 } from '@/components/typography/headers'; | ||
import { Paragraph } from '@/components/typography/paragraph'; | ||
import { AspectRatio } from '@/components/ui/aspect-ratio'; | ||
import { Button } from '@/components/ui/button'; | ||
import { cn } from '@/lib/utils'; | ||
|
||
interface AnnouncementSlideProps { | ||
title: React.ReactNode; | ||
description: React.ReactNode; | ||
link?: string; | ||
linkTitle?: string; | ||
image?: string; | ||
} | ||
|
||
export const AnnouncementSlide = ({ title, description, link, linkTitle, image }: AnnouncementSlideProps) => { | ||
const t = useTranslations('private.main.cards.carousel'); | ||
|
||
return ( | ||
<div className="flex flex-col gap-8 lg:flex-row"> | ||
<div className="mb-4 max-w-full grow overflow-y-hidden"> | ||
<Heading3>{title}</Heading3> | ||
<Paragraph | ||
className={cn('mb-0 grow', { | ||
'line-clamp-[6] lg:line-clamp-[6] xl:line-clamp-[8]': !!link, | ||
'line-clamp-[8] lg:line-clamp-[7] xl:line-clamp-[9]': !link, | ||
})} | ||
> | ||
{description} | ||
</Paragraph> | ||
{link && ( | ||
<Button variant="secondary" className="mt-4" asChild> | ||
<Link href={link} target="_blank" rel="noopener noreferrer"> | ||
{linkTitle || t('default-link-title')} | ||
</Link> | ||
</Button> | ||
)} | ||
</div> | ||
<div className={cn('hidden min-w-[300px] basis-[300px] lg:block xl:min-w-[400px] xl:basis-[400px]')}> | ||
<AspectRatio ratio={4 / 3.5}> | ||
{image && <img src={image} alt={title as string} className="h-full w-full rounded-md object-cover" />} | ||
</AspectRatio> | ||
</div> | ||
</div> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/app/[locale]/(private)/cards/announcements-card/announcements-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getAnnouncements } from '@/actions/announcement.actions'; | ||
import { AnnouncementsCarousel } from './announcements-carousel'; | ||
import { Card, CardContent } from '@/components/ui/card'; | ||
import { cn } from '@/lib/utils'; | ||
|
||
interface AnnouncementsCardProps { | ||
className?: string; | ||
} | ||
|
||
export const AnnouncementsCard = async ({ className }: AnnouncementsCardProps) => { | ||
const announcements = await getAnnouncements(); | ||
|
||
return ( | ||
<Card className={cn(className)}> | ||
<CardContent className="flex h-full gap-8 space-y-1.5 p-10"> | ||
<AnnouncementsCarousel announcements={announcements} /> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; |
54 changes: 54 additions & 0 deletions
54
src/app/[locale]/(private)/cards/announcements-card/announcements-carousel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use client'; | ||
|
||
import { Carousel, CarouselApi, CarouselContent, CarouselItem } from '@/components/ui/carousel'; | ||
|
||
import Autoplay from 'embla-carousel-autoplay'; | ||
import { AnnouncementSlide } from './announcement-slide'; | ||
import { Announcement } from '@/types/announcement'; | ||
import { DotButton } from './dot-button'; | ||
import { useState } from 'react'; | ||
import { useDotButton } from './use-dot-button'; | ||
import { DefaultAnnouncementSlide } from './default-announcement-slide'; | ||
|
||
const AUTOPLAY_DELAY = 10_000; // 10 seconds | ||
|
||
interface AnnouncementsCarouselProps { | ||
announcements: Announcement[]; | ||
} | ||
|
||
const Slide = ({ children }: { children: React.ReactNode }) => <CarouselItem className="pl-4">{children}</CarouselItem>; | ||
|
||
export const AnnouncementsCarousel = ({ announcements }: AnnouncementsCarouselProps) => { | ||
const [api, setApi] = useState<CarouselApi>(); | ||
const { selectedIndex, scrollSnaps, onDotButtonClick } = useDotButton(api); | ||
|
||
return ( | ||
<Carousel | ||
opts={{ loop: true, align: 'center' }} | ||
plugins={[Autoplay({ delay: AUTOPLAY_DELAY })]} | ||
className="w-full" | ||
setApi={setApi} | ||
> | ||
<CarouselContent className="-ml-4 mb-4"> | ||
<Slide> | ||
<DefaultAnnouncementSlide /> | ||
</Slide> | ||
{announcements.map((announcement) => ( | ||
<Slide key={announcement.id}> | ||
<AnnouncementSlide | ||
title={announcement.title} | ||
description={announcement.description} | ||
link={announcement.link} | ||
image={announcement.image} | ||
/> | ||
</Slide> | ||
))} | ||
</CarouselContent> | ||
<div className="absolute -bottom-4 -left-4 flex gap-[8px]"> | ||
{scrollSnaps.map((_, index) => ( | ||
<DotButton key={index} onClick={() => onDotButtonClick(index)} selected={selectedIndex === index} /> | ||
))} | ||
</div> | ||
</Carousel> | ||
); | ||
}; |
Oops, something went wrong.