Skip to content

Commit

Permalink
add fallback for tender details
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Feb 22, 2024
1 parent 1765165 commit 5a8091d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 61 deletions.
2 changes: 1 addition & 1 deletion components/_shared/DList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const DList = ({ content }) => {
</span>
)}
</dt>
<dd className="dlist__desc">{value.desc}</dd>
<dd className="dlist__desc">{value.desc || '--'}</dd>
</div>
);
})}
Expand Down
104 changes: 47 additions & 57 deletions components/datasets/ContractDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,116 +13,114 @@ export const ContractDetails = ({ dataPackage }) => {
const basicContent = [
{
title: 'Open contracting ID',
desc: dataPackage.ocid || '--',
desc: dataPackage?.ocid,
},
{
title: 'Tender Title',
desc: dataPackage.tender[0].title || '--',
desc: dataPackage?.tender?.[0].title,
},
{
title: 'Tender ID',
desc: dataPackage.tender[0].id || '--',
desc: dataPackage?.tender?.[0].id,
},
{
title: 'Tender Reference Number',
desc: dataPackage.tender[0].identifiers[0].id || '--',
desc: dataPackage?.tender?.[0].identifiers?.[0].id,
},

{
title: 'Organisation Chain',
desc: dataPackage.buyer[0].name || '--',
desc: dataPackage?.buyer?.[0].name,
},
{
title: 'Tender amount',
desc: dataPackage.tender[0].value
? `${dataPackage.tender[0].value[0].currency} ${commaNumber(
dataPackage.tender[0].value[0].amount
desc: dataPackage?.tender?.[0].value
? `${dataPackage?.tender?.[0].value?.[0].currency} ${commaNumber(
dataPackage?.tender?.[0].value?.[0].amount
)}`
: '--',
: undefined,
},
{
title: 'Tender Category',
desc:
dataPackage.tender[0].items[0].classification[0].description || '--',
desc: dataPackage?.tender?.[0].items?.[0].classification?.[0]
.description,
},
];

const dateContent = dataPackage.tender[0].milestones.map(
(milestone: any) => {
return {
title: milestone.title,
desc: milestone.dueDate,
};
}
);
const dateContent = dataPackage?.tender?.[0].milestones
? dataPackage.tender[0].milestones.map((milestone: any) => {
return {
title: milestone.title,
desc: milestone.dueDate,
};
})
: [];

const tenderDetails = [
{
title: 'Work Description',
desc: dataPackage.tender[0].description || '--',
desc: dataPackage?.tender?.[0].description,
},
{
title: 'Product Category',
desc:
dataPackage.tender[0].items[0].classification[0].description || '--',
desc: dataPackage?.tender?.[0].items?.[0].classification?.[0]
.description,
},
{
title: 'Contract Type',
desc: dataPackage.tender[0].contractType || '--',
desc: dataPackage?.tender?.[0].contractType,
},
{
title: 'Published Date',
desc: dataPackage.tender[0].datePublished || '--',
desc: dataPackage?.tender?.[0].datePublished,
},
{
title: 'Period of Work (Days)',
desc: dataPackage.tender[0].contractPeriod[0].durationInDays || '--',
desc: dataPackage?.tender?.[0].contractPeriod?.[0].durationInDays,
},
];

const invitingAuthority = [
{
title: 'Name',
desc: dataPackage.tender[0].procuringEntity[0].name || '--',
desc: dataPackage?.tender?.[0].procuringEntity?.[0].name,
},
{
title: 'Fee Payable To',
desc: dataPackage.tender[0].participationFees[0].description || '--',
desc: dataPackage?.tender?.[0].participationFees?.[0].description,
},
{
title: 'Tender Fee in Rs',
desc: dataPackage.tender[0].participationFees[0].value[0].amount || '--',
desc: dataPackage?.tender?.[0].participationFees?.[0].value?.[0].amount,
},
{
title: 'Location',
desc:
dataPackage.tender[0].items[0].deliveryAddresses[0].streetAddress ||
'--',
desc: dataPackage?.tender?.[0].items?.[0].deliveryAddresses[0]
?.streetAddress,
},
{
title: 'Pincode',
desc:
Number.parseInt(
dataPackage.tender[0].items[0].deliveryAddresses[0].postalCode
) || '--',
desc: Number.parseInt(
dataPackage?.tender?.[0].items?.[0].deliveryAddresses?.[0].postalCode
),
},
];

const bidderDetails = [
{
title: 'Bid Validity(Days)',
desc:
dataPackage.tender[0].submissionTerms[0].bidValidityPeriod[0]
.durationInDays || '--',
desc: dataPackage?.tender?.[0].submissionTerms?.[0].bidValidityPeriod[0]
?.durationInDays,
},
{
title: 'Bid Opening Place',
desc:
dataPackage.tender[0].bidOpening[0].address[0].streetAddress || '--',
dataPackage?.tender?.[0].bidOpening?.[0].address?.[0].streetAddress ||
'--',
},
{
title: 'Bidder Information',
desc: dataPackage.bids ? (
desc: dataPackage?.bids ? (
<Table className="bg-white mt-4 rounded-sm shadow-sm">
<TableHeader>
<TableRow>
Expand All @@ -136,9 +134,9 @@ export const ContractDetails = ({ dataPackage }) => {
{dataPackage.bids[0].details.map((bid: any) => {
return (
<TableRow key={bid.id}>
<TableCell>{bid.tenderers[0].name}</TableCell>
<TableCell>{bid.tenderers?.[0].name || '--'}</TableCell>
<TableCell>{bid.date || '--'}</TableCell>
<TableCell>{commaNumber(bid.id)}</TableCell>
<TableCell>{commaNumber(bid.id) || '--'}</TableCell>
<TableCell>{bid.status || '--'}</TableCell>
</TableRow>
);
Expand All @@ -154,33 +152,23 @@ export const ContractDetails = ({ dataPackage }) => {
const awardDetails = [
{
title: 'Awarded Value',
desc: dataPackage.awards
? commaNumber(dataPackage.awards[0].value[0].amount)
: '--',
desc: commaNumber(dataPackage?.awards?.[0].value?.[0].amount),
},
{
title: 'Awarded Currency',
desc: dataPackage.awards
? dataPackage.awards[0].value[0].currency
: '--',
desc: dataPackage?.awards?.[0].value?.[0].currency,
},
{
title: 'Contract Date',
desc: dataPackage.awards
? dataPackage.awards[0].contractPeriod[0].startDate
: '--',
desc: dataPackage?.awards?.[0].contractPeriod?.[0].startDate,
},
{
title: 'Contract Value',
desc: dataPackage.statistics
? commaNumber(dataPackage.statistics[0].value)
: '--',
desc: commaNumber(dataPackage?.statistics?.[0].value),
},
{
title: 'Work Completion Period in days',
desc: dataPackage.awards
? dataPackage.awards[0].contractPeriod[0].durationInDays
: '--',
desc: dataPackage?.awards?.[0].contractPeriod?.[0].durationInDays,
},
];

Expand Down Expand Up @@ -235,6 +223,8 @@ export const ContractDetails = ({ dataPackage }) => {
};

function commaNumber(num: number | string) {
if (!num) return null;

return String(num).replace(/\B(?=(?:(\d\d)+(\d)(?!\d))+(?!\d))/g, ',');
}

Expand Down
6 changes: 3 additions & 3 deletions pages/datasets/[tender]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MegaHeader from 'components/_shared/MegaHeader';
import { ContractDetails } from 'components/datasets/ContractDetails';
import type { Tender } from 'components/datasets/types';
import type { Tender as Type } from 'components/datasets/types';
import { GetServerSideProps } from 'next';
import Head from 'next/head';
import { useRouter } from 'next/router';
Expand All @@ -17,7 +17,7 @@ type Props = {
const Tender: React.FC<Props> = ({ data }) => {
const router = useRouter();

const dataPackage: Tender = data.result;
const dataPackage: Type = data.result;

const headerData = {
title: dataPackage.tender[0].title,
Expand Down Expand Up @@ -69,7 +69,7 @@ const Tender: React.FC<Props> = ({ data }) => {
</button>
</section>

<ContractDetails dataPackage={dataPackage} />
{dataPackage ? <ContractDetails dataPackage={dataPackage} /> : null}
</div>
</main>
</>
Expand Down

0 comments on commit 5a8091d

Please sign in to comment.