EHSAN official look & auth (Task #5)

Reskin the EHSAN POC to match ehsan.sa and gate the admin area behind a
simple POC login.

- Official header: cropped EHSAN logo, nav (الرئيسية/الوقف/فرص التبرع/
  خدماتنا dropdown→طلب دعم/عن إحسان/براعم إحسان), login/cart/search icons,
  language toggle, mobile menu. Functional items link; rest are visual-only.
- Colors: green primary tuned + orange accent token added in index.css.
- Auth: AuthContext (localStorage, admin/admin) + login page; /admin and
  /whatsapp-log now behind a Protected wrapper redirecting to /login.
- Redesigned OpportunityCard (photo, green progress bar with %, category
  badge, تم جمع/المبلغ المتبقي columns, inline donate button + amount),
  used on home and opportunities pages.
- Two-step donate page (التفاصيل → الدفع): step indicator, presets
  100/50/10, custom amount (prefilled via ?amount=), "تبرع عن أهلك"
  checkbox, donor form (phone min 10 for OpenClaw loop).
- 8 need-type card images added; needImages helper maps need→image.
- Seed: added published opportunities (req-012..017) with partial progress
  to showcase cards; one kept near-full for an easy closed-loop demo.

Deviation (from code review): donate handler now ACCUMULATES collectedAmount
and clamps to target, validates finite/positive amount, and only advances to
the closed-loop pipeline when a case is fully funded (previously overwrote
and force-advanced — broke partial-progress cases). Donate buttons kept green
to match the reference; orange is an accent only.
This commit is contained in:
Replit Agent
2026-06-05 17:45:17 +00:00
parent 4db9f09195
commit 5d40b0d3c2
28 changed files with 1177 additions and 324 deletions
+138
View File
@@ -374,6 +374,144 @@ export const requests: DonationRequest[] = [
createdAt: d(1),
updatedAt: d(0),
},
{
id: "req-012",
caseId: "CASE-012",
beneficiaryName: "هند فيصل العنزي",
nationalId: "1067890123",
phone: "0513333333",
source: "charity",
sourceName: "جمعية كافل الخيرية",
needType: "food",
requestedAmount: 1200,
collectedAmount: 780,
description: "سلة غذائية شهرية لأسرة مكونة من خمسة أفراد",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(9),
updatedAt: d(2),
},
{
id: "req-013",
caseId: "CASE-013",
beneficiaryName: "صالح عوض الحارثي",
nationalId: "2078901234",
phone: "0514444444",
source: "official",
sourceName: "شركة الكهرباء السعودية",
needType: "electricity",
requestedAmount: 2600,
collectedAmount: 1850,
description: "سداد فاتورة كهرباء متراكمة لمنزل أسرة متعففة",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(7),
updatedAt: d(1),
},
{
id: "req-014",
caseId: "CASE-014",
beneficiaryName: "لطيفة عبدالله الشهري",
nationalId: "1089012345",
phone: "0515555555",
source: "charity",
sourceName: "الهلال الأحمر السعودي",
needType: "health",
requestedAmount: 6000,
collectedAmount: 1500,
description: "مستلزمات طبية وأجهزة منزلية لمريضة مزمنة",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(6),
updatedAt: d(1),
},
{
id: "req-015",
caseId: "CASE-015",
beneficiaryName: "ماجد سعيد القرني",
nationalId: "2090123456",
phone: "0516666666",
source: "beneficiary",
sourceName: "مستفيد مباشر",
needType: "water",
requestedAmount: 1400,
collectedAmount: 1120,
description: "سداد فاتورة مياه متأخرة لأسرة تعيلها أرملة",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(5),
updatedAt: d(1),
},
{
id: "req-016",
caseId: "CASE-016",
beneficiaryName: "ريم ناصر المطيري",
nationalId: "1078901234",
phone: "0517777777",
source: "charity",
sourceName: "جمعية الإسكان التنموي",
needType: "housing",
requestedAmount: 9000,
collectedAmount: 3200,
description: "ترميم وحدة سكنية متضررة لأسرة ذات دخل محدود",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(4),
updatedAt: d(1),
},
{
id: "req-017",
caseId: "CASE-017",
beneficiaryName: "عبدالعزيز فهد الرشيد",
nationalId: "2012345678",
phone: "0518888888",
source: "official",
sourceName: "جمعية تكافل",
needType: "air_conditioner",
requestedAmount: 2200,
collectedAmount: 2100,
description: "تأمين مكيف لمنزل يقطنه مسنون في منطقة شديدة الحرارة",
status: "published",
currentStep: 4,
donorId: null,
donorName: null,
thankYouMessage: null,
whatsappStatus: null,
whatsappSentAt: null,
rejectionReason: null,
createdAt: d(3),
updatedAt: d(1),
},
];
// ─── WhatsApp Log ────────────────────────────────────────────────────────────
+26 -7
View File
@@ -165,15 +165,30 @@ router.post("/requests/:id/donate", (req: Request, res: Response): void => {
}
const { donorName, donorPhone, donorEmail, amount } = req.body;
if (!donorName || !donorPhone || !amount) {
res.status(400).json({ error: "Missing donor details" });
const amt = Number(amount);
if (!donorName || !donorPhone || !Number.isFinite(amt) || amt <= 0) {
res.status(400).json({ error: "Invalid donor details or amount" });
return;
}
if (item.status !== "published") {
res.status(400).json({ error: "Case is not open for donations" });
return;
}
const remaining = Math.max(0, item.requestedAmount - item.collectedAmount);
if (remaining <= 0) {
res.status(400).json({ error: "Case already fully funded" });
return;
}
// Clamp the donation so the collected amount never exceeds the target.
const applied = Math.min(amt, remaining);
const donorId = uuidv4();
const existingDonor = donors.find((d) => d.phone === donorPhone);
if (existingDonor) {
existingDonor.totalDonated += Number(amount);
existingDonor.totalDonated += applied;
existingDonor.donationCount += 1;
item.donorId = existingDonor.id;
} else {
@@ -182,7 +197,7 @@ router.post("/requests/:id/donate", (req: Request, res: Response): void => {
name: donorName,
phone: donorPhone,
email: donorEmail || null,
totalDonated: Number(amount),
totalDonated: applied,
donationCount: 1,
};
donors.push(newDonor);
@@ -190,9 +205,13 @@ router.post("/requests/:id/donate", (req: Request, res: Response): void => {
}
item.donorName = donorName;
item.collectedAmount = Number(amount);
item.status = "donated";
item.currentStep = STATUS_STEP["donated"];
item.collectedAmount += applied;
// Only advance into the closed-loop pipeline once the case is fully funded.
if (item.collectedAmount >= item.requestedAmount) {
item.status = "donated";
item.currentStep = STATUS_STEP["donated"];
}
item.updatedAt = new Date().toISOString();
res.json(item);
});