diff --git a/actions/shares/shares.ts b/actions/shares/shares.ts index e6d2616..fb3023d 100644 --- a/actions/shares/shares.ts +++ b/actions/shares/shares.ts @@ -4,6 +4,8 @@ import { IApiResponseShares, IFinancialInstrument, IPagination, + IApiResponseShareItem, + IInstrument, } from '@/typing'; /** @@ -38,11 +40,23 @@ export const getShares = async ( export const getSharesByTicker = async (ticker: string): Promise => { const { data } = await axios.get<{ - data: IFinancialInstrument[]; + data: IInstrument; }>(`${API_BASE_URL}/sharesByTicker`, { params: { ticker }, }); return { - data: data, + data, }; }; + +export const getLastPriceByTicker = async (ticker: string): Promise => { + const { data } = await axios.get<{ + data: IInstrument; + }>(`${API_BASE_URL}/lastPriceByTicker`, { + params: { ticker }, + }); + return { + data, + }; +}; + diff --git a/app/[slug]/page.tsx b/app/[slug]/page.tsx index cf4f3b5..961f83b 100644 --- a/app/[slug]/page.tsx +++ b/app/[slug]/page.tsx @@ -1,16 +1,14 @@ import React from 'react'; import styles from './styles.module.scss'; import { ShareIntro } from '@/components/ShareIntro'; -import { Button } from '@/components/Button'; +import { BuyStock } from '@/components/BuyStock'; import { serviceShares } from '@/services'; -const data = { - brand: { bg: '#1a5ea0', color: 'white' }, -}; - -const ItemPage = async ({ params }: { params: { slug: string } }) => { - const res = await serviceShares.getByTicker(params.slug); - console.log(res, res) +const PageStock = async ({ params }: { params: { slug: string } }) => { + const { data } = await serviceShares.getByTicker(params.slug); + const { data: dataLastPrice } = await serviceShares.getLastPriceByTicker( + params.slug, + ); return (
@@ -18,14 +16,10 @@ const ItemPage = async ({ params }: { params: { slug: string } }) => {
-
-
- -
-
+
); }; -export default ItemPage; +export default PageStock; diff --git a/app/[slug]/styles.module.scss b/app/[slug]/styles.module.scss index a814e28..ad201f4 100644 --- a/app/[slug]/styles.module.scss +++ b/app/[slug]/styles.module.scss @@ -7,8 +7,8 @@ .main { flex: 1; max-width: 920px; - margin-right: 120px; + margin-right: 30px; } .side { - + flex: 0 0 300px } diff --git a/app/globals.css b/app/globals.css index 00594d7..5629513 100644 --- a/app/globals.css +++ b/app/globals.css @@ -2,6 +2,7 @@ --box-max-width: 1100px; --body-font-size: 16px; --body-background-color: #f6f7f8; + --body-border-color: #d1d1e4; --body-text-color: #000000; --logo-background-color: #2196f3; --logo-text-color: #ffffff; diff --git a/app/loading.module.scss b/app/loading.module.scss index e69de29..eca16d1 100644 --- a/app/loading.module.scss +++ b/app/loading.module.scss @@ -0,0 +1,5 @@ +.page { + min-height: 775px; + max-width: var(--box-max-width); + margin: 0 auto; +} diff --git a/app/loading.tsx b/app/loading.tsx index f6d5976..ea9c59c 100644 --- a/app/loading.tsx +++ b/app/loading.tsx @@ -1,6 +1,8 @@ +import styles from './loading.module.scss'; + export default function Loading() { return ( -
+

Loading dashboard...

diff --git a/components/BuyStock/BuyStock.tsx b/components/BuyStock/BuyStock.tsx new file mode 100644 index 0000000..063bcba --- /dev/null +++ b/components/BuyStock/BuyStock.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import styles from './styles.module.scss'; + +interface Price { + units: string; + nano: number; +} + +interface PriceInfo { + figi: string; + price: Price; + time: string; + instrumentUid: string; + lastPriceType: string; +} + +export const BuyStock: React.FC<{ info: PriceInfo }> = ({ info }) => { + const formattedDate = new Date(info.time).toLocaleString(); + const formattedPrice = parseFloat( + `${info.price.units}.${info.price.nano / 1e9}`, + ).toFixed(2); + + return ( +
+
Date: {formattedDate}
+
Price: {formattedPrice}
+ +
+ ); +}; diff --git a/components/BuyStock/index.ts b/components/BuyStock/index.ts new file mode 100644 index 0000000..9550b1d --- /dev/null +++ b/components/BuyStock/index.ts @@ -0,0 +1 @@ +export * from './BuyStock'; diff --git a/components/BuyStock/styles.module.scss b/components/BuyStock/styles.module.scss new file mode 100644 index 0000000..2f0b9a1 --- /dev/null +++ b/components/BuyStock/styles.module.scss @@ -0,0 +1,21 @@ +.box { + padding: 20px; + border: 1px solid #ccc; + border-radius: 5px; + width: 300px; + text-align: center; +} + +.buyButton { + margin-top: 15px; + padding: 10px 20px; + background-color: #4caf50; + color: white; + border: none; + border-radius: 5px; + cursor: pointer; +} + +.buyButton:hover { + background-color: #45a049; +} diff --git a/components/Profile/ProfileBalance/ProfileBalance.tsx b/components/Profile/ProfileBalance/ProfileBalance.tsx index cb377d9..04311df 100644 --- a/components/Profile/ProfileBalance/ProfileBalance.tsx +++ b/components/Profile/ProfileBalance/ProfileBalance.tsx @@ -1,5 +1,5 @@ import { FC } from 'react'; export const ProfileBalance: FC = () => { - return 1000 $; + return 1000; }; diff --git a/components/ShareIntro/ShareIntro.tsx b/components/ShareIntro/ShareIntro.tsx index 5d289e9..74df3f0 100644 --- a/components/ShareIntro/ShareIntro.tsx +++ b/components/ShareIntro/ShareIntro.tsx @@ -1,30 +1,21 @@ import React from 'react'; import styles from './styles.module.scss'; -import { IFinancialInstrument } from '@/typing'; import { generateGradient } from '@/utils'; -type Props = { - value: IFinancialInstrument; -}; - -export const ShareIntro = ({ value }: Props) => { +export const ShareIntro = ({ value }: any) => { return (
-
APPLE
+
{value.name}
-
-
Profitability for six months
-
6%
-
Sector
-
Financial sector
+
{value.sector}
diff --git a/services/shares/index.ts b/services/shares/index.ts index d001361..04c66d3 100644 --- a/services/shares/index.ts +++ b/services/shares/index.ts @@ -1,4 +1,4 @@ -import { getShares, getSharesByTicker } from '@/actions/shares'; +import { getLastPriceByTicker, getShares, getSharesByTicker } from '@/actions/shares'; import { IApiResponseShares, IPagination } from '@/typing'; class ServiceShares { @@ -20,6 +20,14 @@ class ServiceShares { } catch (e) {} } + async getLastPriceByTicker(ticker: string) { + try { + const res = await getLastPriceByTicker(ticker); + return res; + } catch (e) {} + } + + handleError(err: Error) {} } diff --git a/typing/index.ts b/typing/index.ts index 29c4cad..1f7db27 100644 --- a/typing/index.ts +++ b/typing/index.ts @@ -63,7 +63,7 @@ export interface IInstBrand { textColor: string; } -interface IInstrument { +export interface IInstrument { figi: string; ticker: string; classCode: string; @@ -101,3 +101,20 @@ interface IInstrument { first1dayCandleDate: string; brand: IBrand; } + +export interface IApiResponseShareItem { + data: IInstrument; +} + +export interface IPrice { + units: string; + nano: number; +} + +export interface IPriceInfo { + figi: string; + price: IPrice; + time: string; + instrumentUid: string; + lastPriceType: string; +}