|
| 1 | +import React from 'react' |
| 2 | +import styled from 'styled-components' |
| 3 | +import Linkify from 'react-linkify' |
| 4 | +import PageTitle from '../../../components/core/PageTitle' |
| 5 | +import { ISponsorDetail, ISponsorListItem } from '../../../interfaces/ISponsor' |
| 6 | +import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next' |
| 7 | +import { getSponsorDetail } from '../../api/sponsor' |
| 8 | +import { LocalePage } from '../../../interfaces/PageProps' |
| 9 | +import { useTranslation } from 'react-i18next' |
| 10 | +import { media } from '../../../assets/styles/mixin' |
| 11 | + |
| 12 | +interface SponsorDetailProps extends LocalePage<ISponsorDetail> { |
| 13 | + locale: string |
| 14 | +} |
| 15 | + |
| 16 | +const SponsorImage = styled.img` |
| 17 | + display: block; |
| 18 | + margin: 0 auto; |
| 19 | + max-width: 400px; |
| 20 | + margin-top: 4rem; |
| 21 | + ${media.mobile(` |
| 22 | + width: 100%; |
| 23 | + `)} |
| 24 | +` |
| 25 | +const SponsorUrl = styled.a` |
| 26 | + display: block; |
| 27 | + margin-top: 2rem; |
| 28 | + color: ${(props) => props.theme.colors.blue0}; |
| 29 | + &:hover { |
| 30 | + text-decoration: underline; |
| 31 | + } |
| 32 | +` |
| 33 | +const SponsorContent = styled.p` |
| 34 | + white-space: pre-wrap; |
| 35 | + margin-top: 6rem; |
| 36 | + a { |
| 37 | + color: ${(props) => props.theme.colors.blue0}; |
| 38 | + } |
| 39 | + ${media.mobile(` |
| 40 | + margin-top: 4rem; |
| 41 | + `)} |
| 42 | +` |
| 43 | + |
| 44 | +const SponsorDetail: NextPage = (props: SponsorDetailProps) => { |
| 45 | + const { t } = useTranslation() |
| 46 | + const sponsor: ISponsorListItem = props[props.locale] |
| 47 | + |
| 48 | + return ( |
| 49 | + <> |
| 50 | + <PageTitle title={sponsor.name} /> |
| 51 | + <SponsorImage src={sponsor.logo_image} alt={sponsor.name} /> |
| 52 | + {!sponsor.url ?? ( |
| 53 | + <SponsorUrl href={sponsor.url}>{sponsor.url}</SponsorUrl> |
| 54 | + )} |
| 55 | + <SponsorContent> |
| 56 | + <Linkify>{sponsor.desc}</Linkify> |
| 57 | + </SponsorContent> |
| 58 | + </> |
| 59 | + ) |
| 60 | +} |
| 61 | + |
| 62 | +export const getServerSideProps: GetServerSideProps = async ( |
| 63 | + context: GetServerSidePropsContext |
| 64 | +) => { |
| 65 | + const { locale, params } = context |
| 66 | + try { |
| 67 | + const data = await getSponsorDetail(params?.id as string) |
| 68 | + |
| 69 | + // TODO: Apply locale |
| 70 | + return { |
| 71 | + props: { |
| 72 | + locale, |
| 73 | + ko: data, |
| 74 | + en: data |
| 75 | + } |
| 76 | + } |
| 77 | + } catch (error) { |
| 78 | + // TODO: Return custom error message |
| 79 | + return { |
| 80 | + notFound: true |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +export default SponsorDetail |
0 commit comments