Skip to content

Commit

Permalink
feat : add utils format title
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyofdev committed Oct 20, 2023
1 parent 560a7aa commit 9c58adc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/card/single-estate-card/SingleEstateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import useFetchEstate from '@hooks/useFetchEstate';
import useTheme from '@hooks/useTheme';
import { Box, Card, CardContent, CardMedia, Typography } from '@mui/material';
import { formatPrice } from '@utils/index';
import { formatPrice, formatTitle } from '@utils/index';
import defaultEstateImg from '../../../assets/estate.jpg';
import useStyles from './style';

Expand Down Expand Up @@ -48,7 +48,7 @@ const SingleEstateCard = ({
<Box sx={styles.topBox}>
<Box sx={styles.nameBox}>
<Typography variant='h4' sx={styles.title}>
{estate?.name}
{formatTitle(estate?.name)}
</Typography>

<Box sx={styles.addressBox}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/lists/estate-list/EstateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
SelectChangeEvent,
Typography,
} from '@mui/material';
import { formatPrice } from '@utils/index';
import { formatPrice, formatTitle } from '@utils/index';
import {
ChangeEvent,
Dispatch,
Expand Down Expand Up @@ -133,7 +133,7 @@ const EstateList = ({

<Box>
<Typography variant='h6' sx={styles.cardTitle}>
{estate.name}
{formatTitle(estate.name)}
</Typography>

<Typography
Expand Down
9 changes: 9 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ export const truncate = (text: string, limit: number): string => {
: `${text.split(' ').slice(0, limit).join(' ')}...`;
};

/**
* Format currency price
*/
export const formatPrice = (price: number, locales: string): string => {
const currencyFormat = new Intl.NumberFormat(locales);
return currencyFormat.format(price);
};

/**
* Format estate title
*/
export const formatTitle = (title: string): string =>
title.slice(0, 1).toUpperCase() + title.slice(1);

0 comments on commit 9c58adc

Please sign in to comment.