update cart discount for prod build, add loading toast

This commit is contained in:
2025-09-10 06:32:55 +03:00
parent 229b3d7c27
commit 2aad0329f3
5 changed files with 70 additions and 42 deletions

View File

@@ -0,0 +1,24 @@
"use server"
import { applyPromotions } from "@lib/data/cart"
export async function addPromotionCodeAction(code: string) {
try {
await applyPromotions([code]);
return { success: true, message: 'Discount code applied successfully' };
} catch (error) {
console.error('Error applying promotion code:', error);
return { success: false, message: 'Failed to apply discount code' };
}
}
export async function removePromotionCodeAction(codeToRemove: string, appliedCodes: string[]) {
try {
const updatedCodes = appliedCodes.filter((appliedCode) => appliedCode !== codeToRemove);
await applyPromotions(updatedCodes);
return { success: true, message: 'Discount code removed successfully' };
} catch (error) {
console.error('Error removing promotion code:', error);
return { success: false, message: 'Failed to remove discount code' };
}
}