Skip to content

Commit

Permalink
Merge pull request #28 from copilot-platforms/OUT-62
Browse files Browse the repository at this point in the history
OUT-62 Image opt. and aspect ratio fixes in client preview
  • Loading branch information
aatbip authored Feb 28, 2024
2 parents 1800ab9 + 341a63d commit 6b766fe
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/app/client-preview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Handlebars from 'handlebars'
import { IClient, ISettings } from '@/types/interfaces'
import ClientPreview from '../components/ClientPreview'
import { apiUrl } from '@/config'
import Image from 'next/image'
import { defaultBannerImagePath } from '@/utils/constants'

Check warning on line 6 in src/app/client-preview/page.tsx

View workflow job for this annotation

GitHub Actions / Run linters

'defaultBannerImagePath' is defined but never used

Check warning on line 6 in src/app/client-preview/page.tsx

View workflow job for this annotation

GitHub Actions / Run linters

'defaultBannerImagePath' is defined but never used

export const revalidate = 0
Expand Down Expand Up @@ -55,20 +56,20 @@ export default async function ClientPreviewPage({
createdById: '',
}

const _settings = await getSettings(token)
const defaultSetting = await getSettings(token)

if (_settings) {
settings = _settings
if (defaultSetting) {
settings = defaultSetting
}

const _client = await getClient(clientId, token)
const defaultClient = await getClient(clientId, token)

const company = await getCompany(_client.companyId, token)
const company = await getCompany(defaultClient.companyId, token)

const template = Handlebars?.compile(settings?.content)

//add comma separator for custom fields
const customFields: any = _client?.customFields
const customFields: any = defaultClient?.customFields

Check warning on line 72 in src/app/client-preview/page.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected any. Specify a different type
for (const key in customFields) {
if (Array.isArray(customFields[key])) {
//element[0].toUpperCase() + element.substring(1) is a hack to capitalize the first string, however changes in SDK response
Expand All @@ -79,13 +80,16 @@ export default async function ClientPreviewPage({
}
}
const client = {
..._client,
...(Object.keys(customFields as object).length && customFields),
...defaultClient,
company: company.name,
}

const htmlContent = template({ client })

const bannerImgUrl = !defaultSetting
? '/images/default_banner.png'
: settings?.bannerImage?.url

return (
<div
className={`overflow-y-auto overflow-x-hidden max-h-screen w-full`}
Expand All @@ -94,12 +98,17 @@ export default async function ClientPreviewPage({
}}
>
{settings?.bannerImage?.url && (
<img
className='w-full object-fill xl:object-cover'
src={!_settings ? defaultBannerImagePath : settings?.bannerImage.url}
<Image
className='w-full'
src={bannerImgUrl || '/images/default_banner.png'}
alt='banner image'
width={0}
height={0}
sizes='100vw'
style={{
width: '100%',
height: '25vh',
objectFit: 'cover',
}}
/>
)}
Expand Down

0 comments on commit 6b766fe

Please sign in to comment.