Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
fix errors after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicjaSzu committed May 19, 2020
1 parent 9ff63d2 commit 0f88ecf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/views/Product/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Media from "react-media";
import { Breadcrumbs, ProductDescription } from "../../components";
import { generateCategoryUrl, generateProductUrl } from "../../core/utils";
import GalleryCarousel from "./GalleryCarousel";
import { ProductDetails_product } from "./gqlTypes/ProductDetails";
import OtherProducts from "./Other";

import { ProductDescription as NewProductDescription } from "../../@next/components/molecules";
Expand Down
64 changes: 35 additions & 29 deletions src/views/Product/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import React, { useEffect, useState } from "react";
import { RouteComponentProps } from "react-router";
import { useHistory } from "react-router-dom";

import { ProductDetails_product } from "@sdk/queries/types/ProductDetails";
import { useCart, useProductDetails } from "@sdk/react";
import { useCart } from "@sdk/react";

import { MetaWrapper, NotFound, OfflinePlaceholder } from "../../components";
import NetworkStatus from "../../components/NetworkStatus";
import { getGraphqlIdFromDBId, maybe } from "../../core/utils";
import { ProductDetails_product } from "./gqlTypes/ProductDetails";
import Page from "./Page";
import { TypedProductDetailsQuery } from "./queries";
import { IProps } from "./types";

const canDisplay = (product: ProductDetails_product) =>
Expand Down Expand Up @@ -110,37 +110,43 @@ const PageWithQueryAttributes: React.FC<IProps> = props => {

const View: React.FC<RouteComponentProps<{ id: string }>> = ({ match }) => {
const { addItem, items } = useCart();
const { data: product } = useProductDetails(
{
id: getGraphqlIdFromDBId(match.params.id, "Product"),
},
{ errorPolicy: "all" }
);

return (
<NetworkStatus>
{isOnline => {
if (canDisplay(product)) {
return (
<MetaWrapper meta={extractMeta(product)}>
<PageWithQueryAttributes
product={product}
add={addItem}
items={items}
/>
</MetaWrapper>
);
}
<TypedProductDetailsQuery
loaderFull
variables={{
id: getGraphqlIdFromDBId(match.params.id, "Product"),
}}
errorPolicy="all"
key={match.params.id}
>
{({ data }) => (
<NetworkStatus>
{isOnline => {
const { product } = data;
if (canDisplay(product)) {
return (
<MetaWrapper meta={extractMeta(product)}>
<PageWithQueryAttributes
product={product}
add={addItem}
items={items}
/>
</MetaWrapper>
);
}

if (product === null) {
return <NotFound />;
}
if (product === null) {
return <NotFound />;
}

if (!isOnline) {
return <OfflinePlaceholder />;
}
}}
</NetworkStatus>
if (!isOnline) {
return <OfflinePlaceholder />;
}
}}
</NetworkStatus>
)}
</TypedProductDetailsQuery>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/views/Product/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProductDetails_product } from "@sdk/queries/types/ProductDetails";
import { ICheckoutModelLine } from "@sdk/repository";
import { ProductDetails_product } from "./gqlTypes/ProductDetails";

export interface IProps {
product: ProductDetails_product;
Expand Down

0 comments on commit 0f88ecf

Please sign in to comment.