Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit c7c822c

Browse files
committed
feat: Add exchange rate from PLN to USD, update price products
1 parent 4da14b1 commit c7c822c

File tree

19 files changed

+163
-44
lines changed

19 files changed

+163
-44
lines changed

app/[locale]/(main)/faq/layout.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { getTranslator } from 'next-intl/server';
33
import { Metadata } from 'next';
44

55
import { WrapperFaq } from '@/views/faq/wrapper/WrapperFaq';
6-
7-
import { CONFIG_TITLE } from '../../../../config';
6+
import { CONFIG } from '@/config';
87

98
interface MetadataProps {
109
params: {
@@ -18,7 +17,7 @@ export async function generateMetadata({ params: { locale } }: MetadataProps): P
1817
return {
1918
title: {
2019
default: t('faq'),
21-
template: `%s - ${t('faq')} - ${CONFIG_TITLE}`
20+
template: `%s - ${t('faq')} - ${CONFIG.title}`
2221
}
2322
};
2423
}

app/[locale]/(main)/products/(products)/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getTranslator } from 'next-intl/server';
22

33
import { ProductsView } from '@/views/products/ProductsView';
4+
import { CONFIG, ExchangeRateToUSD } from '@/config';
45

56
interface MetadataProps {
67
params: {
@@ -16,6 +17,15 @@ export async function generateMetadata({ params: { locale } }: MetadataProps) {
1617
};
1718
}
1819

19-
export default function Page() {
20-
return <ProductsView />;
20+
const fetchExchangeRateToUSD = async (): Promise<ExchangeRateToUSD> => {
21+
const current = await fetch(CONFIG.nbpAPI);
22+
23+
return current.json();
24+
};
25+
26+
export default async function Page() {
27+
const exchangeRateToUSD = await fetchExchangeRateToUSD();
28+
const current = exchangeRateToUSD.rates;
29+
30+
return <ProductsView oneUSDtoPLN={current.length > 0 ? current[0].mid : undefined} />;
2131
}

app/[locale]/(main)/products/[id]/page.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { notFound } from 'next/navigation';
33

44
import { ProductView } from '@/views/products/[id]/ProductView';
55
import { productsData } from '@/views/products/productsData';
6+
import { CONFIG, ExchangeRateToUSD } from '@/config';
67

78
interface Props {
89
params: {
@@ -27,12 +28,23 @@ export async function generateMetadata({ params: { id, locale } }: Props) {
2728
};
2829
}
2930

30-
export default function Page({ params: { id } }: Props) {
31+
const fetchExchangeRateToUSD = async (): Promise<ExchangeRateToUSD> => {
32+
const current = await fetch(CONFIG.nbpAPI);
33+
34+
return current.json();
35+
};
36+
37+
export default async function Page({ params: { id } }: Props) {
3138
const findProduct = productsData.find(product => product.id === id);
3239

3340
if (!findProduct) {
3441
notFound();
3542
}
3643

37-
return <ProductView {...findProduct} />;
44+
const exchangeRateToUSD = await fetchExchangeRateToUSD();
45+
const current = exchangeRateToUSD.rates;
46+
47+
return (
48+
<ProductView {...findProduct} oneUSDtoPLN={current.length > 0 ? current[0].mid : undefined} />
49+
);
3850
}

app/[locale]/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { HomeView } from '@/views/home/HomeView';
2+
import { CONFIG, ExchangeRateToUSD } from '@/config';
23

3-
export default function Page() {
4-
return <HomeView />;
4+
const fetchExchangeRateToUSD = async (): Promise<ExchangeRateToUSD> => {
5+
const current = await fetch(CONFIG.nbpAPI);
6+
7+
return current.json();
8+
};
9+
10+
export default async function Page() {
11+
const exchangeRateToUSD = await fetchExchangeRateToUSD();
12+
const current = exchangeRateToUSD.rates;
13+
14+
return <HomeView oneUSDtoPLN={current.length > 0 ? current[0].mid : undefined} />;
515
}

app/layout.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import '@/styles/global.scss';
33
import { Metadata } from 'next';
44
import { Analytics } from '@vercel/analytics/react';
55

6-
import { CONFIG_TITLE } from '../config';
6+
import { CONFIG } from '../config';
77

88
export function generateMetadata(): Metadata {
99
const desc =
1010
"I'm Maciej Piotr Balcerzak and I'm working as Software Engineer with a passion for creating beautiful and user-friendly products. I have experience in front-end, back-end, testing and UX/UI design, but my primary experience is front-end. Also I'm contributor for Invision Community making themes and apps.";
1111

1212
return {
1313
title: {
14-
default: CONFIG_TITLE,
15-
template: `%s - ${CONFIG_TITLE}`
14+
default: CONFIG.title,
15+
template: `%s - ${CONFIG.title}`
1616
},
1717
icons: {
1818
shortcut: '/icons/favicon.ico'
@@ -21,14 +21,14 @@ export function generateMetadata(): Metadata {
2121
themeColor: '#200706',
2222
metadataBase: new URL('https://axendev.net/'),
2323
openGraph: {
24-
title: CONFIG_TITLE,
24+
title: CONFIG.title,
2525
description: desc,
2626
images: [
2727
{
2828
url: '/icons/og.png',
2929
width: 1050,
3030
height: 350,
31-
alt: CONFIG_TITLE
31+
alt: CONFIG.title
3232
}
3333
]
3434
}

components/layout/footer/Footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import style from './Footer.module.scss';
66
import { Logo } from '@/assets/Logo';
77
import { SocialFooter } from './socials/SocialsFooter';
88
import { InfoFooter } from './info/InfoFooter';
9-
import { CONFIG_TITLE } from '@/config';
9+
import { CONFIG } from '@/config';
1010

1111
export const Footer = () => {
1212
const t = useTranslations('global');
@@ -15,7 +15,7 @@ export const Footer = () => {
1515
<footer className={style.main}>
1616
<div className={cx('layout_wrapper', style.wrapper)}>
1717
<div className={style.logo}>
18-
<Link href="/" aria-label={t('logo', { name: CONFIG_TITLE })}>
18+
<Link href="/" aria-label={t('logo', { name: CONFIG.title })}>
1919
<Logo />
2020
</Link>
2121

components/layout/header/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import style from './Header.module.scss';
66
import { Nav } from './nav/Nav';
77
import { Drawer } from './drawer/Drawer';
88
import { WrapperHeader } from './wrapper/WrapperHeader';
9-
import { CONFIG_TITLE } from '@/config';
9+
import { CONFIG } from '@/config';
1010

1111
import { Switches } from '../../switches/Switches';
1212

@@ -16,7 +16,7 @@ export const Header = () => {
1616
return (
1717
<WrapperHeader>
1818
<div className="layout_wrapper">
19-
<Link href="/" className={style.logo} aria-label={t('logo', { name: CONFIG_TITLE })}>
19+
<Link href="/" className={style.logo} aria-label={t('logo', { name: CONFIG.title })}>
2020
<Logo />
2121
</Link>
2222

components/switches/theme/ThemeSwitch.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useEffect, useState } from 'react';
1313
import { useTranslations } from 'next-intl';
1414

1515
import style from './ThemeSwitch.module.scss';
16-
import { CONFIG_LOCAL_STORAGE_THEME } from '@/config';
16+
import { CONFIG } from '@/config';
1717

1818
import { Tooltip } from '../../tooltip/Tooltip';
1919

@@ -28,7 +28,7 @@ export const ThemeSwitch = () => {
2828
const [theme, setTheme] = useState<ThemeType | null>(null);
2929

3030
useEffect(() => {
31-
const theme = localStorage.getItem(CONFIG_LOCAL_STORAGE_THEME);
31+
const theme = localStorage.getItem(CONFIG.local_storage_theme);
3232

3333
if (theme === ThemeType.light) {
3434
setTheme(ThemeType.light);
@@ -50,8 +50,8 @@ export const ThemeSwitch = () => {
5050
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
5151

5252
if (theme === ThemeType.system) {
53-
localStorage.removeItem(`${CONFIG_LOCAL_STORAGE_THEME}_manual`);
54-
localStorage.removeItem(CONFIG_LOCAL_STORAGE_THEME);
53+
localStorage.removeItem(`${CONFIG.local_storage_theme}_manual`);
54+
localStorage.removeItem(CONFIG.local_storage_theme);
5555

5656
if (checkDark) {
5757
document.documentElement.setAttribute('theme', 'dark');
@@ -64,8 +64,8 @@ export const ThemeSwitch = () => {
6464
return;
6565
}
6666

67-
localStorage.setItem(`${CONFIG_LOCAL_STORAGE_THEME}_manual`, '1');
68-
localStorage.setItem(CONFIG_LOCAL_STORAGE_THEME, theme);
67+
localStorage.setItem(`${CONFIG.local_storage_theme}_manual`, '1');
68+
localStorage.setItem(CONFIG.local_storage_theme, theme);
6969

7070
if (theme === ThemeType.dark) {
7171
document.documentElement.setAttribute('theme', 'dark');

config.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
export const CONFIG_LOCAL_STORAGE_THEME = 'aXenDev_theme';
1+
export const CONFIG = {
2+
nbpAPI: 'https://api.nbp.pl/api/exchangerates/rates/a/usd/?format=json',
3+
title: 'aXenDev',
4+
local_storage_theme: 'aXenDev_theme'
5+
};
26

3-
export const CONFIG_TITLE = 'aXenDev';
7+
export interface ExchangeRateToUSD {
8+
code: string;
9+
currency: string;
10+
rates: {
11+
effectiveDate: string;
12+
mid: number;
13+
no: string;
14+
}[];
15+
table: string;
16+
}

messages/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
"products": {
7777
"title": "Products",
7878
"desc": "Explore my products and find the one that suits you best.",
79+
"or": "or",
80+
"price_calc_info": "The price is calculated based on the PLN => USD current exchange rate.",
7981
"back": "Back to Products",
8082
"free": "Free",
8183
"buy_now_on": "Buy Now on {name}",

0 commit comments

Comments
 (0)