-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stock warehouse message in product and variant forms (#5126)
* fix stock warehouse message in product and variant forms * extract json messages * extract component and add tests * small refactor * small fix --------- Co-authored-by: Paweł Chyła <[email protected]>
- Loading branch information
Showing
9 changed files
with
132 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
The stock settings no longer show a message that you need to create a warehouse when warehouses are already configured. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/products/components/ProductStocks/ProductStocks.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import { messages } from "./messages"; | ||
import { WarehouseInformationMessage } from "./WarehouseInformationMessage"; | ||
|
||
jest.mock("react-intl", () => ({ | ||
defineMessages: jest.fn(x => x), | ||
FormattedMessage: ({ defaultMessage }: { defaultMessage: string }) => <>{defaultMessage}</>, | ||
})); | ||
|
||
describe("WarehouseInformationMessage", () => { | ||
const defaultProps = { | ||
hasVariants: false, | ||
hasWarehouses: false, | ||
onWarehouseConfigure: jest.fn(), | ||
}; | ||
|
||
it("should render message for creating product", () => { | ||
const { getByText } = render(<WarehouseInformationMessage isCreate {...defaultProps} />); | ||
|
||
expect(getByText(messages.warehouseMessageProductOnCreate.defaultMessage)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render message for creating variant", () => { | ||
const { getByText } = render( | ||
<WarehouseInformationMessage {...defaultProps} isCreate hasVariants />, | ||
); | ||
|
||
expect(getByText(messages.warehouseMessageVariantOnCreate.defaultMessage)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should not render message if warehouses exist", () => { | ||
const { queryByText } = render( | ||
<WarehouseInformationMessage {...defaultProps} hasWarehouses isCreate={false} />, | ||
); | ||
|
||
expect(queryByText(messages.configureWarehouseForProduct.defaultMessage)).toBeNull(); | ||
expect(queryByText(messages.configureWarehouseForVariant.defaultMessage)).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/products/components/ProductStocks/WarehouseInformationMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Link from "@dashboard/components/Link"; | ||
import { Text } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { messages } from "./messages"; | ||
|
||
interface WarehouseInformationMessageProps { | ||
isCreate: boolean; | ||
hasVariants: boolean; | ||
hasWarehouses: boolean; | ||
onWarehouseConfigure: () => void; | ||
} | ||
|
||
export const WarehouseInformationMessage: React.FC<WarehouseInformationMessageProps> = ({ | ||
isCreate, | ||
hasVariants, | ||
hasWarehouses, | ||
onWarehouseConfigure, | ||
}) => { | ||
if (isCreate) { | ||
const message = hasVariants | ||
? messages.warehouseMessageVariantOnCreate | ||
: messages.warehouseMessageProductOnCreate; | ||
|
||
return ( | ||
<Text color="default2"> | ||
<FormattedMessage {...message} /> | ||
</Text> | ||
); | ||
} | ||
|
||
if (hasWarehouses) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Text color="default2"> | ||
{hasVariants ? ( | ||
<FormattedMessage | ||
{...messages.configureWarehouseForVariant} | ||
values={{ | ||
a: chunks => <Link onClick={onWarehouseConfigure}>{chunks}</Link>, | ||
}} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
{...messages.configureWarehouseForProduct} | ||
values={{ | ||
a: chunks => <Link onClick={onWarehouseConfigure}>{chunks}</Link>, | ||
}} | ||
/> | ||
)} | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters