1- import {
2- PlaceOrderContainer ,
3- ErrorComponentProps ,
4- } from "@commercelayer/react-components"
1+ import { PlaceOrderContainer } from "@commercelayer/react-components"
52import { useRouter } from "next/router"
63import { useContext , useState } from "react"
74import { Trans , useTranslation } from "react-i18next"
@@ -13,6 +10,7 @@ import { Label } from "components/ui/Label"
1310import { SpinnerIcon } from "components/ui/SpinnerIcon"
1411
1512import { ErrorIcon } from "./ErrorIcon"
13+ import { messages } from "./messages"
1614import {
1715 ErrorIco ,
1816 ErrorMessage ,
@@ -59,51 +57,6 @@ const StepPlaceOrder: React.FC<Props> = ({
5957
6058 const { placeOrder } = appCtx
6159
62- const messages : ErrorComponentProps [ "messages" ] = [
63- {
64- code : "VALIDATION_ERROR" ,
65- resource : "orders" ,
66- field : "status" ,
67- message : t ( "error.transition" ) ,
68- } ,
69- {
70- code : "VALIDATION_ERROR" ,
71- resource : "orders" ,
72- field : "paymentMethod" ,
73- message : t ( "error.paymentMethod" ) ,
74- } ,
75- {
76- code : "VALIDATION_ERROR" ,
77- resource : "orders" ,
78- field : "giftCardOrCouponCode" ,
79- message : " " ,
80- } ,
81- {
82- code : "PAYMENT_NOT_APPROVED_FOR_EXECUTION" ,
83- resource : "orders" ,
84- field : "base" ,
85- message : t ( "error.payer" ) ,
86- } ,
87- {
88- code : "INVALID_RESOURCE_ID" ,
89- resource : "orders" ,
90- field : "base" ,
91- message : t ( "error.resourceID" ) ,
92- } ,
93- {
94- code : "EMPTY_ERROR" ,
95- resource : "orders" ,
96- field : "customer_email" ,
97- message : " " ,
98- } ,
99- {
100- code : "VALIDATION_ERROR" ,
101- resource : "orders" ,
102- field : "customer_email" ,
103- message : " " ,
104- } ,
105- ]
106-
10760 const handlePlaceOrder = async ( { placed } : { placed : boolean } ) => {
10861 if ( placed ) {
10962 setIsPlacingOrder ( true )
@@ -119,11 +72,20 @@ const StepPlaceOrder: React.FC<Props> = ({
11972 return (
12073 < >
12174 < ErrorsContainer data-test-id = "errors-container" >
122- < StyledErrors resource = "orders" messages = { messages } >
75+ < StyledErrors
76+ resource = "orders"
77+ messages = {
78+ messages &&
79+ messages . map ( ( msg ) => {
80+ return { ...msg , message : t ( msg . message ) }
81+ } )
82+ }
83+ >
12384 { ( props ) => {
12485 if ( props . errors ?. length === 0 ) {
12586 return null
12687 }
88+ console . log ( props )
12789 const compactedErrors = props . errors
12890 return compactedErrors ?. map ( ( error , index ) => {
12991 if ( error ?. trim ( ) . length === 0 || ! error ) {
0 commit comments