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

View file

@ -8,11 +8,7 @@ import React from "react";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { customerUrl } from "../../../../customers/urls"; import { customerUrl } from "../../../../customers/urls";
import { import { getMutationState, getStringOrPlaceholder } from "../../../../misc";
getMutationState,
getStringOrPlaceholder,
maybe
} from "../../../../misc";
import { productUrl } from "../../../../products/urls"; import { productUrl } from "../../../../products/urls";
import { FulfillmentStatus } from "../../../../types/globalTypes"; import { FulfillmentStatus } from "../../../../types/globalTypes";
import OrderCancelDialog from "../../../components/OrderCancelDialog"; 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 || []} userPermissions={user?.userPermissions || []}
onOrderCancel={() => openModal("cancel")} onOrderCancel={() => openModal("cancel")}
onOrderFulfill={() => navigate(orderFulfillUrl(id))} onOrderFulfill={() => navigate(orderFulfillUrl(id))}

View file

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

View file

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