Get rid of maybes

This commit is contained in:
Tomasz Szymanski 2021-04-02 06:28:28 +02:00
parent fc3abed23d
commit cca95a77b0
4 changed files with 17 additions and 25 deletions

View file

@ -9,7 +9,7 @@ import React from "react";
import { useIntl } from "react-intl";
import { customerUrl } from "../../../../customers/urls";
import { getStringOrPlaceholder, maybe } from "../../../../misc";
import { getStringOrPlaceholder } from "../../../../misc";
import { productUrl } from "../../../../products/urls";
import OrderDraftCancelDialog from "../../../components/OrderDraftCancelDialog/OrderDraftCancelDialog";
import OrderDraftPage from "../../../components/OrderDraftPage";
@ -98,11 +98,8 @@ export const OrderDraftDetails: React.FC<OrderDraftDetailsProps> = ({
order: id
})
}
users={maybe(
() => users.data.search.edges.map(edge => edge.node),
[]
)}
hasMore={maybe(() => users.data.search.pageInfo.hasNextPage, false)}
users={users?.data?.search?.edges?.map(edge => edge.node) || []}
hasMore={users?.data?.search?.pageInfo?.hasNextPage || false}
onFetchMore={loadMoreCustomers}
fetchUsers={searchUsers}
loading={users.loading}
@ -118,7 +115,7 @@ export const OrderDraftDetails: React.FC<OrderDraftDetailsProps> = ({
onOrderLineAdd={() => openModal("add-order-line")}
onBack={() => navigate(orderDraftListUrl())}
order={order}
countries={maybe(() => data.shop.countries, []).map(country => ({
countries={(data?.shop?.countries || []).map(country => ({
code: country.code,
label: country.country
}))}

View file

@ -8,11 +8,7 @@ import React from "react";
import { useIntl } from "react-intl";
import { customerUrl } from "../../../../customers/urls";
import {
getMutationState,
getStringOrPlaceholder,
maybe
} from "../../../../misc";
import { getMutationState, getStringOrPlaceholder } from "../../../../misc";
import { productUrl } from "../../../../products/urls";
import { FulfillmentStatus } from "../../../../types/globalTypes";
import OrderCancelDialog from "../../../components/OrderCancelDialog";
@ -123,7 +119,7 @@ export const OrderNormalDetails: React.FC<OrderNormalDetailsProps> = ({
[])
]
)}
shippingMethods={maybe(() => data.order.availableShippingMethods, [])}
shippingMethods={data?.order?.availableShippingMethods || []}
userPermissions={user?.userPermissions || []}
onOrderCancel={() => openModal("cancel")}
onOrderFulfill={() => navigate(orderFulfillUrl(id))}

View file

@ -11,11 +11,7 @@ import React from "react";
import { useIntl } from "react-intl";
import { customerUrl } from "../../../../customers/urls";
import {
getMutationState,
getStringOrPlaceholder,
maybe
} from "../../../../misc";
import { getMutationState, getStringOrPlaceholder } from "../../../../misc";
import { productUrl } from "../../../../products/urls";
import { FulfillmentStatus } from "../../../../types/globalTypes";
import OrderCancelDialog from "../../../components/OrderCancelDialog";
@ -155,10 +151,7 @@ export const OrderUnconfirmedDetails: React.FC<OrderUnconfirmedDetailsProps> = (
.errors || [])
]
)}
shippingMethods={maybe(
() => data.order.availableShippingMethods,
[]
)}
shippingMethods={data?.order?.availableShippingMethods || []}
userPermissions={user?.userPermissions || []}
onOrderCancel={() => openModal("cancel")}
onOrderFulfill={() => navigate(orderFulfillUrl(id))}

View file

@ -127955,7 +127955,9 @@ exports[`Storyshots Views / Orders / Order list default 1`] = `
<thead
class="MuiTableHead-root-id"
>
<tr>
<tr
class="MuiTableRow-root-id MuiTableRow-head-id"
>
<th
class="MuiTableCell-root-id MuiTableCell-head-id TableCellHeader-root-id OrderList-colNumber-id"
scope="col"
@ -129324,7 +129326,9 @@ exports[`Storyshots Views / Orders / Order list loading 1`] = `
<thead
class="MuiTableHead-root-id"
>
<tr>
<tr
class="MuiTableRow-root-id MuiTableRow-head-id"
>
<th
class="MuiTableCell-root-id MuiTableCell-head-id TableCellHeader-root-id OrderList-colNumber-id"
scope="col"
@ -129762,7 +129766,9 @@ exports[`Storyshots Views / Orders / Order list when no data 1`] = `
<thead
class="MuiTableHead-root-id"
>
<tr>
<tr
class="MuiTableRow-root-id MuiTableRow-head-id"
>
<th
class="MuiTableCell-root-id MuiTableCell-head-id TableCellHeader-root-id OrderList-colNumber-id"
scope="col"