fix: resolve admin orders re-fetching loop and update order confirmation SMS pattern args structure
Deploy Canina / deploy (push) Successful in 40s
Deploy Canina / deploy (push) Successful in 40s
This commit is contained in:
1 parent
b527befe4a
commit
b807d25632
5 files changed
+26
-12
No files matched your search
@@ -345,7 +345,7 @@ export class SmsService {
|
||||
{
|
||||
id: config.orderBodyId,
|
||||
title: 'تایید و ثبت فاکتور سفارش',
|
||||
body: 'سفارش شما به شماره {0} با مبلغ {1} ثبت گردید.',
|
||||
body: '{0} عزیز ، سفارش شما به شماره {1} به مبلغ {2} با موفقیت ثبت شد.\nکنینا ایران',
|
||||
assigned: 'order',
|
||||
},
|
||||
{
|
||||
@@ -874,14 +874,16 @@ export class SmsService {
|
||||
*/
|
||||
async sendOrderConfirmation(
|
||||
phone: string,
|
||||
customerName: string,
|
||||
orderNumber: string,
|
||||
amount: string,
|
||||
): Promise<boolean> {
|
||||
const config = await this.getSmsConfig();
|
||||
const cleanName = (customerName || 'مشتری').trim();
|
||||
return this.sendPatternSms({
|
||||
to: phone,
|
||||
bodyId: config.orderBodyId,
|
||||
args: [orderNumber, amount],
|
||||
args: [cleanName, orderNumber, amount],
|
||||
type: 'ORDER_CONFIRMATION',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -242,9 +242,11 @@ export class OrdersService {
|
||||
|
||||
// Send Order Confirmation SMS for wallet orders
|
||||
if (user.mobile) {
|
||||
const customerName = user.firstName || 'مشتری';
|
||||
this.smsService
|
||||
.sendOrderConfirmation(
|
||||
user.mobile,
|
||||
customerName,
|
||||
trackingNumber,
|
||||
Number(finalAmount).toLocaleString('fa-IR'),
|
||||
)
|
||||
@@ -288,9 +290,11 @@ export class OrdersService {
|
||||
where: { id: userId },
|
||||
});
|
||||
if (user?.mobile) {
|
||||
const customerName = user.firstName || 'مشتری';
|
||||
await this.smsService
|
||||
.sendOrderConfirmation(
|
||||
user.mobile,
|
||||
customerName,
|
||||
trackingNumber,
|
||||
Number(finalAmount).toLocaleString('fa-IR'),
|
||||
)
|
||||
|
||||
@@ -491,9 +491,18 @@ export class PaymentService {
|
||||
const formattedAmount = Number(transaction.amount).toLocaleString(
|
||||
'fa-IR',
|
||||
);
|
||||
const customerName =
|
||||
transaction.user?.firstName ||
|
||||
transaction.order?.user?.firstName ||
|
||||
'مشتری';
|
||||
|
||||
this.smsService
|
||||
.sendOrderConfirmation(customerMobile, trackingNum, formattedAmount)
|
||||
.sendOrderConfirmation(
|
||||
customerMobile,
|
||||
customerName,
|
||||
trackingNum,
|
||||
formattedAmount,
|
||||
)
|
||||
.catch((err) => {
|
||||
this.logger.warn(`Could not send SMS confirmation: ${err}`);
|
||||
});
|
||||
|
||||
@@ -118,20 +118,19 @@ export default function Orders() {
|
||||
setOrders(response.data.data);
|
||||
setTotalPages(response.data.meta?.lastPage || 1);
|
||||
|
||||
// Update selectedOrder if open
|
||||
if (selectedOrder) {
|
||||
const updated = response.data.data.find((o: Order) => o.id === selectedOrder.id);
|
||||
if (updated) {
|
||||
setSelectedOrder(updated);
|
||||
}
|
||||
}
|
||||
// Update selectedOrder if open without causing re-fetch loop
|
||||
setSelectedOrder((currentSelected) => {
|
||||
if (!currentSelected) return null;
|
||||
const updated = response.data.data.find((o: Order) => o.id === currentSelected.id);
|
||||
return updated || currentSelected;
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch orders', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [page, search, status, selectedOrder]);
|
||||
}, [page, search, status]);
|
||||
|
||||
useEffect(() => {
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
|
||||
@@ -1372,7 +1372,7 @@ export default function SmsSettingsPage() {
|
||||
required
|
||||
value={newPatternBody}
|
||||
onChange={(e) => setNewPatternBody(e.target.value)}
|
||||
placeholder="کاربر گرامی، سفارش {0} با مبلغ {1} تومان در کنینا ثبت شد."
|
||||
placeholder="{0} عزیز ، سفارش شما به شماره {1} به مبلغ {2} با موفقیت ثبت شد. کنینا ایران"
|
||||
className="w-full border border-gray-200 rounded-xl p-3 outline-none focus:ring-2 focus:ring-purple-500 text-sm font-medium leading-relaxed"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user