Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HikkaTown committed May 20, 2022
1 parent 526bce5 commit a0e8de3
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 40 deletions.
Binary file modified backend/.tmp/data.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
"type": "component",
"repeatable": true,
"component": "info-component.info-list"
},
"tableNames": {
"type": "component",
"repeatable": true,
"component": "table.table-name"
}
}
}
8 changes: 6 additions & 2 deletions frontend/src/components/HowMuchSection/HowMuchSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ const testData = {
],
};

export default function HowMuchSection({ data }) {
export default function HowMuchSection({ data, title }) {
return (
<section className={s.section}>
<div className={s.container}>
<h2 className={s.header}>Сколько это будет стоить</h2>
{!title ? (
<h2 className={s.header}>Сколько это будет стоить</h2>
) : (
<h2 className={s.header}>{title}</h2>
)}
{data ? <TableComponent data={data} /> : ""}
</div>
</section>
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/StepSection/StepSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ export default function StepSection({ data, officesData }) {
""
)}

<StepsBlock count={2} className={s.step} id="2" />
<h3 className={s.header_step}>
{data.steps[1].header ? data.steps[1].header : ""}
</h3>
{data ? (
{data.steps[1] && <StepsBlock count={2} className={s.step} id="2" />}
{data.steps[1] && (
<h3 className={s.header_step}>
{data.steps[1].header ? data.steps[1].header : ""}
</h3>
)}
{data.steps[1] ? (
<TwoStepComponent
products={data.steps[1].products}
select={secondStep}
Expand Down
116 changes: 98 additions & 18 deletions frontend/src/lib/apiFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,59 @@ export const getAllProjectsCard = async () => {
return result;
};

export const getCurrentProjects = async (id) => {
const { data } = await client.query({
query: gql`
query getCurrentProject {
projects(
filters: { category: { id: { eq: ${id} } } }
pagination: { page: 1, pageSize: 1000 }
) {
data {
id
attributes {
images {
data {
attributes {
url
}
}
}
category {
data {
id
attributes {
typeProjectName
}
}
}
}
}
meta {
pagination {
page
pageSize
}
}
}
}
`,
});
let result = [];
data.projects.data.map((item) => {
let images = [];
item.attributes.images.data.map((itemImage) => {
images.push(itemImage.attributes.url);
});
let object = {
images: images,
category: item.attributes.category.data.attributes.typeProjectName,
};
result.push(object);
});
return result;
};

export const getCurrentProjectsCard = async (id) => {
const { data } = await client.query({
query: gql`
Expand Down Expand Up @@ -356,7 +409,7 @@ export const getSmallProduct = async (id) => {
const parseTable = (data) => {
let header = [];
let itemsTotal = [];
data.map((item, index) => {
data.tableColumn.map((item, index) => {
if (item.columnName?.length > 0) {
header.push(item.columnName);
}
Expand Down Expand Up @@ -442,7 +495,11 @@ export const getAllProductCard = async () => {
};
})
: null,
table: attributes.column.length ? parseTable(attributes.column) : null,
table: attributes?.table?.length
? attributes.table.map((item) => {
return parseTable(item);
})
: null,
};
res.push(object);
});
Expand All @@ -467,38 +524,52 @@ export const getCurrentProductCard = async (url) => {
let res = [];
data.straniczyUslugs.data.map((item) => {
const { attributes } = item;

let object = {
url: attributes.url,
header: attributes?.header ? attributes.header : null,
pageData: {
metaHead: attributes.metaHead,
metaDescription: attributes.metaDescription,
title: attributes.title,
description: attributes.description,
metaHead: attributes?.metaHead ? attributes.metaHead : null,
metaDescription: attributes?.metaDescription
? attributes.metaDescription
: null,
title: attributes?.title ? attributes.title : null,
description: attributes?.description ? attributes.description : null,
},
infoList: attributes.infoList?.length
? attributes.infoList.map((item) => {
return item.infoListItem;
})
: null,
files: attributes.files ? 1 : null,
deliveryAmount: attributes.deliveryAmount
files: attributes?.files ? 1 : null,
deliveryAmount: attributes?.deliveryAmount
? +attributes.deliveryAmount
: null,
shortDescription: {
firstBlock: attributes.shortDescription.firstBlock,
secondBlock: attributes.shortDescription.secondBlock,
thirdBlock: attributes.shortDescription.thirdBlock,
firstBlock: attributes?.shortDescription?.firstBlock
? attributes.shortDescription.firstBlock
: null,
secondBlock: attributes?.shortDescription?.secondBlock
? attributes.shortDescription.secondBlock
: null,
thirdBlock: attributes?.shortDescription?.thirdBlock
? attributes.shortDescription.thirdBlock
: null,
},
seoBlock: {
header: attributes.seoBlock.seoHeader,
seoDescription: attributes.seoBlock.seoDescription,
header: attributes?.seoBlock?.seoHeader
? attributes.seoBlock.seoHeader
: null,
seoDescription: attributes?.seoBlock?.seoDescription
? attributes.seoBlock.seoDescription
: null,
},
projectId: attributes?.proekts?.data?.id
? attributes?.proekts?.data?.id
: null,
defaultText: attributes?.defaultText ? attributes.defaultText : null,
defaultPrice: attributes?.defaultPrice ? attributes.defaultPrice : null,
headStyle: attributes.headStyle,
tech: attributes.tech.length
tech: attributes?.tech?.length
? attributes.tech.map((item) => {
return {
id: +item.id,
Expand All @@ -513,11 +584,11 @@ export const getCurrentProductCard = async (url) => {
callbackBlockTitle: attributes?.callbackBlock?.title
? attributes.callbackBlock.title
: null,
steps: attributes.steps.length
steps: attributes?.steps?.length
? attributes.steps.map((item, index) => {
return {
id: +index + 1,
header: item.header,
header: item?.header ? item.header : null,
products: item.step.map((stepItem, index) => {
return {
id: index + 1,
Expand All @@ -530,7 +601,16 @@ export const getCurrentProductCard = async (url) => {
};
})
: null,
table: attributes.column.length ? parseTable(attributes.column) : null,
tableName: attributes?.tableName?.length
? attributes?.tableName.map((item) => {
return item.name;
})
: null,
table: attributes?.table?.length
? attributes.table.map((item) => {
return parseTable(item);
})
: null,
};
res.push(object);
});
Expand Down
44 changes: 32 additions & 12 deletions frontend/src/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,22 @@ query getCurrentProduct {
metaHead
metaDescription
title
vidy_proektov {
data {
id
}
}
tableName {
name
}
table {
tableColumn {
columnName
row {
rowText
}
}
}
description
defaultText
defaultPrice
Expand Down Expand Up @@ -448,12 +464,6 @@ query getCurrentProduct {
}
}
}
column {
columnName
row {
rowText
}
}
category {
data {
id
Expand Down Expand Up @@ -532,6 +542,22 @@ export const getCurrentProductCardQuery = (url) => gql`
metaHead
metaDescription
title
proekts {
data {
id
}
}
tableName {
name
}
table {
tableColumn {
columnName
row {
rowText
}
}
}
description
defaultText
defaultPrice
Expand Down Expand Up @@ -593,12 +619,6 @@ export const getCurrentProductCardQuery = (url) => gql`
}
}
}
column {
columnName
row {
rowText
}
}
category {
data {
id
Expand Down
25 changes: 22 additions & 3 deletions frontend/src/pages/catalog/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getAllProjectsCard,
getContactCards,
getCurrentProductCard,
getCurrentProjects,
getProductCardUrl,
getProductLinks,
} from "@/lib/apiFunctions";
Expand Down Expand Up @@ -53,7 +54,20 @@ export default function Index({
<ShortDescription data={pageData.shortDescription} />
{!pageData.steps && (
<>
<HowMuchSection data={pageData.table} />
{pageData.table?.length &&
pageData.table.map((item, index) => {
return (
<HowMuchSection
data={item}
key={index}
title={
pageData.tableName?.length
? pageData.tableName[index]
: undefined
}
/>
);
})}
<InfromationProduct data={pageData.infoList} />
<CallbackProudctSection
theme={pageData.pageData.title}
Expand All @@ -64,7 +78,7 @@ export default function Index({
)}
</>
)}
{pageData.steps && (
{pageData?.steps && (
<>
<StepSection data={pageData} officesData={officesList} />
</>
Expand All @@ -78,12 +92,17 @@ export default function Index({

export const getStaticProps = async (context) => {
const url = context?.params?.id;
const projects = await getAllProjectsCard();
const footerLinks = await getProductLinks();
let pageData;
let projects;
if (url) {
pageData = await getCurrentProductCard(url);
}
if (pageData[0].projectId) {
projects = await getCurrentProjects(+pageData[0].projectId);
} else {
projects = await getAllProjectsCard();
}
const contactList = await getContactCards();
let officesList = [];
contactList.map((item) => {
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0e8de3

Please sign in to comment.