Use optional chaining

This commit is contained in:
dominik-zeglen 2020-08-25 11:42:14 +02:00
parent 7ce0b6c3b3
commit 82aa6ea942
2 changed files with 12 additions and 22 deletions

View file

@ -10,7 +10,7 @@ import { useWarehouseList } from "@saleor/warehouses/queries";
import React from "react"; import React from "react";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { decimal, maybe, weight } from "../../misc"; import { decimal, weight } from "../../misc";
import ProductCreatePage, { import ProductCreatePage, {
ProductCreatePageSubmitData ProductCreatePageSubmitData
} from "../components/ProductCreatePage"; } from "../components/ProductCreatePage";
@ -107,14 +107,13 @@ export const ProductCreateView: React.FC = () => {
})} })}
/> />
<ProductCreatePage <ProductCreatePage
currency={maybe(() => shop.defaultCurrency)} currency={shop?.defaultCurrency}
categories={maybe(() => searchCategoryOpts.data.search.edges, []).map( categories={(searchCategoryOpts.data?.search.edges || []).map(
edge => edge.node
)}
collections={(searchCollectionOpts.data?.search.edges || []).map(
edge => edge.node edge => edge.node
)} )}
collections={maybe(
() => searchCollectionOpts.data.search.edges,
[]
).map(edge => edge.node)}
disabled={productCreateOpts.loading} disabled={productCreateOpts.loading}
errors={productCreateOpts.data?.productCreate.errors || []} errors={productCreateOpts.data?.productCreate.errors || []}
fetchCategories={searchCategory} fetchCategories={searchCategory}
@ -124,30 +123,24 @@ export const ProductCreateView: React.FC = () => {
defaultMessage: "New Product", defaultMessage: "New Product",
description: "page header" description: "page header"
})} })}
productTypes={maybe(() => productTypes={searchProductTypesOpts.data?.search.edges.map(
searchProductTypesOpts.data.search.edges.map(edge => edge.node) edge => edge.node
)} )}
onBack={handleBack} onBack={handleBack}
onSubmit={handleSubmit} onSubmit={handleSubmit}
saveButtonBarState={productCreateOpts.status} saveButtonBarState={productCreateOpts.status}
fetchMoreCategories={{ fetchMoreCategories={{
hasMore: maybe( hasMore: searchCategoryOpts.data?.search.pageInfo.hasNextPage,
() => searchCategoryOpts.data.search.pageInfo.hasNextPage
),
loading: searchCategoryOpts.loading, loading: searchCategoryOpts.loading,
onFetchMore: loadMoreCategories onFetchMore: loadMoreCategories
}} }}
fetchMoreCollections={{ fetchMoreCollections={{
hasMore: maybe( hasMore: searchCollectionOpts.data?.search.pageInfo.hasNextPage,
() => searchCollectionOpts.data.search.pageInfo.hasNextPage
),
loading: searchCollectionOpts.loading, loading: searchCollectionOpts.loading,
onFetchMore: loadMoreCollections onFetchMore: loadMoreCollections
}} }}
fetchMoreProductTypes={{ fetchMoreProductTypes={{
hasMore: maybe( hasMore: searchProductTypesOpts.data?.search.pageInfo.hasNextPage,
() => searchProductTypesOpts.data.search.pageInfo.hasNextPage
),
loading: searchProductTypesOpts.loading, loading: searchProductTypesOpts.loading,
onFetchMore: loadMoreProductTypes onFetchMore: loadMoreProductTypes
}} }}

View file

@ -122,10 +122,7 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
const handleImageSelect = (id: string) => () => { const handleImageSelect = (id: string) => () => {
if (variant) { if (variant) {
if ( if (variant?.images?.map(image => image.id).indexOf(id) !== -1) {
variant.images &&
variant.images.map(image => image.id).indexOf(id) !== -1
) {
unassignImage({ unassignImage({
variables: { variables: {
imageId: id, imageId: id,