1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-03-15 12:29:16 +01:00

(bug) cannot load order withdrawal instructions

This commit is contained in:
Du Peng 2022-10-13 11:23:35 +02:00
parent 11a0f62452
commit 7e3cbf7172
3 changed files with 17 additions and 24 deletions

View File

@ -4,7 +4,7 @@
# Orders are used in store
class API::OrdersController < API::ApiController
before_action :authenticate_user!
before_action :set_order, only: %i[show update destroy]
before_action :set_order, only: %i[show update destroy withdrawal_instructions]
def index
@result = ::Orders::OrderService.list(params, current_user)
@ -26,14 +26,9 @@ class API::OrdersController < API::ApiController
end
def withdrawal_instructions
begin
order = Order.find(params[:id])
rescue ActiveRecord::RecordNotFound
order = nil
end
authorize order || Order
authorize @order
render html: ::Orders::OrderService.withdrawal_instructions(order)
render html: ::Orders::OrderService.withdrawal_instructions(@order)
end
private

View File

@ -42,16 +42,15 @@ const StoreCart: React.FC<StoreCartProps> = ({ onSuccess, onError, currentUser,
const [paymentModal, setPaymentModal] = useState<boolean>(false);
const [withdrawalInstructions, setWithdrawalInstructions] = useState<string>(null);
useEffect(() => {
OrderAPI.withdrawalInstructions(cart)
.then(setWithdrawalInstructions)
.catch(onError);
}, []);
useEffect(() => {
if (cart) {
checkCart();
}
if (cart && !withdrawalInstructions) {
OrderAPI.withdrawalInstructions(cart)
.then(setWithdrawalInstructions)
.catch(onError);
}
}, [cart]);
/**
@ -305,10 +304,12 @@ const StoreCart: React.FC<StoreCartProps> = ({ onSuccess, onError, currentUser,
</div>
<div className="group">
<div className='store-cart-info'>
<h3>{t('app.public.store_cart.pickup')}</h3>
<p dangerouslySetInnerHTML={{ __html: withdrawalInstructions }} />
</div>
{cart && !cartIsEmpty() &&
<div className='store-cart-info'>
<h3>{t('app.public.store_cart.pickup')}</h3>
<p dangerouslySetInnerHTML={{ __html: withdrawalInstructions }} />
</div>
}
{cart && !cartIsEmpty() &&
<div className='store-cart-coupon'>

View File

@ -33,15 +33,12 @@ export const ShowOrder: React.FC<ShowOrderProps> = ({ orderId, currentUser, onSu
useEffect(() => {
OrderAPI.get(orderId).then(data => {
setOrder(data);
OrderAPI.withdrawalInstructions(data)
.then(setWithdrawalInstructions)
.catch(onError);
}).catch(onError);
}, []);
useEffect(() => {
OrderAPI.withdrawalInstructions(order)
.then(setWithdrawalInstructions)
.catch(onError);
}, [order]);
/**
* Check if the current operator has administrative rights or is a normal member
*/