Skip to content

Fix: remove hasExternalPrice prop on <LineItemQuantity> component #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ type Props = {
max?: number
disabled?: boolean
readonly?: boolean
/**
* force the update of the line item price using `_external_price: true` attribute
* @link https://docs.commercelayer.io/core/external-resources/external-prices
*/
hasExternalPrice?: boolean
} & (Omit<JSX.IntrinsicElements['select'], 'children'> &
Omit<JSX.IntrinsicElements['span'], 'children'>)

export function LineItemQuantity(props: Props): JSX.Element {
const { max = 50, readonly = false, hasExternalPrice, ...p } = props
const { max = 50, readonly = false, ...p } = props
const { lineItem } = useContext(LineItemChildrenContext)
const { updateLineItem } = useContext(LineItemContext)
const options: ReactNode[] = []
Expand All @@ -39,7 +34,7 @@ export function LineItemQuantity(props: Props): JSX.Element {
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>): void => {
const quantity = Number(e.target.value)
if (updateLineItem && lineItem) {
void updateLineItem(lineItem.id, quantity, hasExternalPrice)
void updateLineItem(lineItem.id, quantity)
}
}
const quantity = lineItem?.quantity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ export function LineItemsContainer(props: Props): JSX.Element {
const lineItemValue: LineItemContextValue = {
...state,
loader,
updateLineItem: async (lineItemId, quantity = 1, hasExternalPrice) => {
updateLineItem: async (lineItemId, quantity = 1) => {
await updateLineItem({
lineItemId,
quantity,
hasExternalPrice,
dispatch,
config,
getOrder,
Expand Down
23 changes: 3 additions & 20 deletions packages/react-components/src/reducers/LineItemReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import getErrors from '#utils/getErrors'
export interface UpdateLineItemParams {
lineItemId: string
quantity?: number
hasExternalPrice?: boolean
dispatch: Dispatch<LineItemAction>
config: CommerceLayerConfig
getOrder: getOrderContext | undefined
Expand Down Expand Up @@ -42,11 +41,7 @@ export interface LineItemPayload {
}

export interface LineItemState extends LineItemPayload {
updateLineItem?: (
lineItemId: string,
quantity?: number,
hasExternalPrice?: boolean
) => Promise<void>
updateLineItem?: (lineItemId: string, quantity?: number) => Promise<void>
deleteLineItem?: (lineItemId: string) => Promise<void>
}

Expand Down Expand Up @@ -100,22 +95,10 @@ export const getLineItems: GetLineItems = (params) => {
export async function updateLineItem(
params: UpdateLineItemParams
): Promise<void> {
const {
config,
lineItemId,
quantity,
hasExternalPrice,
getOrder,
orderId,
dispatch
} = params
const { config, lineItemId, quantity, getOrder, orderId, dispatch } = params
const sdk = getSdk(config)
try {
await sdk.line_items.update({
id: lineItemId,
quantity,
_external_price: hasExternalPrice
})
await sdk.line_items.update({ id: lineItemId, quantity })
getOrder && (await getOrder(orderId))
dispatch({
type: 'setErrors',
Expand Down