@@ -13,6 +13,7 @@ import {
1313 Typography ,
1414} from "@mui/material" ;
1515import { ErrorBoundary , Suspense } from "@suspensive/react" ;
16+ import { enqueueSnackbar , OptionsObject } from "notistack" ;
1617import * as React from "react" ;
1718import * as R from "remeda" ;
1819
@@ -68,12 +69,26 @@ const OrderProductRelationItem: React.FC<OrderProductRelationItemProps> = ({
6869 { }
6970 ) ;
7071
72+ const addSnackbar = ( c : string | React . ReactNode , variant : OptionsObject [ "variant" ] ) =>
73+ enqueueSnackbar ( c , { variant, anchorOrigin : { vertical : "bottom" , horizontal : "center" } } ) ;
74+
7175 const hasPatchableOption = Object . entries ( currentCustomOptionValues ) . length > 0 ;
7276 const patchOptionBtnDisabled = isPending || ! hasPatchableOption ;
7377
7478 const refundOneProductStr = language === "ko" ? "단일 상품 환불" : "Refund one item" ;
7579 const refundedStr = language === "ko" ? "환불됨" : "Refunded" ;
7680 const modifyOptionStr = language === "ko" ? "옵션 수정" : "Modify options" ;
81+ const succeededToRefundOrderStr = language === "ko" ? "주문을 환불했습니다!" : "Successfully refunded the order!" ;
82+ const failedToRefundOrderStr =
83+ language === "ko"
84+ ? "주문에 포함된 상품을 환불하는 중 문제가 발생했습니다,\n잠시 후 다시 시도해주세요."
85+ : "An error occurred while refunding the order,\nplease try again later." ;
86+ const succeededToPatchOptionsStr =
87+ language === "ko" ? "옵션이 수정되었습니다." : "Options have been modified successfully." ;
88+ const failedToPatchOptionsStr =
89+ language === "ko"
90+ ? "옵션 수정 중 문제가 발생했습니다,\n잠시 후 다시 시도해주세요."
91+ : "An error occurred while modifying the options,\nplease try again later." ;
7792
7893 const refundBtnDisabled = isPending || ! R . isNullish ( prodRel . not_refundable_reason ) ;
7994 const refundBtnText = R . isNullish ( prodRel . not_refundable_reason )
@@ -83,10 +98,13 @@ const OrderProductRelationItem: React.FC<OrderProductRelationItemProps> = ({
8398 : prodRel . not_refundable_reason ;
8499
85100 const refundOneItem = ( ) =>
86- oneItemRefundMutation . mutate ( {
87- order_id : order . id ,
88- order_product_relation_id : prodRel . id ,
89- } ) ;
101+ oneItemRefundMutation . mutate (
102+ { order_id : order . id , order_product_relation_id : prodRel . id } ,
103+ {
104+ onSuccess : ( ) => addSnackbar ( succeededToRefundOrderStr , "success" ) ,
105+ onError : ( ) => addSnackbar ( failedToRefundOrderStr , "error" ) ,
106+ }
107+ ) ;
90108 const patchOneItemOptions = ( ) => {
91109 if ( ! Common . Utils . isFormValid ( formRef . current ) ) throw new Error ( "Form is not valid" ) ;
92110
@@ -104,11 +122,17 @@ const OrderProductRelationItem: React.FC<OrderProductRelationItemProps> = ({
104122 custom_response : value ,
105123 } ) ) ;
106124
107- optionsOfOneItemInOrderPatchMutation . mutate ( {
108- order_id : order . id ,
109- order_product_relation_id : prodRel . id ,
110- options : modifiedCustomOptionValues ,
111- } ) ;
125+ optionsOfOneItemInOrderPatchMutation . mutate (
126+ {
127+ order_id : order . id ,
128+ order_product_relation_id : prodRel . id ,
129+ options : modifiedCustomOptionValues ,
130+ } ,
131+ {
132+ onSuccess : ( ) => addSnackbar ( succeededToPatchOptionsStr , "success" ) ,
133+ onError : ( ) => addSnackbar ( failedToPatchOptionsStr , "error" ) ,
134+ }
135+ ) ;
112136 } ;
113137
114138 const actionButtons = (
@@ -159,8 +183,8 @@ const OrderItem: React.FC<OrderItemProps> = ({ order, disabled, ...props }) => {
159183 const oneItemRefundMutation = ShopHooks . useOneItemRefundMutation ( shopAPIClient ) ;
160184 const optionsOfOneItemInOrderPatchMutation = ShopHooks . useOptionsOfOneItemInOrderPatchMutation ( shopAPIClient ) ;
161185
162- const refundOrder = ( ) => orderRefundMutation . mutate ( { order_id : order . id } ) ;
163- const openReceipt = ( ) => window . open ( ` ${ shopApiDomain } /v1/orders/ ${ order . id } /receipt/` , "_blank" ) ;
186+ const addSnackbar = ( c : string | React . ReactNode , variant : OptionsObject [ "variant" ] ) =>
187+ enqueueSnackbar ( c , { variant , anchorOrigin : { vertical : "bottom" , horizontal : "center" } } ) ;
164188
165189 const PaymentHistoryStatus = language === "ko" ? PaymentHistoryStatusKo : PaymentHistoryStatusEn ;
166190 const refundFullOrderStr = language === "ko" ? "주문 전체 환불" : "Refund full order" ;
@@ -169,6 +193,21 @@ const OrderItem: React.FC<OrderItemProps> = ({ order, disabled, ...props }) => {
169193 const orderedPriceStr = language === "ko" ? "주문 결제 금액" : "Ordered Price" ;
170194 const statusStr = language === "ko" ? "상태" : "Status" ;
171195 const productsInOrderStr = language === "ko" ? "주문 상품 목록" : "Products in Order" ;
196+ const succeededToRefundFullOrderStr = language === "ko" ? "주문을 환불했습니다!" : "Successfully refunded the order!" ;
197+ const failedToRefundFullOrderStr =
198+ language === "ko"
199+ ? "주문 환불 중 문제가 발생했습니다,\n잠시 후 다시 시도해주세요."
200+ : "An error occurred while refunding the order,\nplease try again later." ;
201+
202+ const refundOrder = ( ) =>
203+ orderRefundMutation . mutate (
204+ { order_id : order . id } ,
205+ {
206+ onSuccess : ( ) => addSnackbar ( succeededToRefundFullOrderStr , "success" ) ,
207+ onError : ( ) => addSnackbar ( failedToRefundFullOrderStr , "error" ) ,
208+ }
209+ ) ;
210+ const openReceipt = ( ) => window . open ( `${ shopApiDomain } /v1/orders/${ order . id } /receipt/` , "_blank" ) ;
172211
173212 const isPending =
174213 disabled ||
0 commit comments