Skip to content

Commit

Permalink
Merge pull request #121 from NikDoe/feature/user-housted-info
Browse files Browse the repository at this point in the history
  • Loading branch information
NikDoe authored Oct 10, 2024
2 parents b6c1e64 + 15df500 commit dda8e62
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
14 changes: 8 additions & 6 deletions app/stays/[stayId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PageContainer, ShareButton, ImageContainer, BookingCalendar } from '@/components/common';
import { PageContainer, ShareButton, ImageContainer, BookingCalendar, UserInfo } from '@/components/common';
import { FavoriteToggleButton, Rating } from '@/components/mainPages';
import { StayDetails } from '@/components/mainPages/staysPage';
import { Separator } from '@/components/ui/separator';
Expand Down Expand Up @@ -45,9 +45,14 @@ async function SingleStayPage({ params }: SingleStayPageProps) {
beds,
bedrooms,
baths,
guests
guests,
profile
} = stay;
const details = { beds, bedrooms, baths, guests };
const profileData = {
profileImage: profile.profileImage,
username: profile.displayName
};

const country = findCountryByCode(countryCode);

Expand All @@ -72,10 +77,7 @@ async function SingleStayPage({ params }: SingleStayPageProps) {
<ImageContainer mainImage={image} name={title} />
<section className='lg:grid lg:grid-cols-12 gap-x-12 mt-12'>
<div className='lg:col-span-8'>
<p className='text-muted-foreground'>
размещено
<span className='text-foreground'> NikDoe</span>
</p>
<UserInfo profileData={profileData} />
<Separator className='h-[0.5px] my-6' />
<StayDetails details={details} />
</div>
Expand Down
35 changes: 35 additions & 0 deletions components/common/UserInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Image from 'next/image';

type UserInfoProps = {
profileData: {
profileImage: string;
username: string;
};
};

function UserInfo({ profileData }: UserInfoProps) {
const { profileImage, username } = profileData;

return (
<article className='grid grid-cols-[auto,1fr] gap-4'>
<Image
src={profileImage}
alt={username}
width={50}
height={50}
className='rounded-md w-12 h-12 object-cover'
/>
<div className='text-muted-foreground'>
<p>
размещено
<span className='font-bold text-foreground'> {username}</span>
</p>
<p>
2 года назад
</p>
</div>
</article>
);
}

export default UserInfo;
3 changes: 2 additions & 1 deletion components/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as BreadCrumbs } from './BreadCrumbs';
export { default as PageContainer } from './PageContainer';
export { default as ShareButton } from './ShareButton';
export { default as ImageContainer } from './ImageContainer';
export { default as BookingCalendar } from './BookingCalendar';
export { default as BookingCalendar } from './BookingCalendar';
export { default as UserInfo } from './UserInfo';
5 changes: 3 additions & 2 deletions components/form/CountriesInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client';

import { Label } from '@/components/ui/label';
import { formattedCountries, truncateCountryName } from '@/utils/countries';
import { formattedCountries } from '@/utils/countries';
import { formatText } from '@/utils/format';
import {
Select,
SelectContent,
Expand Down Expand Up @@ -34,7 +35,7 @@ function CountriesInput({ placeholder }: { placeholder?: string }) {
key={item.code}
value={item.code}
>
{truncateCountryName(item.name, COUNTRY_NAME_MAX_LENGTH)}
{formatText(item.name, COUNTRY_NAME_MAX_LENGTH)}
</SelectItem>
);
})}
Expand Down
8 changes: 5 additions & 3 deletions components/mainPages/staysPage/StayCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { StayCardProps } from '@/utils/types';
import Link from 'next/link';
import Image from 'next/image';
import { formatCurrency } from '@/utils/format';
import { Separator } from '@/components/ui/separator';
import StayCardAmenities from './StayCardAmenities';
import Rating from '../common/Rating';

import { StayCardProps } from '@/utils/types';
import { STAY_TITLE_MAX_LENGTH } from '@/utils/constants';
import { formatCurrency, formatText } from '@/utils/format';

type Props = {
stay: StayCardProps;
}
Expand All @@ -28,7 +30,7 @@ function StayCard({ stay }: Props) {
</div>
<div className='p-6'>
<h1 className='text-lg font-semibold mb-4'>
{stayTitle.substring(0, 25) + '...'}
{formatText(stayTitle, STAY_TITLE_MAX_LENGTH)}
</h1>
<StayCardAmenities cardAmenities={cardAmenities} />
<Separator className='h-[0.5px] my-4' />
Expand Down
1 change: 1 addition & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const TEXTAREA_DEFAULT_ROWS_NUMBER = 5;

//CREATE STAY FORM
export const COUNTRY_NAME_MAX_LENGTH = 34;
export const STAY_TITLE_MAX_LENGTH = 25;
export const DEFAULT_ARRAY_LENGTH = 4;
export const DEFAULT_STAY_PRICE = 100;
export const COUNTRY_TRANSLATION_LANGUAGE = 'rus';
8 changes: 0 additions & 8 deletions utils/countries.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import countries from 'world-countries';
import { COUNTRY_TRANSLATION_LANGUAGE } from './constants';

export function truncateCountryName(str: string, maxLength: number = 20): string {
if (str.length > maxLength) {
return str.slice(0, maxLength) + '...';
}

return str;
}

export const formattedCountries = countries.map((item) => ({
code: item.cca2,
name: item.translations[COUNTRY_TRANSLATION_LANGUAGE].common,
Expand Down
8 changes: 8 additions & 0 deletions utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ export const formatCurrency = (amount: number | null) => {
maximumFractionDigits: 0,
}).format(value);
};

export const formatText = (str: string, maxLength: number = 20): string => {
if (str.length > maxLength) {
return str.slice(0, maxLength) + '...';
}

return str;
};

0 comments on commit dda8e62

Please sign in to comment.