feat(financial): add enable/disable toggle for shelter animal charity and round-up donation
This commit is contained in:
1 parent
e7ded849f6
commit
204350eff8
18 files changed
+11235
-11034
No files matched your search
@@ -34,6 +34,7 @@ import api from "../lib/services/api";
|
||||
|
||||
export default function CheckoutPage() {
|
||||
const router = useRouter();
|
||||
const { showPrices } = useCatalogMode();
|
||||
const { items, getTotal, getSubtotal, isSubscribed, charityDonation, setCharityDonation, addOrder, clearCart } = useCartStore();
|
||||
const { pets, activePetId, getActivePet, updatePet } = usePetStore();
|
||||
const { profile, isLoggedIn } = useUserStore();
|
||||
@@ -90,6 +91,12 @@ export default function CheckoutPage() {
|
||||
});
|
||||
}, [isLoggedIn, profile]);
|
||||
|
||||
const isCharityEnabled = useSettingsStore((state) =>
|
||||
state.getBoolean('CHARITY_DONATION_ENABLED', true) &&
|
||||
state.getBoolean('charity_donation_enabled', true) &&
|
||||
state.getBoolean('charityDonationEnabled', true)
|
||||
);
|
||||
|
||||
const roundStep = Number(useSettingsStore((state) => state.getText('CHARITY_ROUND_STEP', '10000'))) || 10000;
|
||||
const shippingFeeSetting = useSettingsStore((state) => state.getText('shipping_fee', '0'));
|
||||
const baseShippingFee = Number(shippingFeeSetting) || 0;
|
||||
@@ -106,7 +113,10 @@ export default function CheckoutPage() {
|
||||
const remainder = subtotal % roundStep;
|
||||
const roundUpDiff = remainder === 0 ? roundStep : roundStep - remainder;
|
||||
|
||||
const effectiveCharityDonation = isCharityEnabled ? charityDonation : 0;
|
||||
|
||||
const handleCharityToggle = () => {
|
||||
if (!isCharityEnabled) return;
|
||||
if (!useRoundUp) {
|
||||
setCharityDonation(roundUpDiff);
|
||||
setUseRoundUp(true);
|
||||
@@ -218,7 +228,7 @@ export default function CheckoutPage() {
|
||||
const orderId = await addOrder({
|
||||
items: [...items],
|
||||
total: totalAmount,
|
||||
charityDonation: charityDonation,
|
||||
charityDonation: effectiveCharityDonation,
|
||||
paymentMethod: paymentMethod,
|
||||
isRefill: isSubscribed,
|
||||
petId: selectedPetId || undefined,
|
||||
@@ -732,27 +742,29 @@ export default function CheckoutPage() {
|
||||
</section>
|
||||
|
||||
{/* Charity Donation Banner (Compact) */}
|
||||
<section className="bg-pink-50/70 border border-pink-200/80 rounded-2xl p-3.5 flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 bg-pink-500 text-white rounded-xl flex items-center justify-center shrink-0">
|
||||
<Heart className="w-4 h-4 fill-white" />
|
||||
{showPrices && isCharityEnabled && (
|
||||
<section className="bg-pink-50/70 border border-pink-200/80 rounded-2xl p-3.5 flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 bg-pink-500 text-white rounded-xl flex items-center justify-center shrink-0">
|
||||
<Heart className="w-4 h-4 fill-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-xs font-bold text-medical-gray-900">کمک به حیوانات پناهگاه (ردپای مهربانی)</h4>
|
||||
<p className="text-[10px] text-medical-gray-500">رند کردن مبلغ فاکتور تا {toPersian(roundStep.toLocaleString())} تومان بعدی</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-xs font-bold text-medical-gray-900">کمک به حیوانات پناهگاه (ردپای مهربانی)</h4>
|
||||
<p className="text-[10px] text-medical-gray-500">رند کردن مبلغ فاکتور تا {toPersian(roundStep.toLocaleString())} تومان بعدی</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCharityToggle}
|
||||
className={cn(
|
||||
"px-3 py-1.5 rounded-xl text-xs font-bold transition-all shrink-0 cursor-pointer",
|
||||
useRoundUp ? "bg-pink-500 text-white shadow-xs" : "bg-white text-pink-600 border border-pink-200 hover:bg-pink-50"
|
||||
)}
|
||||
>
|
||||
{useRoundUp ? `اهدای ${toPersian(charityDonation.toLocaleString())} ت` : 'مشارکت در خیریه'}
|
||||
</button>
|
||||
</section>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCharityToggle}
|
||||
className={cn(
|
||||
"px-3 py-1.5 rounded-xl text-xs font-bold transition-all shrink-0 cursor-pointer",
|
||||
useRoundUp ? "bg-pink-500 text-white shadow-xs" : "bg-white text-pink-600 border border-pink-200 hover:bg-pink-50"
|
||||
)}
|
||||
>
|
||||
{useRoundUp ? `اهدای ${toPersian(charityDonation.toLocaleString())} ت` : 'مشارکت در خیریه'}
|
||||
</button>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sticky Order Summary Sidebar (4 cols) */}
|
||||
@@ -792,7 +804,7 @@ export default function CheckoutPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{charityDonation > 0 && (
|
||||
{isCharityEnabled && charityDonation > 0 && (
|
||||
<div className="flex justify-between text-pink-400 font-bold">
|
||||
<span>ردپای مهربانی</span>
|
||||
<span className="font-vazir">{toPersian(charityDonation.toLocaleString())} تومان+</span>
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import { usePetStore, PetProfile as GlobalPetProfile, Reminder, HealthLog } from "../lib/store/usePetStore";
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import SmartAdvisor from "./SmartAdvisor";
|
||||
import OrderDetailsModal from "./OrderDetailsModal";
|
||||
import { toast } from "sonner";
|
||||
@@ -47,6 +48,12 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
const searchParams = useSearchParams();
|
||||
const { pets, addPet, removePet, setActivePet, getActivePet, updatePet, addReminder, toggleReminder, addHealthLog } = usePetStore();
|
||||
const { orders } = useCartStore();
|
||||
const isCharityEnabled = useSettingsStore(
|
||||
(state) =>
|
||||
state.getBoolean("CHARITY_DONATION_ENABLED", true) &&
|
||||
state.getBoolean("charity_donation_enabled", true) &&
|
||||
state.getBoolean("charityDonationEnabled", true)
|
||||
);
|
||||
const activePet = getActivePet();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
@@ -855,7 +862,7 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
|
||||
{/* Profile Card */}
|
||||
<section className="grid lg:grid-cols-3 gap-8">
|
||||
<section className={cn("grid gap-8", isCharityEnabled ? "lg:grid-cols-3" : "lg:grid-cols-3")}>
|
||||
<div className="lg:col-span-2 bg-white rounded-[3.5rem] p-10 border border-medical-gray-200 shadow-xl flex flex-col md:flex-row gap-10 items-center relative overflow-hidden">
|
||||
<div className="absolute top-0 left-0 w-32 h-32 bg-canina-blue/5 rounded-full blur-[60px] -translate-x-1/2 -translate-y-1/2" />
|
||||
|
||||
@@ -899,7 +906,7 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-canina-blue rounded-[3.5rem] p-10 text-white flex flex-col justify-between relative overflow-hidden shadow-2xl group">
|
||||
<div className={cn("bg-canina-blue rounded-[3.5rem] p-10 text-white flex flex-col justify-between relative overflow-hidden shadow-2xl group", !isCharityEnabled && "lg:col-span-1")}>
|
||||
<div className="absolute top-0 right-0 p-8 opacity-20 group-hover:rotate-12 transition-transform duration-700">
|
||||
<Activity className="w-16 h-16 text-white" />
|
||||
</div>
|
||||
@@ -921,43 +928,45 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
|
||||
{/* Kindness Footprint Widget for Pet */}
|
||||
<div className="bg-pink-50 rounded-[3.5rem] p-10 border border-pink-100 relative overflow-hidden flex flex-col justify-between">
|
||||
<div className="absolute -bottom-8 -left-8 opacity-5">
|
||||
<Heart className="w-48 h-48 fill-pink-500" />
|
||||
</div>
|
||||
<div className="flex items-center gap-4 mb-6">
|
||||
<div className="w-12 h-12 bg-pink-500 rounded-2xl flex items-center justify-center text-white shadow-lg shadow-pink-100">
|
||||
<Heart className="w-6 h-6 fill-white" />
|
||||
{isCharityEnabled && (
|
||||
<div className="bg-pink-50 rounded-[3.5rem] p-10 border border-pink-100 relative overflow-hidden flex flex-col justify-between">
|
||||
<div className="absolute -bottom-8 -left-8 opacity-5">
|
||||
<Heart className="w-48 h-48 fill-pink-500" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-black text-medical-gray-900 italic">ردپای مهربانی {activePet.name}</h3>
|
||||
<p className="text-[10px] font-black text-pink-500 uppercase tracking-widest mt-1">سفیر مهربانی: {activePet.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-4 relative z-10">
|
||||
<div className="bg-white/90 backdrop-blur-sm rounded-2xl p-4 border border-pink-100 space-y-2.5">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-bold text-medical-gray-500">کمک اهدایی با نام {activePet.name}:</span>
|
||||
<span className="text-sm font-black text-pink-600 font-mono">
|
||||
{toPersian(petCharityTotal.toLocaleString())} <span className="text-[10px] font-normal">تومان</span>
|
||||
</span>
|
||||
<div className="flex items-center gap-4 mb-6">
|
||||
<div className="w-12 h-12 bg-pink-500 rounded-2xl flex items-center justify-center text-white shadow-lg shadow-pink-100">
|
||||
<Heart className="w-6 h-6 fill-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-black text-medical-gray-900 italic">ردپای مهربانی {activePet.name}</h3>
|
||||
<p className="text-[10px] font-black text-pink-500 uppercase tracking-widest mt-1">سفیر مهربانی: {activePet.name}</p>
|
||||
</div>
|
||||
{allCharityTotal > 0 && (
|
||||
<div className="flex items-center justify-between text-[11px] font-bold text-medical-gray-400 pt-2 border-t border-pink-50">
|
||||
<span>مجموع مهربانی کل حساب:</span>
|
||||
<span>{toPersian(allCharityTotal.toLocaleString())} تومان</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-medical-gray-600 font-medium leading-relaxed">
|
||||
{petCharityTotal > 0 ? (
|
||||
<>«{activePet.name}» با خریدهای مکمل خود تا کنون <strong className="text-pink-600">{toPersian(petCharityTotal.toLocaleString())} تومان</strong> به درمان و تغذیه حیوانات نیازمند پناهگاهی کمک کرده است.</>
|
||||
) : (
|
||||
<>با هر خرید برای «{activePet.name}» میتوانید با انتخاب گزینه ردپای مهربانی، مبلغی را به نام او به پناهگاههای حیوانات اختصاص دهید.</>
|
||||
)}
|
||||
</p>
|
||||
<div className="space-y-4 relative z-10">
|
||||
<div className="bg-white/90 backdrop-blur-sm rounded-2xl p-4 border border-pink-100 space-y-2.5">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-bold text-medical-gray-500">کمک اهدایی با نام {activePet.name}:</span>
|
||||
<span className="text-sm font-black text-pink-600 font-mono">
|
||||
{toPersian(petCharityTotal.toLocaleString())} <span className="text-[10px] font-normal">تومان</span>
|
||||
</span>
|
||||
</div>
|
||||
{allCharityTotal > 0 && (
|
||||
<div className="flex items-center justify-between text-[11px] font-bold text-medical-gray-400 pt-2 border-t border-pink-50">
|
||||
<span>مجموع مهربانی کل حساب:</span>
|
||||
<span>{toPersian(allCharityTotal.toLocaleString())} تومان</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-medical-gray-600 font-medium leading-relaxed">
|
||||
{petCharityTotal > 0 ? (
|
||||
<>«{activePet.name}» با خریدهای مکمل خود تا کنون <strong className="text-pink-600">{toPersian(petCharityTotal.toLocaleString())} تومان</strong> به درمان و تغذیه حیوانات نیازمند پناهگاهی کمک کرده است.</>
|
||||
) : (
|
||||
<>با هر خرید برای «{activePet.name}» میتوانید با انتخاب گزینه ردپای مهربانی، مبلغی را به نام او به پناهگاههای حیوانات اختصاص دهید.</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Refill & Stock Tracking */}
|
||||
|
||||
@@ -32,9 +32,16 @@ export function useCatalogMode() {
|
||||
? getBoolean("CATALOG_SHOW_WALLET", false) || getBoolean("catalog_show_wallet", false)
|
||||
: true;
|
||||
|
||||
const showCharity = isCatalogOnly
|
||||
? getBoolean("CATALOG_SHOW_CHARITY", false) || getBoolean("catalog_show_charity", false)
|
||||
: true;
|
||||
const isCharityGlobalEnabled =
|
||||
getBoolean("CHARITY_DONATION_ENABLED", true) &&
|
||||
getBoolean("charity_donation_enabled", true) &&
|
||||
getBoolean("charityDonationEnabled", true);
|
||||
|
||||
const showCharity = isCharityGlobalEnabled && (
|
||||
isCatalogOnly
|
||||
? getBoolean("CATALOG_SHOW_CHARITY", false) || getBoolean("catalog_show_charity", false)
|
||||
: true
|
||||
);
|
||||
|
||||
const orderDisabledTitle = getText(
|
||||
"ORDER_DISABLED_TITLE",
|
||||
|
||||
Reference in new issue
Block a user